File Coverage

blib/lib/Bolts/Blueprint/Given.pm
Criterion Covered Total %
statement 13 14 92.8
branch 4 6 66.6
condition 2 3 66.6
subroutine 4 5 80.0
pod 3 3 100.0
total 26 31 83.8


line stmt bran cond sub pod time code
1             package Bolts::Blueprint::Given;
2             $Bolts::Blueprint::Given::VERSION = '0.143171';
3             # ABSTRACT: Used to pass parameters from the user during acquisition into the injector
4              
5 11     11   48 use Moose;
  11         14  
  11         71  
6              
7             with 'Bolts::Blueprint::Role::Injector';
8              
9 11     11   51168 use Carp ();
  11         19  
  11         1564  
10              
11              
12             has required => (
13             is => 'ro',
14             isa => 'Bool',
15             required => 1,
16             default => 0,
17             );
18              
19              
20             sub builder {
21 498     498 1 788 my ($self, $bag, $name, %params) = @_;
22              
23 498 50 66     11703 Carp::croak("Missing required parameter $name")
24             if $self->required and not exists $params{ $name };
25              
26 498 50       892 return unless exists $params{ $name };
27              
28 498         1321 return $params{ $name };
29             }
30              
31              
32             sub exists {
33 966     966 1 1736 my ($self, $bag, $name, %params) = @_;
34              
35 966 100       22369 return 1 if $self->required;
36 584         2551 return exists $params{ $name };
37             }
38              
39             # sub inline_get {
40             # return q[$artifact = $self->_].$name.q[;];
41             # }
42              
43              
44 0     0 1   sub implied_scope { 'singleton' }
45              
46             __PACKAGE__->meta->make_immutable;
47              
48             __END__
49              
50             =pod
51              
52             =encoding UTF-8
53              
54             =head1 NAME
55              
56             Bolts::Blueprint::Given - Used to pass parameters from the user during acquisition into the injector
57              
58             =head1 VERSION
59              
60             version 0.143171
61              
62             =head1 SYNOPSIS
63              
64             use Bolts;
65              
66             # Using the usual sugar...
67             artifact thing => (
68             ...
69             parameters => {
70             thing => option { # uses blueprint, given
71             isa => 'Str',
72             required => 1,
73             },
74             },
75             );
76              
77             # Or directly...
78             my $meta = Bolts::Bag->start_bag;
79              
80             my $artifact = Bolts::Artifact->new(
81             ...
82             injectors => [
83             $meta->locator->acquire('injector', 'parameter_name', {
84             key => 'thing',
85             blueprint => $meta->locator->acquire('blueprint', 'given', {
86             required => 1,
87             }),
88             isa => 'Str',
89             }),
90             ],
91             );
92              
93             =head1 DESCRIPTION
94              
95             This takes parameters passed in during acquisition and passes them on to the injector. It is only useful for handling parameters passed during acquisition. It is a no-op if used as a regular artifact blueprint.
96              
97             =head1 ROLES
98              
99             =over
100              
101             =item *
102              
103             L<Bolts::Blueprint::Role::Injector>
104              
105             =back
106              
107             =head1 ATTRIBUTES
108              
109             =head2 required
110              
111             The blueprint will complain if this flag is set, but the keyed parameter is not
112             found in those passed during acquisition.
113              
114             =head1 METHODS
115              
116             =head2 builder
117              
118             This takes finds the parameter matching the injector key in the passed in
119             parameters and returns it.
120              
121             =head2 exists
122              
123             Returns true when the parameters contains the named key and when L</required>
124             is set to true.
125              
126             =head2 implied_scope
127              
128             This is set, but doesn't really matter since scope does not matter during
129             injection.
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