File Coverage

blib/lib/Bolts/Blueprint/Built.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Bolts::Blueprint::Built;
2             $Bolts::Blueprint::Built::VERSION = '0.142930';
3             # ABSTRACT: Build an artifact by running a subroutine
4              
5 8     8   37 use Moose;
  8         10  
  8         47  
6              
7             with 'Bolts::Blueprint';
8              
9 8     8   37242 use Carp ();
  8         13  
  8         650  
10              
11              
12             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 20     20 1 35 my ($self, $bag, $name, @params) = @_;
25 20         707 $self->call_builder($bag, $name, @params);
26             }
27              
28             __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.142930
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