blib/lib/Moose/Meta/Method/Accessor/Native/Writer.pm

filter: Statementstmt 95.3% 82 / 86 Branchbran 83.3% 10 / 12 Conditioncond 59.2% 16 / 27 MC/DCmcdc 35.7% 5 / 14 Subroutinesub 95.8% 23 / 24 Podpod n/a totaltotal 83.4% 136 / 163 CC 16 SCAR 9.6
CC
16
Cov
86%
_is_root_type
5.7
_constraint_must_be_checked
4.6
_inline_set_new_value
4.0
CRAP 2.6
« blib/lib/Class/MOP/Mixin/HasAttributes.pm ↑ Summary blib/lib/Class/MOP/Module.pm »
1 package Moose::Meta::Method::Accessor::Native::Writer;
2 25 our $VERSION = '2.4001';
3  
4 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 25 ▶use List::Util 1.33 qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 ▶use Moose::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 25 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 25 with 'Moose::Meta::Method::Accessor::Native';
13  
14 25 requires '_potential_value';
15  
16 529 ▶sub _generate_method {
Subroutine _generate_method: called CC=1 SCAR=0.0
17 529 my $self = shift;
18  
19 529 my $inv = '$self';
20 529 my $slot_access = $self->_get_value($inv);
21  
22 return (
23 529 'sub {',
24 'my ' . $inv . ' = shift;',
25 $self->_inline_curried_arguments,
26 $self->_inline_writer_core($inv, $slot_access),
27 '}',
28 );
29 }
30  
31 613 ▶sub _inline_writer_core {
Subroutine _inline_writer_core: called CC=2 SCAR=6.9
32 613 my $self = shift;
33 613 my ($inv, $slot_access) = @_;
34  
35 613 my $potential = $self->_potential_value($slot_access);
36 613 my $old = '@old';
37  
38 613 my @code;
39 613 push @code, (
40 $self->_inline_check_argument_count,
41 $self->_inline_process_arguments($inv, $slot_access),
42 $self->_inline_check_arguments('for writer'),
43 $self->_inline_check_lazy($inv, '$type_constraint', '$type_coercion', '$type_message'),
44 );
45  
46 613 ▶ if ($self->_return_value($slot_access)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_return_value($slot_access)) 572 41 613
47 # some writers will save the return value in this variable when they
48 # generate the potential value.
49 572 push @code, 'my @return;'
50 }
51  
52 613 push @code, (
53 $self->_inline_coerce_new_values,
54 $self->_inline_copy_native_value(\$potential),
55 $self->_inline_tc_code($potential, '$type_constraint', '$type_coercion', '$type_message'),
56 $self->_inline_get_old_value_for_trigger($inv, $old),
57 $self->_inline_capture_return_value($slot_access),
58 $self->_inline_set_new_value($inv, $potential, $slot_access),
59 $self->_inline_trigger($inv, $slot_access, $old),
60 $self->_inline_return_value($slot_access, 'for writer'),
61 );
62  
63 613 return @code;
64 }
65  
66 474 ▶sub _inline_process_arguments { return }
Subroutine _inline_process_arguments: called CC=1 SCAR=0.0
67  
68 391 ▶sub _inline_check_arguments { return }
Subroutine _inline_check_arguments: called CC=1 SCAR=0.0
69  
70 256 ▶sub _inline_coerce_new_values { return }
Subroutine _inline_coerce_new_values: called CC=1 SCAR=0.0
71  
72 512 ▶sub _writer_value_needs_copy {
Subroutine _writer_value_needs_copy: called CC=1 SCAR=0.0
73 512 my $self = shift;
74  
75 512 return $self->_constraint_must_be_checked;
76 }
77  
78 1493 ▶sub _constraint_must_be_checked {
Subroutine _constraint_must_be_checked: called CC=4 SCAR=15.2
79 1493 my $self = shift;
80  
81 1493 my $attr = $self->associated_attribute;
82  
83 1493 ▶ return $attr->has_type_constraint
Condition55%5/9
$attr->has_type_constraint && (!$self->_is_root_type($attr->type_constraint) || $attr->should_coerce && $attr->type_constraint->has_coercion)
!ll&&!rl&&r
0512981
not $self->_is_root_type($attr->type_constraint) or $attr->should_coerce and $attr->type_constraint->has_coercion
l!l&&r!l&&!r
9810512
$attr->should_coerce and $attr->type_constraint->has_coercion
!ll&&!rl&&r
51200
MC/DC25%1/4
$attr->has_type_constraint && (!$self->_is_root_type($attr->type_constraint) || $attr->should_coerce && $attr->type_constraint->has_coercion)
$attr->has_type_constraint not $self->_is_root_type($attr->type_constraint) $attr->should_coerce $attr->type_constraint->has_coercion
Truth table40%2/5
A && not(B) or C and D
A= $attr->has_type_constraintB= not $self->_is_root_type($attr->type_constraint)C= $attr->should_coerceD= $attr->type_constraint->has_coercion
ABCDresult
0XXX0
100X0
10100
11XX1
10111
84 && ( !$self->_is_root_type( $attr->type_constraint )
85 || ( $attr->should_coerce && $attr->type_constraint->has_coercion ) );
86 }
87  
88 1699 ▶sub _is_root_type {
Subroutine _is_root_type: called CC=4 SCAR=17.4
89 1699 my $self = shift;
90 1699 my $type = shift;
91  
92 1699 ▶ if ( blessed($type)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type) and $type->can('does') and $type->does('Specio::Constraint::Role::Interface')) { } 0 1699 1699
Condition33%2/6
builtin::blessed($type) and $type->can("does") and $type->does("Specio::Constraint::Role::Interface")
!ll&&!rl&&r
169900
builtin::blessed($type) and $type->can("does")
!ll&&!rl&&r
016990
MC/DC0%0/3
builtin::blessed($type) and $type->can("does") and $type->does("Specio::Constraint::Role::Interface")
builtin::blessed($type) $type->can("does") $type->does("Specio::Constraint::Role::Interface")
Truth table25%1/4
A and B and C
A= builtin::blessed($type)B= $type->can("does")C= $type->does("Specio::Constraint::Role::Interface")
ABCresult
0XX0
10X0
1100
1111
93 && $type->can('does')
94 && $type->does('Specio::Constraint::Role::Interface') )
95 {
96 0 require Specio::Library::Builtins;
97 return
98 0 ▶ any { $type->is_same_type_as( Specio::Library::Builtins::t($_) ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 0 @{ $self->root_types };
100 }
101 else {
102 1699 my $name = $type->name;
103 1699 ▶ return any { $name eq $_ } @{ $self->root_types };
Subroutine __ANON__: called CC=1 SCAR=0.0
104 }
105 }
106  
107 613 ▶sub _inline_copy_native_value {
Subroutine _inline_copy_native_value: called CC=2 SCAR=6.9
108 613 my $self = shift;
109 613 my ($potential_ref) = @_;
110  
111 613 ▶ return unless $self->_writer_value_needs_copy;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_writer_value_needs_copy 446 167 613
112  
113 167 my $code = 'my $potential = ' . ${$potential_ref} . ';';
114  
115 167 ${$potential_ref} = '$potential';
116  
117 167 return $code;
118 }
119  
120 613 ▶around _inline_tc_code => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
121 613 my $orig = shift;
122 613 my $self = shift;
123 613 my ($value, $tc, $coercion, $message, $for_lazy) = @_;
124  
125 613 ▶ return unless $for_lazy || $self->_constraint_must_be_checked;
Branch: 1 branch
BranchTrueFalseTotal
unless $for_lazy or $self->_constraint_must_be_checked 228 385 613
Condition66%2/3
$for_lazy or $self->_constraint_must_be_checked
l!l&&r!l&&!r
0385228
MC/DC50%1/2
$for_lazy or $self->_constraint_must_be_checked
$for_lazy $self->_constraint_must_be_checked
Truth table66%2/3
A or B
A= $for_lazyB= $self->_constraint_must_be_checked
ABresult
1X1
011
000
126  
127 385 return $self->$orig(@_);
128 25 };
129  
130 97 ▶around _inline_check_constraint => sub {
Subroutine __ANON__: called CC=3 SCAR=11.8
131 97 my $orig = shift;
132 97 my $self = shift;
133 97 my ($value, $tc, $message, $for_lazy) = @_;
134  
135 97 ▶ return unless $for_lazy || $self->_constraint_must_be_checked;
Branch: 1 branch
BranchTrueFalseTotal
unless $for_lazy or $self->_constraint_must_be_checked 0 97 97
Condition33%1/3
$for_lazy or $self->_constraint_must_be_checked
l!l&&r!l&&!r
0970
MC/DC0%0/2
$for_lazy or $self->_constraint_must_be_checked
$for_lazy $self->_constraint_must_be_checked
Truth table33%1/3
A or B
A= $for_lazyB= $self->_constraint_must_be_checked
ABresult
1X1
011
000
136  
137 97 return $self->$orig(@_);
138 25 };
139  
140 593 ▶sub _inline_capture_return_value { return }
Subroutine _inline_capture_return_value: called CC=1 SCAR=0.0
141  
142 613 ▶sub _inline_set_new_value {
Subroutine _inline_set_new_value: called CC=4 SCAR=13.9
143 613 my $self = shift;
144  
145 613 ▶ return $self->_inline_store_value(@_)
Branch: 1 branch
BranchTrueFalseTotal
if $self->_writer_value_needs_copy or not $self->_slot_access_can_be_inlined or not $self->_get_is_lvalue 282 331 613
Condition100%6/6
$self->_writer_value_needs_copy or not $self->_slot_access_can_be_inlined or not $self->_get_is_lvalue
l!l&&r!l&&!r
21963331
$self->_writer_value_needs_copy or not $self->_slot_access_can_be_inlined
l!l&&r!l&&!r
16752394
MC/DC100%3/3
$self->_writer_value_needs_copy or not $self->_slot_access_can_be_inlined or not $self->_get_is_lvalue
$self->_writer_value_needs_copy not $self->_slot_access_can_be_inlined not $self->_get_is_lvalue
Truth table100%4/4
A or not(B) or not(C)
A= $self->_writer_value_needs_copyB= not $self->_slot_access_can_be_inlinedC= not $self->_get_is_lvalue
ABCresult
1XX1
01X1
0011
0000
146 if $self->_writer_value_needs_copy
147 || !$self->_slot_access_can_be_inlined
148 || !$self->_get_is_lvalue;
149  
150 331 return $self->_inline_optimized_set_new_value(@_);
151 }
152  
153 394 ▶sub _get_is_lvalue {
Subroutine _get_is_lvalue: called CC=1 SCAR=0.0
154 394 my $self = shift;
155  
156 394 return $self->associated_attribute->associated_class->instance_metaclass->inline_get_is_lvalue;
157 }
158  
159 13 ▶sub _inline_optimized_set_new_value {
Subroutine _inline_optimized_set_new_value: called CC=1 SCAR=0.0
160 13 my $self = shift;
161  
162 13 return $self->_inline_store_value(@_);
163 }
164  
165 422 ▶sub _return_value {
Subroutine _return_value: called CC=1 SCAR=0.0
166 422 my $self = shift;
167 422 my ($slot_access) = @_;
168  
169 422 return $slot_access;
170 }
171  
172 25 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
173  
174 25 1;
« blib/lib/Class/MOP/Mixin/HasAttributes.pm ↑ Summary blib/lib/Class/MOP/Module.pm »