MooseX/Enumeration/Meta/Method/Accessor/Native/Enumeration/assign.pm

filter: Statementstmt 95.9% 71 / 74 Branchbran 75.0% 9 / 12 Conditioncond 62.5% 15 / 24 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 82.7% 110 / 133 CC 15 SCAR 18.7
CC
15
Cov
86%
__ANON__
12.8
_potential_value
2.4
_inline_force_build
2.0
CRAP 6.5
↑ Summary MooseX/Enumeration/Meta/Attribute/Native/Trait/Enumeration.pm »
1 3 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package MooseX::Enumeration::Meta::Method::Accessor::Native::Enumeration::assign;
6 3 our $AUTHORITY = 'cpan:TOBYINK';
7 3 our $VERSION = '0.010';
8  
9 3 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 with 'Moose::Meta::Method::Accessor::Native::Writer';
11  
12 9 ▶around _minimum_arguments => sub { 1 };
Subroutine __ANON__: called CC=1 SCAR=0.0
13 9 ▶around _maximum_arguments => sub { 2 };
Subroutine __ANON__: called CC=1 SCAR=0.0
14  
15 sub _potential_value
16 3 ▶{
Subroutine _potential_value: called CC=2 SCAR=8.5
17 3 my $self = shift;
18 3 my $type = $self->associated_attribute->type_constraint;
19
20 3 ▶ if ($self->associated_attribute->should_coerce)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->associated_attribute->should_coerce) 0 3 3
21 {
22 0 my $type = $self->associated_attribute->type_constraint;
23 0 $self->_eval_environment->{'$type'} = $type;
24 0 return '$type->coerce($_[0])';
25 }
26
27 3 '$_[0]';
28 }
29  
30 around _inline_return_value => sub
31 9 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
32 # Technically speaking, we can't rely on the invocant
33 # being called '$self'
34 9 '$self';
35 3 };
36  
37 around _inline_process_arguments => sub
38 3 ▶{
Subroutine __ANON__: called CC=2 SCAR=7.0
39 3 my $next = shift;
40 3 my $self = shift;
41 3 my ($inv, $slot_access) = @_;
42
43 3 my $orig = $self->$next(@_);
44 3 ▶ $orig = "" unless defined $orig;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $orig 3 0 3
45
46 3 $self->_inline_check_allowed_transition($slot_access, 1) . $orig;
47 3 };
48  
49 6 ▶sub _inline_force_build {
Subroutine _inline_force_build: called CC=2 SCAR=7.0
50 6 my $self = shift;
51 6 my ($inv, $slot_access) = @_;
52
53 6 my $method = $self->associated_attribute->get_read_method;
54
55 6 ▶ sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$method ? : 6 0 6
56 'if (!exists %s) { %s }',
57 $slot_access,
58 $method
59 ? "${inv}->${method}"
60 : sprintf("%s = Moose::Util::find_meta(%s)->find_attribute_by_name(%s)->get_value(%s)", $slot_access, $inv, B::perlstring($self->associate_attribute->name, $inv))
61 );
62 }
63  
64 sub _inline_check_allowed_transition
65 6 ▶{
Subroutine _inline_check_allowed_transition: called CC=1 SCAR=0.0
66 6 require B;
67 6 require match::simple;
68
69 6 my $self = shift;
70 6 my ($slot_access, $allow) = @_;
71
72 6 my $die = $self->_inline_allowed_transition_exception($slot_access);
73 6 my $force_build = $self->_inline_force_build('$self', $slot_access);
74 6 return "$force_build; \$#_ < $allow or match::simple::match($slot_access, \$_[$allow]) or $die;";
75 }
76  
77 sub _inline_allowed_transition_exception
78 9 ▶{
Subroutine _inline_allowed_transition_exception: called CC=1 SCAR=0.0
79 9 my $self = shift;
80 9 my ($slot_access) = @_;
81
82 9 my $name = B::perlstring($self->name);
83 9 my $attr = B::perlstring($self->associated_attribute->name);
84 9 my $tmpl = '"Method %s cannot be called when attribute %s has value %s, stopped"';
85
86 9 return "Carp::confess(sprintf($tmpl, $name, $attr, $slot_access))";
87 }
88  
89 around _generate_method => sub
90 9 ▶{
Subroutine __ANON__: called CC=12 SCAR=25.5
91 9 my $next = shift;
92 9 my $self = shift;
93 ### $self->$next(@_); # can't remember why we do this???
94
95 9 my $inv = '$self';
96 9 my @curried = @{ $self->curried_arguments };
97 9 my $type = $self->associated_attribute->type_constraint;
98 9 my $coerce = $self->associated_attribute->should_coerce;
99
100 # Optimized accessor for one curried argument
101 9 ▶ if ( @curried==1
Branch: 1 branch
BranchTrueFalseTotal
if (@curried == 1 and not $coerce and not $self->associated_attribute->is_lazy and $self->_maximum_arguments == 2 and $self->_minimum_arguments == 1) 3 6 9
Condition66%8/12
@curried == 1 and not $coerce and not $self->associated_attribute->is_lazy and $self->_maximum_arguments == 2 and $self->_minimum_arguments == 1
!ll&&!rl&&r
603
@curried == 1 and not $coerce and not $self->associated_attribute->is_lazy and $self->_maximum_arguments == 2
!ll&&!rl&&r
603
@curried == 1 and not $coerce and not $self->associated_attribute->is_lazy
!ll&&!rl&&r
603
@curried == 1 and not $coerce
!ll&&!rl&&r
603
MC/DC20%1/5
@curried == 1 and not $coerce and not $self->associated_attribute->is_lazy and $self->_maximum_arguments == 2 and $self->_minimum_arguments == 1
@curried == 1 not $coerce not $self->associated_attribute->is_lazy $self->_maximum_arguments == 2 $self->_minimum_arguments == 1
Truth table33%2/6
A and not(B) and not(C) and D and E
A= @curried == 1B= not $coerceC= not $self->associated_attribute->is_lazyD= $self->_maximum_arguments == 2E= $self->_minimum_arguments == 1
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
102 and !$coerce
103 and not $self->associated_attribute->is_lazy
104 and $self->_maximum_arguments==2
105 and $self->_minimum_arguments==1 )
106 {
107 3 $type->assert_valid($curried[0]);
108
109 3 my $slot_access = $self->_get_value($inv);
110
111 3 require B;
112 3 require Moose::Util;
113 3 return sprintf(
114 'sub { my %s = shift; %s if @_ > 1; %s; %s; %s }',
115 $inv,
116 "Moose::Util::throw_exception('MethodExpectsFewerArgs', 'method_name', 'assign', 'maximum_args', 2)",
117 $self->_inline_check_allowed_transition($slot_access, 0),
118 $self->_inline_set_new_value($inv, B::perlstring($curried[0]), $slot_access),
119 $self->_inline_return_value($slot_access, 'for writer'),
120 );
121 }
122
123 # Optimized accessor for two curried arguments
124 6 ▶ if ( @curried==2
Branch: 1 branch
BranchTrueFalseTotal
if (@curried == 2 and not $coerce and not $self->associated_attribute->is_lazy and $self->_maximum_arguments == 2 and $self->_minimum_arguments == 1) 3 3 6
Condition58%7/12
@curried == 2 and not $coerce and not $self->associated_attribute->is_lazy and $self->_maximum_arguments == 2 and $self->_minimum_arguments == 1
!ll&&!rl&&r
303
@curried == 2 and not $coerce and not $self->associated_attribute->is_lazy and $self->_maximum_arguments == 2
!ll&&!rl&&r
303
@curried == 2 and not $coerce and not $self->associated_attribute->is_lazy
!ll&&!rl&&r
033
@curried == 2 and not $coerce
!ll&&!rl&&r
006
MC/DC20%1/5
@curried == 2 and not $coerce and not $self->associated_attribute->is_lazy and $self->_maximum_arguments == 2 and $self->_minimum_arguments == 1
@curried == 2 not $coerce not $self->associated_attribute->is_lazy $self->_maximum_arguments == 2 $self->_minimum_arguments == 1
Truth table33%2/6
A and not(B) and not(C) and D and E
A= @curried == 2B= not $coerceC= not $self->associated_attribute->is_lazyD= $self->_maximum_arguments == 2E= $self->_minimum_arguments == 1
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
125 and !$coerce
126 and not $self->associated_attribute->is_lazy
127 and $self->_maximum_arguments==2
128 and $self->_minimum_arguments==1 )
129 {
130 3 $type->assert_valid($curried[0]);
131
132 3 my $slot_access = $self->_get_value($inv);
133
134 3 ▶ if ($type->check($curried[1]))
Branch: 1 branch
BranchTrueFalseTotal
if ($type->check($curried[1])) { } 1 2 3
135 {
136 1 return sprintf(
137 'sub { my %s = shift; %s if @_; return %s if %s eq %s; %s eq %s or %s; %s; %s }',
138 $inv,
139 "Moose::Util::throw_exception('MethodExpectsFewerArgs', 'method_name', 'assign', 'maximum_args', 2)",
140 $inv,
141 $slot_access,
142 B::perlstring($curried[0]),
143 $slot_access,
144 B::perlstring($curried[1]),
145 $self->_inline_allowed_transition_exception($slot_access),
146 $self->_inline_set_new_value($inv, B::perlstring($curried[0]), $slot_access),
147 $self->_inline_return_value($slot_access, 'for writer'),
148 );
149 }
150
151 else
152 {
153 2 require match::simple;
154
155 2 return sprintf(
156 'sub { my %s = shift; %s if @_; return %s if %s eq %s; match::simple::match(%s, $curried[1]) or %s; %s; %s }',
157 $inv,
158 "Moose::Util::throw_exception('MethodExpectsFewerArgs', 'method_name', 'assign', 'maximum_args', 2)",
159 $inv,
160 $slot_access,
161 B::perlstring($curried[0]),
162 $slot_access,
163 $self->_inline_allowed_transition_exception($slot_access),
164 $self->_inline_set_new_value($inv, B::perlstring($curried[0]), $slot_access),
165 $self->_inline_return_value($slot_access, 'for writer'),
166 );
167 }
168 }
169  
170 # Otherwise we should trust the default implementation
171 # from Moose::Meta::Method::Accessor::Native::Reader.
172 3 $self->$next(@_);
173 3 };
174  
175 3 1;
↑ Summary MooseX/Enumeration/Meta/Attribute/Native/Trait/Enumeration.pm »