Bolts/Injector.pm

filter: Statementstmt 100% 36 / 36 Branchbran 85.7% 12 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 4 / 4 totaltotal 89.0% 57 / 64 CC 9 SCAR 12.6
CC
9
Cov
91%
get
5.2
post_inject
3.0
pre_inject
3.0
CRAP 3.5
« Bolts/Locator.pm ↑ Summary Bolts/Blueprint/Given.pm »
1 package Bolts::Injector;
2 11 $Bolts::Injector::VERSION = '0.143171';
3 # ABSTRACT: inject options and parameters into artifacts
4  
5 11 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 our @CARP_NOT = qw(
8 Bolts::Injector::Parameter::ByName
9 Bolts::Artifact
10 );
11  
12  
13 11 has init_locator => (
14 is => 'ro',
15 isa => 'Bolts::Role::Locator',
16 weak_ref => 1,
17 );
18  
19 #with 'Bolts::Role::Initializer';
20  
21  
22 11 has key => (
23 is => 'ro',
24 isa => 'Str',
25 required => 1,
26 );
27  
28  
29 11 has blueprint => (
30 is => 'ro',
31 does => 'Bolts::Blueprint::Role::Injector',
32 required => 1,
33 traits => [ 'Bolts::Initializer' ],
34 );
35  
36  
37 11 has does => (
38 accessor => 'does_type',
39 isa => 'Moose::Meta::TypeConstraint',
40 );
41  
42  
43 11 has isa => (
44 accessor => 'isa_type',
45 isa => 'Moose::Meta::TypeConstraint',
46 );
47  
48  
49 # not actually required, we use duck-typing to determine what kind of injection
50 # to perform.
51 #requires 'pre_inject_value';
52 #requires 'post_inject_value';
53  
54  
55 1051 ▶sub pre_inject {
Subroutine pre_inject: called CC=3 SCAR=11.0
Pod documented
56 1051 my ($self, $loc, $options, $param) = @_;
57  
58 1051 ▶ return unless $self->can('pre_inject_value');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can("pre_inject_value") 54 997 1051
59 997 ▶ return unless $self->exists($loc, $options);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->exists($loc, $options) 468 529 997
60  
61 529 my $value = $self->get($loc, $options);
62 528 $self->pre_inject_value($loc, $value, $param);
63 }
64  
65  
66 1049 ▶sub post_inject {
Subroutine post_inject: called CC=3 SCAR=11.0
Pod documented
67 1049 my ($self, $loc, $options, $artifact) = @_;
68  
69 1049 ▶ return unless $self->can('post_inject_value');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can("post_inject_value") 995 54 1049
70 54 ▶ return unless $self->exists($loc, $options);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->exists($loc, $options) 0 54 54
71  
72 54 my $value = $self->get($loc, $options);
73 54 $self->post_inject_value($loc, $value, $artifact);
74 }
75  
76  
77 1051 ▶sub exists {
Subroutine exists: called CC=1 SCAR=0.0
Pod documented
78 1051 my ($self, $loc, $options) = @_;
79  
80 1051 my $blueprint = $self->blueprint;
81 1051 my $key = $self->key;
82  
83 1051 return $blueprint->exists($loc, $key, %$options);
84 }
85  
86  
87 583 ▶sub get {
Subroutine get: called CC=5 SCAR=16.5
Pod documented
88 583 my ($self, $loc, $options) = @_;
89  
90 583 my $blueprint = $self->blueprint;
91 583 my $key = $self->key;
92  
93 583 my $value = $blueprint->get($loc, $key, %$options);
94  
95 583 my $isa = $self->isa_type;
96 583 my $does = $self->does_type;
97  
98 583 my $msg;
99 583 ▶ $msg = $isa->validate($value) if defined $isa;
Branch: 1 branch
BranchTrueFalseTotal
if defined $isa 98 485 583
100 583 ▶ $msg //= $does->validate($value) if defined $does;
Branch: 1 branch
BranchTrueFalseTotal
if defined $does 0 583 583
Condition0%0/3
$msg //= $does->validate($value)
l!l&&r!l&&!r
000
MC/DC0%0/2
$msg //= $does->validate($value)
$msg $does->validate($value)
Truth table0%0/3
A //= B
A= $msgB= $does->validate($value)
ABresult
1X1
011
000
101  
102 583 ▶ Carp::croak(qq[Value for injection at key "$key" has the wrong type: $msg]) if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 1 582 583
103  
104 582 return $value;
105 }
106  
107 11 1;
108  
109 __END__
« Bolts/Locator.pm ↑ Summary Bolts/Blueprint/Given.pm »