Bolts/Blueprint/Acquired.pm

filter: Statementstmt 100% 19 / 19 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 2 / 2 totaltotal 96.5% 28 / 29 SCAR 11.0
CC
3
Cov
96%
builder
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« Bolts/Meta/Initializer.pm ↑ Summary Bolts/Locator.pm »
1 package Bolts::Blueprint::Acquired;
2 6 $Bolts::Blueprint::Acquired::VERSION = '0.143170';
3 # ABSTRACT: acquire an artifact via a path and locator
4  
5 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 with 'Bolts::Blueprint::Role::Injector';
8  
9 6 ▶use Bolts::Util qw( locator_for );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 6 has locator => (
13 is => 'ro',
14 does => 'Bolts::Role::Locator',
15 predicate => 'has_locator',
16 );
17  
18  
19 6 has path => (
20 is => 'ro',
21 isa => 'ArrayRef[Str]',
22 predicate => 'has_path',
23 traits => [ 'Array' ],
24 handles => {
25 full_path => 'elements',
26 },
27 );
28  
29  
30 sub builder {
31 177 ▶ my ($self, $bag, $name) = @_;
Subroutine builder: called CC=3 SCAR=11.0
Pod documented
32  
33 177 ▶ my @path = $self->has_path ? $self->full_path : $name;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_path ? : 177 0 177
34
35 177 my $return;
36 177 ▶ if ($self->has_locator) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_locator) { } 3 174 177
37 3 $return = $self->locator->acquire(@path);
38 }
39 else {
40 174 $return = locator_for($bag)->acquire(@path);
41 }
42  
43 177 return $return;
44 }
45  
46  
47 42 ▶sub exists { 1 }
Subroutine exists: called CC=1 SCAR=0.0
Pod documented
48  
49 6 __PACKAGE__->meta->make_immutable;
50  
51 __END__
52  
53 =pod
54  
55 =encoding UTF-8
56  
57 =head1 NAME
58  
59 Bolts::Blueprint::Acquired - acquire an artifact via a path and locator
60  
61 =head1 VERSION
62  
63 version 0.143170
64  
65 =head1 SYNOPSIS
66  
67 use Bolts;
68  
69 # Using the usual sugar... these all use acquired blueprints
70 artifact thing1; # acquired by attribute
71 artifact thing2 => (
72 path => [ 'thing1' ],
73 );
74 artifact thing3 => (
75 locator => $other_loc,
76 path => [ 'other', 'thing' ],
77 );
78  
79 # Or for injection
80 artifact thing4 => (
81 class => 'MyApp::Thing',
82 parameters => {
83 foo => dep('thing1'), # uses this blueprint
84 },
85 );
86  
87 # Or directly...
88 my $meta = Bolts::Bag->start_bag;
89  
90 my $artifact = Bolts::Artifact->new(
91 name => 'thing',
92 blueprint => $meta->locator->acquire('blueprint', 'acquired', {
93 path => [ 'myapp', 'settings', 'thing' ],
94 locator => $other_loc,
95 },
96 scope => $meta->locator->acquire('scope', singleton'),
97 );
98  
99 =head1 DESCRIPTION
100  
101 A blueprint for constructing the object by acquiring it from a L<Bolts::Role::Locator>. This is handy for assembling complex bags in Bolts. It is also used as a convenient way of injecting dependencies into an artifact.
102  
103 =head1 ROLES
104  
105 =over
106  
107 =item *
108  
109 L<Bolts::Blueprint::Role::Injector>
110  
111 =back
112  
113 =head1 ATTRIBUTES
114  
115 =head2 locator
116  
117 This is the L<Bolts::Role::Locator> to acquire an artifact from. If none is given, the blueprint will use the bag the parent artifact is in as the locator.
118  
119 =head2 path
120  
121 This is the path within the locator to use for acquiring the artifact. If not given, the name of the parent artifact is used instead (which is primarily useful for injected dependencies and could lead to negative consquences, like looping forever, if used otherwise).
122  
123 =head2 builder
124  
125 This implements the actual acquisition from the L</locator> (or the bag the parent artifact is in) and L</path> (or the name of the parent artifact).
126  
127 =head2 exists
128  
129 Always returns true.
130  
131 =head1 AUTHOR
132  
133 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
134  
135 =head1 COPYRIGHT AND LICENSE
136  
137 This software is copyright (c) 2014 by Qubling Software LLC.
138  
139 This is free software; you can redistribute it and/or modify it under
140 the same terms as the Perl 5 programming language system itself.
141  
142 =cut
« Bolts/Meta/Initializer.pm ↑ Summary Bolts/Locator.pm »