Bolts/Blueprint.pm

filter: Statementstmt 100% 8 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 100% 2 / 2 totaltotal 100% 13 / 13 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
get
1.0
implied_scope
1.0
CRAP 1.0
« Bolts/Artifact/Thunk.pm ↑ Summary Bolts/Blueprint/Built.pm »
1 package Bolts::Blueprint;
2 10 $Bolts::Blueprint::VERSION = '0.143170';
3 # ABSTRACT: Defines the interface implemented by blueprints
4  
5 10 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 10 requires 'builder';
9  
10  
11 sub get {
12 1284 ▶ my ($self, $bag, $name, @params) = @_;
Subroutine get: called CC=1 SCAR=0.0
Pod documented
13  
14 # use Data::Dumper;
15 # Carp::cluck( "BLUEPRINT GET[$name]: ", Dumper(\@params));
16  
17 1284 $self->builder($bag, $name, @params);
18 }
19  
20 #sub init_meta { }
21  
22  
23 ▶sub implied_scope { }
Subroutine implied_scope: called CC=1 SCAR=0.0
Pod documented
24  
25 10 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.143170
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
« Bolts/Artifact/Thunk.pm ↑ Summary Bolts/Blueprint/Built.pm »