line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bolts::Blueprint; |
2
|
|
|
|
|
|
|
$Bolts::Blueprint::VERSION = '0.143171'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Defines the interface implemented by blueprints |
4
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
4280
|
use Moose::Role; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
55
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
requires 'builder'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub get { |
12
|
1294
|
|
|
1294
|
1
|
2399
|
my ($self, $bag, $name, @params) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# use Data::Dumper; |
15
|
|
|
|
|
|
|
# Carp::cluck( "BLUEPRINT GET[$name]: ", Dumper(\@params)); |
16
|
|
|
|
|
|
|
|
17
|
1294
|
|
|
|
|
3027
|
$self->builder($bag, $name, @params); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#sub init_meta { } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
885
|
|
|
885
|
1
|
3718
|
sub implied_scope { } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__END__ |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=pod |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=encoding UTF-8 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Bolts::Blueprint - Defines the interface implemented by blueprints |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 VERSION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
version 0.143171 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SYNOPSIS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
package MyApp::Blueprint::Custom; |
44
|
|
|
|
|
|
|
use Moose; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
with 'Bolts::Blueprint'; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has service_locator => ( |
49
|
|
|
|
|
|
|
is => 'ro', |
50
|
|
|
|
|
|
|
isa => 'MyApp::ServiceLocator', |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub builder { |
54
|
|
|
|
|
|
|
my ($self, $bag, $name, @params) = @_; |
55
|
|
|
|
|
|
|
$self->service_locator($name, @params); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
A blueprint is a class for retrieving a fresh instance of a value or object on behalf of an artifact. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 REQUIRED METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 builder |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub builder { |
67
|
|
|
|
|
|
|
my ($self, $bag, $name, @params) = @_; |
68
|
|
|
|
|
|
|
... |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This method must be implemented to perform the actual object construction. The arguments passed are as follows: |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=over |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item C<$self> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This is the invocant, the blueprint object itself. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item C<$bag> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This is the bag that contains the artifact being constructed. This is often referenced as an object giving context to the construction. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item C<$name> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This is the name of the artifact being constructed. This is also given for context. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item C<@params> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
These are the parameters passed in during the pre-injection phase. This may be a list of parameters or hash or whatever the injectors say should be passed in. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 METHODS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 get |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $artifact = $blueprint->get($bag, $name, @params); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This is basically a wrapper around the call to L</builder>. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 implied_scope |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $is_implied = $blueprint->implied_scope; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Sometimes, the blueprint itself is inherently scoped. For example, a literal value is immutable and therefore saving the value to the scope would be a waste of time. Another example is a service locator that might manage it's own scope based on complex features of the application state. In those cases, you may override this method to return a true value to cause the artifact to skip saving to and checking the scope for this value and calling the blueprint every time. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 AUTHOR |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Andrew Sterling Hanenkamp <hanenkamp@cpan.org> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Qubling Software LLC. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
116
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |