line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bolts::Blueprint::Acquired; |
2
|
|
|
|
|
|
|
$Bolts::Blueprint::Acquired::VERSION = '0.143171'; |
3
|
|
|
|
|
|
|
# ABSTRACT: acquire an artifact via a path and locator |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
3860
|
use Moose; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
45
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with 'Bolts::Blueprint::Role::Injector'; |
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
30090
|
use Bolts::Util qw( locator_for ); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
230
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has locator => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
does => 'Bolts::Role::Locator', |
15
|
|
|
|
|
|
|
predicate => 'has_locator', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
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
|
|
|
177
|
1
|
196
|
my ($self, $bag, $name) = @_; |
32
|
|
|
|
|
|
|
|
33
|
177
|
50
|
|
|
|
5196
|
my @path = $self->has_path ? $self->full_path : $name; |
34
|
|
|
|
|
|
|
|
35
|
177
|
|
|
|
|
193
|
my $return; |
36
|
177
|
100
|
|
|
|
5071
|
if ($self->has_locator) { |
37
|
3
|
|
|
|
|
73
|
$return = $self->locator->acquire(@path); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
174
|
|
|
|
|
439
|
$return = locator_for($bag)->acquire(@path); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
177
|
|
|
|
|
589
|
return $return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
42
|
|
|
42
|
1
|
116
|
sub exists { 1 } |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__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.143171 |
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 |