| 1 | package Bolts::Blueprint::Built; | ||
| 2 | 10 | $Bolts::Blueprint::Built::VERSION = '0.143170'; | |
| 3 | # ABSTRACT: Build an artifact by running a subroutine | ||
| 4 | |||
| 5 | 10 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 10 | with 'Bolts::Blueprint'; | |
| 8 | |||
| 9 | 10 | ▶ | use Carp (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | |||
| 12 | 10 | has builder => ( | |
| 13 | isa => 'CodeRef', | ||
| 14 | reader => 'the_builder', | ||
| 15 | required => 1, | ||
| 16 | traits => [ 'Code' ], | ||
| 17 | handles => { | ||
| 18 | 'call_builder' => 'execute_method', | ||
| 19 | }, | ||
| 20 | ); | ||
| 21 | |||
| 22 | |||
| 23 | sub builder { | ||
| 24 | 54 | ▶ | my ($self, $bag, $name, @params) = @_; |
|
Subroutine
builder: called CC=1 SCAR=0.0
Pod
documented
| |||
| 25 | 54 | $self->call_builder($bag, $name, @params); | |
| 26 | } | ||
| 27 | |||
| 28 | 10 | __PACKAGE__->meta->make_immutable; | |
| 29 | |||
| 30 | __END__ | ||
| 31 | |||
| 32 | =pod | ||
| 33 | |||
| 34 | =encoding UTF-8 | ||
| 35 | |||
| 36 | =head1 NAME | ||
| 37 | |||
| 38 | Bolts::Blueprint::Built - Build an artifact by running a subroutine | ||
| 39 | |||
| 40 | =head1 VERSION | ||
| 41 | |||
| 42 | version 0.143170 | ||
| 43 | |||
| 44 | =head1 SYNOPSIS | ||
| 45 | |||
| 46 | use Bolts; | ||
| 47 | |||
| 48 | # Using the usual sugar... | ||
| 49 | artifact thing => ( | ||
| 50 | builder => sub { | ||
| 51 | my ($self, $bag, $name, @params) = @_; | ||
| 52 | return MyApp::Thing->new(@params); | ||
| 53 | }, | ||
| 54 | ); | ||
| 55 | |||
| 56 | # Or directly... | ||
| 57 | my $meta = Bolts::Bag->start_bag; | ||
| 58 | |||
| 59 | my $artifact = Bolts::Artifact->new( | ||
| 60 | name => 'thing', | ||
| 61 | blueprint => $meta->locator->acquire('blueprint', 'built', { | ||
| 62 | builder => sub { | ||
| 63 | my ($self, $bag, $name, @params) = @_; | ||
| 64 | return MyApp::Thing->new(@params); | ||
| 65 | }, | ||
| 66 | }), | ||
| 67 | scope => $meta->locator->acquire('scope', '_'), | ||
| 68 | ); | ||
| 69 | |||
| 70 | =head1 DESCRIPTION | ||
| 71 | |||
| 72 | This is a blueprint for constructing an artifact using a custom subroutine. This is handy for gluing anything to anything. | ||
| 73 | |||
| 74 | =head1 ROLES | ||
| 75 | |||
| 76 | =over | ||
| 77 | |||
| 78 | =item * | ||
| 79 | |||
| 80 | L<Bolts::Blueprint> | ||
| 81 | |||
| 82 | =back | ||
| 83 | |||
| 84 | =head1 ATTRIBUTES | ||
| 85 | |||
| 86 | =head2 builder | ||
| 87 | |||
| 88 | B<Required.> This is the subroutine to execute to construct the artifact. The reader for this attribute is named C<the_builder>. | ||
| 89 | |||
| 90 | =head1 METHODS | ||
| 91 | |||
| 92 | =head2 builder | ||
| 93 | |||
| 94 | This executes the subroutine in the C<builder> attribute. | ||
| 95 | |||
| 96 | =head1 AUTHOR | ||
| 97 | |||
| 98 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||
| 99 | |||
| 100 | =head1 COPYRIGHT AND LICENSE | ||
| 101 | |||
| 102 | This software is copyright (c) 2014 by Qubling Software LLC. | ||
| 103 | |||
| 104 | This is free software; you can redistribute it and/or modify it under | ||
| 105 | the same terms as the Perl 5 programming language system itself. | ||
| 106 | |||
| 107 | =cut | ||