Bolts/Blueprint/BuiltInjector.pm

filter: Statementstmt 100% 13 / 13 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 2 / 2 totaltotal 100% 19 / 19 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
builder
1.0
CRAP 1.0
« Bolts/Blueprint/Built.pm ↑ Summary Bolts/Blueprint/Factory.pm »
1 package Bolts::Blueprint::BuiltInjector;
2 2 $Bolts::Blueprint::BuiltInjector::VERSION = '0.143170';
3 # ABSTRACT: An injector-oriented builder using a subroutine
4  
5 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 with 'Bolts::Blueprint::Role::Injector';
8  
9 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 2 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 4 ▶ my ($self, $bag, $name, %params) = @_;
Subroutine builder: called CC=1 SCAR=0.0
Pod documented
24 4 $self->call_builder($bag, $name, %params);
25 }
26  
27  
28 4 ▶sub exists { 1 }
Subroutine exists: called CC=1 SCAR=0.0
Pod documented
29  
30 2 __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.143170
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
« Bolts/Blueprint/Built.pm ↑ Summary Bolts/Blueprint/Factory.pm »