Bolts/Blueprint/Given.pm

filter: Statementstmt 94.4% 17 / 18 Branchbran 66.6% 4 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 4 / 5 Podpod 100% 3 / 3 totaltotal 81.0% 30 / 37 SCAR 16.3
CC
5
Cov
85%
builder
4.3
exists
2.0
implied_scope
2.0
CRAP 5.1
« Bolts/Inference/Moose.pm ↑ Summary Bolts/Scope/Singleton.pm »
1 package Bolts::Blueprint::Given;
2 8 $Bolts::Blueprint::Given::VERSION = '0.142930';
3 # ABSTRACT: Used to pass parameters from the user during acquisition into the injector
4  
5 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 with 'Bolts::Blueprint::Role::Injector';
8  
9 8 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 8 has required => (
13 is => 'ro',
14 isa => 'Bool',
15 required => 1,
16 default => 0,
17 );
18  
19  
20 sub builder {
21 264 ▶ my ($self, $bag, $name, %params) = @_;
Subroutine builder: called CC=4 SCAR=14.6
Pod documented
22  
23 Carp::croak("Missing required parameter $name")
24 264 ▶ if $self->required and not exists $params{ $name };
Branch: 1 branch
BranchTrueFalseTotal
if $self->required and not exists $params{$name} 0 264 264
Condition66%2/3
$self->required and not exists $params{$name}
!ll&&!rl&&r
602040
MC/DC0%0/2
$self->required and not exists $params{$name}
$self->required not exists $params{$name}
Truth table66%2/3
A and not(B)
A= $self->requiredB= not exists $params{$name}
ABresult
0X0
100
111
25  
26 264 ▶ return unless exists $params{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{$name} 0 264 264
27  
28 264 return $params{ $name };
29 }
30  
31  
32 sub exists {
33 498 ▶ my ($self, $bag, $name, %params) = @_;
Subroutine exists: called CC=2 SCAR=6.9
Pod documented
34  
35 498 ▶ return 1 if $self->required;
Branch: 1 branch
BranchTrueFalseTotal
if $self->required 204 294 498
36 294 return exists $params{ $name };
37 }
38  
39 # sub inline_get {
40 # return q[$artifact = $self->_].$name.q[;];
41 # }
42  
43  
44 0 ▶sub implied_scope { 'singleton' }
Subroutine implied_scope: not called CC=1 SCAR=6.9
Pod documented
45  
46 8 __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.142930
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
« Bolts/Inference/Moose.pm ↑ Summary Bolts/Scope/Singleton.pm »