Bolts/Meta/Class/Trait/Bag.pm

filter: Statementstmt 78.4% 40 / 51 Branchbran 66.6% 12 / 18 Conditioncond 58.3% 7 / 12 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 80.0% 12 / 15 Podpod 100% 3 / 3 totaltotal 72.6% 77 / 106 CC 14 SCAR 16.8
CC
14
Cov
73%
_wrap_method_in_such_that_check
12.0
__ANON__
12.0
add_artifact
10.0
CRAP 5.4
« Bolts/Inference/Moose.pm ↑ Summary Bolts/Meta/Attribute/Trait/Initializer.pm »
1 package Bolts::Meta::Class::Trait::Bag;
2 11 $Bolts::Meta::Class::Trait::Bag::VERSION = '0.143171';
3 # ABSTRACT: Metaclass role for Bolts-built bags
4  
5 11 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use Safe::Isa;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Scalar::Util qw( reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 has artifacts => (
12 is => 'ro',
13 required => 1,
14 44 ▶ default => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 11 traits => [ 'Hash' ],
16 handles => {
17 '_add_artifact' => 'set',
18 'list_artifacts' => 'elements',
19 },
20 );
21  
22  
23 11 has such_that_isa => (
24 is => 'rw',
25 isa => 'Moose::Meta::TypeConstraint',
26 predicate => 'has_such_that_isa',
27 );
28  
29  
30 11 has such_that_does => (
31 is => 'rw',
32 isa => 'Moose::Meta::TypeConstraint',
33 predicate => 'has_such_that_does',
34 );
35  
36  
37 53 ▶sub is_finished_bag {
Subroutine is_finished_bag: called CC=1 SCAR=0.0
Pod documented
38 53 my $meta = shift;
39 53 return $meta->is_immutable;
40 }
41  
42  
43 216 ▶sub add_artifact {
Subroutine add_artifact: called CC=10 SCAR=23.0
Pod documented
44 216 my ($meta, $name, $value, $such_that) = @_;
45
46 216 ▶ if (!defined $such_that and ($meta->has_such_that_isa
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $such_that and $meta->has_such_that_isa || $meta->has_such_that_does) 167 49 216
Condition83%5/6
not defined $such_that and $meta->has_such_that_isa || $meta->has_such_that_does
!ll&&!rl&&r
049167
$meta->has_such_that_isa or $meta->has_such_that_does
l!l&&r!l&&!r
316449
MC/DC66%2/3
not defined $such_that and $meta->has_such_that_isa || $meta->has_such_that_does
not defined $such_that $meta->has_such_that_isa $meta->has_such_that_does
Truth table75%3/4
not(A) and B or C
A= not defined $such_thatB= $meta->has_such_that_isaC= $meta->has_such_that_does
ABCresult
0XX0
1000
11X1
1011
47 or $meta->has_such_that_does)) {
48 167 $such_that = {};
49 167 ▶ $such_that->{isa} = $meta->such_that_isa
Branch: 1 branch
BranchTrueFalseTotal
if $meta->has_such_that_isa 3 164 167
50 if $meta->has_such_that_isa;
51 167 ▶ $such_that->{does} = $meta->such_that_does
Branch: 1 branch
BranchTrueFalseTotal
if $meta->has_such_that_does 164 3 167
52 if $meta->has_such_that_does;
53 }
54  
55 216 ▶ if ($value->$_does('Bolts::Role::Artifact')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value->$Bolts::Meta::Class::Trait::Bag::_does('Bolts::Role::Artifact')) { } 214 2 216
elsif (defined builtin::reftype($value) and builtin::reftype($value) eq 'CODE') { } 1 1 2
56 214 ▶ $value->such_that($such_that) if $such_that;
Branch: 1 branch
BranchTrueFalseTotal
if $such_that 167 47 214
57 214 $meta->_add_artifact($name => $value);
58 214 ▶ $meta->add_method($name => sub { $value });
Subroutine parent_bag: called CC=1 SCAR=0.0
Subroutine prototype: called CC=1 SCAR=0.0
59 }
60  
61 ▶ elsif (defined reftype($value) and reftype($value) eq 'CODE') {
Condition66%2/3
defined builtin::reftype($value) and builtin::reftype($value) eq "CODE"
!ll&&!rl&&r
101
MC/DC50%1/2
defined builtin::reftype($value) and builtin::reftype($value) eq "CODE"
defined builtin::reftype($value) builtin::reftype($value) eq "CODE"
Truth table66%2/3
A and B
A= defined builtin::reftype($value)B= builtin::reftype($value) eq "CODE"
ABresult
0X0
100
111
62 1 my $thunk = Bolts::Artifact::Thunk->new(
63 %$such_that,
64 thunk => $value,
65 );
66  
67 1 $meta->_add_artifact($name => $thunk);
68 1 ▶ $meta->add_method($name => sub { $thunk });
Subroutine __ANON__: called CC=1 SCAR=0.0
69 }
70  
71 else {
72 # TODO It would be better to assert the validity of the checks on
73 # the value immediately.
74  
75 my $thunk = Bolts::Artifact::Thunk->new(
76 %$such_that,
77 2 ▶ thunk => sub { $value },
Subroutine __ANON__: called CC=1 SCAR=0.0
78 1 );
79  
80 1 $meta->_add_artifact($name => $thunk);
81 1 ▶ $meta->add_method($name => sub { $thunk });
Subroutine __ANON__: called CC=1 SCAR=0.0
82 }
83  
84 }
85  
86  
87 24 ▶sub finish_bag {
Subroutine finish_bag: called CC=1 SCAR=0.0
Pod documented
88 24 my ($meta) = @_;
89  
90 24 $meta->make_immutable(
91 replace_constructor => 1,
92 replace_destructor => 1,
93 );
94  
95 24 return $meta;
96 }
97  
98 0 ▶sub _wrap_method_in_such_that_check {
Subroutine _wrap_method_in_such_that_check: not called CC=3 SCAR=24.8
99 0 my ($meta, $code, $such_that) = @_;
100  
101 0 my $wrapped;
102 0 ▶ if (defined $such_that->{isa} or defined $such_that->{does}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $such_that->{'isa'} or defined $such_that->{'does'}) { } 0 0 0
Condition0%0/3
defined $such_that->{"isa"} or defined $such_that->{"does"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $such_that->{"isa"} or defined $such_that->{"does"}
defined $such_that->{"isa"} defined $such_that->{"does"}
Truth table0%0/3
A or B
A= defined $such_that->{"isa"}B= defined $such_that->{"does"}
ABresult
1X1
011
000
103 0 ▶ $wrapped = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
104 0 my $result = $code->(@_);
105  
106 $such_that->{isa}->assert_valid($result)
107 0 ▶ if defined $such_that->{isa};
Branch: 1 branch
BranchTrueFalseTotal
if defined $such_that->{"isa"} 0 0 0
108  
109 $such_that->{does}->assert_valid($result)
110 0 ▶ if defined $such_that->{does};
Branch: 1 branch
BranchTrueFalseTotal
if defined $such_that->{"does"} 0 0 0
111  
112 0 return $result;
113 0 };
114 }
115 else {
116 0 ▶ $wrapped = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
117 0 return scalar $code->(@_);
118 0 };
119 }
120  
121 0 return $wrapped;
122 }
123  
124  
125 11 1;
126  
127 __END__
« Bolts/Inference/Moose.pm ↑ Summary Bolts/Meta/Attribute/Trait/Initializer.pm »