File Coverage

blib/lib/Bolts/Blueprint/BuiltInjector.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod 2 2 100.0
total 15 15 100.0


line stmt bran cond sub pod time code
1             package Bolts::Blueprint::BuiltInjector;
2             $Bolts::Blueprint::BuiltInjector::VERSION = '0.143171';
3             # ABSTRACT: An injector-oriented builder using a subroutine
4              
5 2     2   1292 use Moose;
  2         4  
  2         12  
6              
7             with 'Bolts::Blueprint::Role::Injector';
8              
9 2     2   9612 use Carp ();
  2         4  
  2         215  
10              
11              
12             has builder => (
13             isa => 'CodeRef',
14             reader => 'the_builder',
15             traits => [ 'Code' ],
16             handles => {
17             'call_builder' => 'execute_method',
18             },
19             );
20              
21              
22             sub builder {
23 5     5 1 17 my ($self, $bag, $name, %params) = @_;
24 5         178 $self->call_builder($bag, $name, %params);
25             }
26              
27              
28 5     5 1 20 sub exists { 1 }
29              
30             __PACKAGE__->meta->make_immutable;
31              
32             __END__
33              
34             =pod
35              
36             =encoding UTF-8
37              
38             =head1 NAME
39              
40             Bolts::Blueprint::BuiltInjector - An injector-oriented builder using a subroutine
41              
42             =head1 VERSION
43              
44             version 0.143171
45              
46             =head1 SYNOPSIS
47              
48             use Bolts;
49              
50             # Using the usual sugar...
51             artifact thing => (
52             ...
53             parameters => {
54             thing => builder {
55             my ($self, $bag, $name, %params) = @_;
56             return MyApp::Thing->new(%params);
57             },
58             },
59             );
60              
61             # Or directly...
62             my $meta = Bolts::Bag->start_bag;
63              
64             my $artifact = Bolts::Artifact->new(
65             ...
66             injectors => [
67             $meta->locator->acquire('injector', 'parameter_name', {
68             key => 'thing',
69             blueprint => $meta->locator->acquire('blueprint', 'built_injector', {
70             builder => sub {
71             my ($self, $bag, $name, %params) = @_;
72             return MyApp::Thing->new(%params);
73             },
74             }),
75             }),
76             ],
77             );
78              
79             =head1 DESCRIPTION
80              
81             This is a blueprint for using a subroutine to fill in an injected artifact dependency.
82              
83             This differs from L<Bolts::Blueprint::Built> in that it implements L<Bolts::Blueprint::Role::Injector>, which tags this has only accepting named parameters to the builder method, which is required during injection.
84              
85             =head1 ROLES
86              
87             =over
88              
89             =item *
90              
91             L<Bolts::Blueprint::Role::Injector>
92              
93             =back
94              
95             =head1 ATTRIBUTES
96              
97             =head2 builder
98              
99             B<Required.> This is the subroutine to execute to construct the artifact. The reader for this attribute is named C<the_builder>.
100              
101             =head1 METHODS
102              
103             =head2 builder
104              
105             This executes the subroutine in the C<builder> attribute.
106              
107             =head2 exists
108              
109             Always returns true.
110              
111             =head1 AUTHOR
112              
113             Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
114              
115             =head1 COPYRIGHT AND LICENSE
116              
117             This software is copyright (c) 2014 by Qubling Software LLC.
118              
119             This is free software; you can redistribute it and/or modify it under
120             the same terms as the Perl 5 programming language system itself.
121              
122             =cut