Sub/Accessor/Small.pm

filter: Statementstmt 64.8% 286 / 441 Branchbran 42.7% 123 / 288 Conditioncond 32.5% 68 / 209 MC/DCmcdc 12.0% 14 / 116 Subroutinesub 77.6% 59 / 76 Podpod 2.1% 1 / 47 totaltotal 46.8% 551 / 1177 CC 223 SCAR 38.2
CC
223
Cov
51%
canonicalize_is
249.6
_is_bool
110.0
inline_type_assertion
107.3
CRAP 45.4
↑ Summary Lexical/Accessor.pm »
1 10 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶no warnings qw( void once uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Sub::Accessor::Small;
7  
8 10 our $AUTHORITY = 'cpan:TOBYINK';
9 10 our $VERSION = '1.001002';
10 10 our @ISA = qw/ Exporter::Tiny /;
11 10 our @EXPORT_OK = qw/ has /;
12  
13 10 ▶use Carp qw( carp croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use Eval::TypeTiny qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 ▶use Exporter::Tiny qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 ▶use Scalar::Util qw( blessed reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 10 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=16.3
19 *fieldhash =
20 10 eval { require Hash::FieldHash; \&Hash::FieldHash::fieldhash } ||
21 0 eval { require Hash::Util::FieldHash; \&Hash::Util::FieldHash::fieldhash } ||
22 0 ▶ do { require Hash::Util::FieldHash::Compat; \&Hash::Util::FieldHash::Compat::fieldhash } ;;
Condition33%2/6
eval { do { require Hash::FieldHash; \&Hash::FieldHash::fieldhash } } || eval { do { require Hash::Util::FieldHash; \&Hash::Util::FieldHash::fieldhash } } || do { require Hash::Util::FieldHash::Compat; \&Hash::Util::FieldHash::Compat::fieldhash }
l!l&&r!l&&!r
1000
eval { do { require Hash::FieldHash; \&Hash::FieldHash::fieldhash } } or eval { do { require Hash::Util::FieldHash; \&Hash::Util::FieldHash::fieldhash } }
l!l&&r!l&&!r
1000
MC/DC0%0/3
eval { do { require Hash::FieldHash; \&Hash::FieldHash::fieldhash } } || eval { do { require Hash::Util::FieldHash; \&Hash::Util::FieldHash::fieldhash } } || do { require Hash::Util::FieldHash::Compat; \&Hash::Util::FieldHash::Compat::fieldhash }
eval { do { require Hash::FieldHash; \&Hash::FieldHash::fieldhash } } eval { do { require Hash::Util::FieldHash; \&Hash::Util::FieldHash::fieldhash } } do { require Hash::Util::FieldHash::Compat; \&Hash::Util::FieldHash::Compat::fieldhash }
Truth table25%1/4
A or B || C
A= eval { do { require Hash::FieldHash; \&Hash::FieldHash::fieldhash } }B= eval { do { require Hash::Util::FieldHash; \&Hash::Util::FieldHash::fieldhash } }C= do { require Hash::Util::FieldHash::Compat; \&Hash::Util::FieldHash::Compat::fieldhash }
ABCresult
1XX1
01X1
0011
0000
23 };
24  
25 10 fieldhash( our %FIELDS );
26  
27 10 my $set_subname_is_fake = 0;
28 *set_subname =
29 10 ▶ eval { require Sub::Util } ? \&Sub::Util::set_subname :
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Sub::Name } } ? : 0 0 0
30 0 eval { require Sub::Name } ? \&Sub::Name::subname :
31 0 ▶ do { $set_subname_is_fake++; sub { pop; } };
Subroutine __ANON__: not called CC=1 SCAR=2.6
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Sub::Util } } ? : 10 0 10
32  
33 10 ▶sub _generate_has : method
Subroutine _generate_has: called CC=1 SCAR=0.0
34 {
35 10 my $me = shift;
36 10 my (undef, undef, $export_opts) = @_;
37
38 my $code = sub
39 10 ▶ {
Subroutine lexical_has: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Pod documented
40 10 my $attr = $me->new_from_has($export_opts, @_);
41 10 $attr->install_accessors;
42 10 };
43
44 10 return set_subname( "$me\::has", $code );
45 }
46  
47 {
48 10 my $uniq = 0;
49 34 ▶ sub new_from_has : method
Subroutine new_from_has: called CC=6 SCAR=18.0
Pod undocumented
50 {
51 34 my $me = shift;
52 34 ▶ my $export_opts = ref($_[0]) eq 'HASH' ? shift(@_) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 28 6 34
53 34 ▶ my ($name, %opts) = (@_%2) ? @_ : (undef, @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 34 0 34
54
55 34 my $package;
56 $package = $export_opts->{into}
57 34 ▶ if defined($export_opts->{into}) && !ref($export_opts->{into});
Branch: 1 branch
BranchTrueFalseTotal
if defined $export_opts->{"into"} and not ref $export_opts->{"into"} 28 6 34
Condition66%2/3
defined $export_opts->{"into"} and not ref $export_opts->{"into"}
!ll&&!rl&&r
6028
MC/DC50%1/2
defined $export_opts->{"into"} and not ref $export_opts->{"into"}
defined $export_opts->{"into"} not ref $export_opts->{"into"}
Truth table66%2/3
A and not(B)
A= defined $export_opts->{"into"}B= not ref $export_opts->{"into"}
ABresult
0X0
100
111
58
59 34 ▶ $me->new(
Branch: 1 branch
BranchTrueFalseTotal
$package ? : 28 6 34
60 slot => $name,
61 id => $uniq++,
62 _export => $export_opts,
63 ($package ? (package => $package) : ()),
64 %opts,
65 );
66 }
67 }
68  
69 10 ▶sub _create_child : method
Subroutine _create_child: called CC=3 SCAR=11.4
70 {
71 6 my $me = shift;
72 6 my $name = shift;
73
74 return ref($me)->new_from_has(
75 $name,
76 $me->{package} ? (package => $me->{package}) : (),
77 6 ▶ $me->{_export} ? (_export => $me->{_export}) : (),
Branch: 2 branches
BranchTrueFalseTotal
$me->{'package'} ? : 6 0 6
$me->{'_export'} ? : 6 0 6
78 @_,
79 );
80 }
81  
82 0 ▶sub has : method
Subroutine has: not called CC=1 SCAR=6.9
Pod undocumented
83 {
84 0 my $me = shift;
85 0 my $attr = $me->new_from_has(@_);
86 0 $attr->install_accessors;
87 }
88  
89 34 ▶sub new : method
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
90 {
91 34 my $me = shift;
92 34 my (%opts) = @_;
93 34 my $self = bless(\%opts, $me);
94 34 $self->canonicalize_opts;
95 34 return $self;
96 }
97  
98 15 ▶sub make_var_name : method
Subroutine make_var_name: called CC=2 SCAR=7.1
Pod undocumented
99 {
100 15 my $me = shift;
101 15 my $stem = shift;
102 15 ▶ my $sigil = shift || '$';
Condition50%1/2
shift() || '$'
l!l
015
MC/DC0%0/1
shift() || '$'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
103
104 15 my $varname = sprintf '%s_for_%s', $stem, $me->{slot};
105 0 $varname =~ s{([\WX])}{sprintf q{X%04XX}, ord($1)}eg;
106
107 15 return $sigil . $varname;
108 }
109  
110 28 ▶sub install_accessors : method
Subroutine install_accessors: called CC=17 SCAR=29.7
Pod undocumented
111 {
112 28 my $me = shift;
113
114 28 for my $type (qw( accessor reader writer predicate clearer ))
115 {
116 140 ▶ next unless defined $me->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $me->{$type} 88 52 140
117 52 $me->install_coderef($me->{$type}, $me->$type);
118 }
119
120 28 ▶ if (defined $me->{handles}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $me->{"handles"}) 1 27 28
121
122 1 my $shv_data;
123 1 ▶ if ($me->{traits} or $me->{handles_via}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"traits"} or $me->{"handles_via"}) 1 0 1
Condition33%1/3
$me->{"traits"} or $me->{"handles_via"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$me->{"traits"} or $me->{"handles_via"}
$me->{"traits"} $me->{"handles_via"}
Truth table33%1/3
A or B
A= $me->{"traits"}B= $me->{"handles_via"}
ABresult
1X1
011
000
124
125 1 my @pairs = $me->expand_handles;
126 1 my %handles_map;
127 1 ▶ while ( @pairs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pairs) 2 1 3
128 2 my ( $name ) = splice( @pairs, 0, 2 );
129 2 $handles_map{"$name"} = $name;
130 }
131
132 1 delete local $me->{chain};
133 1 require Sub::HandlesVia::Toolkit::SubAccessorSmall;
134 1 my $SHV = 'Sub::HandlesVia::Toolkit::SubAccessorSmall'->new(
135 attr => $me,
136 handles_map => \%handles_map,
137 );
138 $shv_data = $SHV->clean_spec(
139 $me->{package},
140 $me->{slot},
141 1 +{%$me},
142 );
143 1 ▶ $shv_data and $SHV->install_delegations( $shv_data );
Branch: 1 branch
BranchTrueFalseTotal
$shv_data and $SHV->install_delegations($shv_data) 1 0 1
144 }
145
146 1 ▶ if (!$shv_data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($shv_data) 0 1 1
147 0 my @pairs = $me->expand_handles;
148 0 ▶ while (@pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pairs) 0 0 0
149 0 my ($target, $method) = splice(@pairs, 0, 2);
150 0 $me->install_coderef($target, $me->handles($method));
151 }
152 }
153 }
154
155 23 ▶ my @return = map { ( ref($_) eq 'REF' or ref($_) eq 'SCALAR' ) ? ${$_} : $_ }
Branch: 5 branches
BranchTrueFalseTotal
ref $_ eq 'REF' || ref $_ eq 'SCALAR' ? : 21 2 23
$me->{'is'} eq 'ro' ? : 4 24 28
$me->{'is'} eq 'rw' ? : 7 17 24
$me->{'is'} eq 'rwp' ? : 4 13 17
$me->{'is'} eq 'lazy' ? : 4 9 13
Condition66%2/3
ref $_ eq "REF" or ref $_ eq "SCALAR"
l!l&&r!l&&!r
2102
MC/DC50%1/2
ref $_ eq "REF" or ref $_ eq "SCALAR"
ref $_ eq "REF" ref $_ eq "SCALAR"
Truth table66%2/3
A or B
A= ref $_ eq "REF"B= ref $_ eq "SCALAR"
ABresult
1X1
011
000
156 $me->{is} eq 'ro' ? ($me->{reader}) :
157 $me->{is} eq 'rw' ? ($me->{accessor}) :
158 $me->{is} eq 'rwp' ? ($me->{reader}, $me->{writer}) :
159 28 $me->{is} eq 'lazy' ? ($me->{reader}) :
160 ();
161 28 ▶ wantarray ? @return : $return[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 24 28
162 }
163  
164 sub install_coderef
165 54 ▶{
Subroutine install_coderef: called CC=8 SCAR=24.8
Pod undocumented
166 54 my $me = shift;
167 54 my ($target, $coderef) = @_;
168
169 54 ▶ return unless defined $target;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target 0 54 54
170
171 54 ▶ if (!ref $target and $target =~ /\A[^\W0-9]\w*\z/)
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $target and $target =~ /\A[^\W0-9]\w*\z/) 11 43 54
Condition66%2/3
not ref $target and $target =~ /\A[^\W0-9]\w*\z/
!ll&&!rl&&r
43011
MC/DC50%1/2
not ref $target and $target =~ /\A[^\W0-9]\w*\z/
not ref $target $target =~ /\A[^\W0-9]\w*\z/
Truth table66%2/3
not(A) and B
A= not ref $targetB= $target =~ /\A[^\W0-9]\w*\z/
ABresult
0X0
100
111
172 {
173 11 my $name = "$me->{package}\::$target";
174 10 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
175 11 *$name = set_subname( $name, $coderef );
176 11 return;
177 }
178
179 43 ▶ if (ref($target) eq q(SCALAR) and not defined $$target)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $target eq "SCALAR" and not defined $$target) 43 0 43
Condition33%1/3
ref $target eq "SCALAR" and not defined $$target
!ll&&!rl&&r
0043
MC/DC0%0/2
ref $target eq "SCALAR" and not defined $$target
ref $target eq "SCALAR" not defined $$target
Truth table33%1/3
A and not(B)
A= ref $target eq "SCALAR"B= not defined $$target
ABresult
0X0
100
111
180 {
181 43 $$target = $coderef;
182 43 return;
183 }
184
185 0 ▶ if (!ref($target) and $target eq 1)
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $target and $target eq 1) 0 0 0
Condition0%0/3
not ref $target and $target eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $target and $target eq 1
not ref $target $target eq 1
Truth table0%0/3
not(A) and B
A= not ref $targetB= $target eq 1
ABresult
0X0
100
111
186 {
187 0 return;
188 }
189
190 0 croak "Expected installation target to be a method name or a reference to an undefined scalar; got $target";
191 }
192  
193 sub expand_handles
194 0 ▶{
Subroutine expand_handles: not called CC=3 SCAR=24.8
Pod undocumented
195 0 my $me = shift;
196
197 0 ▶ if (ref($me->{handles}) eq q(ARRAY))
Branch: 2 branches
BranchTrueFalseTotal
if (ref $me->{'handles'} eq 'ARRAY') { } 0 0 0
elsif (ref $me->{'handles'} eq 'HASH') { } 0 0 0
198 {
199 0 return map ($_=>$_), @{$me->{handles}};
200 }
201 elsif (ref($me->{handles}) eq q(HASH))
202 {
203 0 return %{$me->{handles}};
204 }
205
206 0 croak "Expected delegations to be a reference to an array or hash; got $me->{handles}";
207 }
208  
209 {
210 10 my %one = (
211 accessor => [qw/ %s %s /],
212 reader => [qw/ get_%s _get%s /],
213 writer => [qw/ set_%s _set%s /],
214 predicate => [qw/ has_%s _has%s /],
215 clearer => [qw/ clear_%s _clear%s /],
216 trigger => [qw/ _trigger_%s _trigger_%s /],
217 builder => [qw/ _build_%s _build_%s /],
218 );
219
220 34 ▶ sub canonicalize_1 : method
Subroutine canonicalize_1: called CC=7 SCAR=21.8
Pod undocumented
221 {
222 34 my $me = shift;
223
224 34 ▶ my $is_private = ($me->{slot} =~ /\A_/) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$me->{'slot'} =~ /\A_/ ? : 0 34 34
225
226 34 for my $type (keys %one)
227 {
228 238 ▶ next if !exists($me->{$type});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{$type} 182 56 238
229 56 ▶ next if ref($me->{$type});
Branch: 1 branch
BranchTrueFalseTotal
if ref $me->{$type} 47 9 56
230 9 ▶ next if $me->{$type} ne 1;
Branch: 1 branch
BranchTrueFalseTotal
if $me->{$type} ne 1 9 0 9
231
232 croak("Cannot interpret $type=>1 because attribute has no name defined")
233 0 ▶ if !defined $me->{slot};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $me->{"slot"} 0 0 0
234
235 0 $me->{$type} = sprintf($one{$type}[$is_private], $me->{slot});
236 }
237 }
238
239 34 ▶ sub canonicalize_builder : method
Subroutine canonicalize_builder: called CC=6 SCAR=32.2
Pod undocumented
240 {
241 34 my $me = shift;
242 34 my $name = $me->{slot};
243
244 34 ▶ if ( ref $me->{builder} eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $me->{"builder"} eq "CODE") 0 34 34
245
246 0 ▶ croak "builder => CODE requires Sub::Util or Sub::Name to be installed"
Branch: 1 branch
BranchTrueFalseTotal
if $set_subname_is_fake 0 0 0
247 if $set_subname_is_fake;
248
249 defined($name) && defined($me->{package})
250 0 ▶ or croak("Invalid builder; expected method name as string");
Branch: 1 branch
BranchTrueFalseTotal
defined $name and defined $me->{"package"} or croak("Invalid builder; expected method name as string") 0 0 0
Condition0%0/3
defined $name and defined $me->{"package"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and defined $me->{"package"}
defined $name defined $me->{"package"}
Truth table0%0/3
A and B
A= defined $nameB= defined $me->{"package"}
ABresult
0X0
100
111
251
252 0 my $code = delete $me->{builder};
253 0 ▶ my $is_private = ($name =~ /\A_/) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /\A_/ ? : 0 0 0
254 0 my $subname = sprintf $one{builder}[$is_private], $name;
255 0 $me->install_coderef( $subname, $code );
256 0 $me->{builder} = $subname;
257 }
258 }
259 }
260  
261 10 ▶sub canonicalize_is : method
Subroutine canonicalize_is: called CC=23 SCAR=55.2
Pod undocumented
262 {
263 8 my $me = shift;
264
265 8 ▶ if ( $me->{is} eq 'lazy' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"is"} eq "lazy") 0 8 8
266 0 ▶ $me->{lazy} = 1 if !exists($me->{lazy});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"lazy"} 0 0 0
267 0 ▶ $me->{builder} = 1 unless exists($me->{builder}) || exists($me->{default});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"builder"} or exists $me->{"default"} 0 0 0
Condition0%0/3
exists $me->{"builder"} or exists $me->{"default"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $me->{"builder"} or exists $me->{"default"}
exists $me->{"builder"} exists $me->{"default"}
Truth table0%0/3
A or B
A= exists $me->{"builder"}B= exists $me->{"default"}
ABresult
1X1
011
000
268 }
269
270 8 ▶ defined( my $name = $me->{slot} ) or return;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $name = $me->{"slot"}) or return 8 0 8
271
272 8 ▶ if ($me->{is} eq 'rw')
Branch: 4 branches
BranchTrueFalseTotal
if ($me->{'is'} eq 'rw') { } 2 6 8
elsif ($me->{'is'} eq 'ro') { } 0 6 6
elsif ($me->{'is'} eq 'rwp') { } 0 6 6
elsif ($me->{'is'} eq 'lazy') { } 0 6 6
273 {
274 $me->{accessor} = $name
275 2 ▶ unless exists $me->{accessor} or ( defined $me->{reader} and $me->{reader} eq $name );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"accessor"} or defined $me->{"reader"} and $me->{"reader"} eq $name 2 0 2
Condition33%2/6
exists $me->{"accessor"} or defined $me->{"reader"} and $me->{"reader"} eq $name
l!l&&r!l&&!r
002
defined $me->{"reader"} and $me->{"reader"} eq $name
!ll&&!rl&&r
200
MC/DC0%0/3
exists $me->{"accessor"} or defined $me->{"reader"} and $me->{"reader"} eq $name
exists $me->{"accessor"} defined $me->{"reader"} $me->{"reader"} eq $name
Truth table25%1/4
A or B and C
A= exists $me->{"accessor"}B= defined $me->{"reader"}C= $me->{"reader"} eq $name
ABCresult
1XX1
0111
00X0
0100
276 }
277 elsif ($me->{is} eq 'ro')
278 {
279 $me->{reader} = $name
280 0 ▶ unless exists $me->{reader} or ( defined $me->{accessor} and $me->{accessor} eq $name );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"reader"} or defined $me->{"accessor"} and $me->{"accessor"} eq $name 0 0 0
Condition0%0/6
exists $me->{"reader"} or defined $me->{"accessor"} and $me->{"accessor"} eq $name
l!l&&r!l&&!r
000
defined $me->{"accessor"} and $me->{"accessor"} eq $name
!ll&&!rl&&r
000
MC/DC0%0/3
exists $me->{"reader"} or defined $me->{"accessor"} and $me->{"accessor"} eq $name
exists $me->{"reader"} defined $me->{"accessor"} $me->{"accessor"} eq $name
Truth table0%0/4
A or B and C
A= exists $me->{"reader"}B= defined $me->{"accessor"}C= $me->{"accessor"} eq $name
ABCresult
1XX1
0111
00X0
0100
281 }
282 elsif ($me->{is} eq 'rwp')
283 {
284 $me->{reader} = $name
285 0 ▶ unless exists $me->{reader} or ( defined $me->{accessor} and $me->{accessor} eq $name );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"reader"} or defined $me->{"accessor"} and $me->{"accessor"} eq $name 0 0 0
Condition0%0/6
exists $me->{"reader"} or defined $me->{"accessor"} and $me->{"accessor"} eq $name
l!l&&r!l&&!r
000
defined $me->{"accessor"} and $me->{"accessor"} eq $name
!ll&&!rl&&r
000
MC/DC0%0/3
exists $me->{"reader"} or defined $me->{"accessor"} and $me->{"accessor"} eq $name
exists $me->{"reader"} defined $me->{"accessor"} $me->{"accessor"} eq $name
Truth table0%0/4
A or B and C
A= exists $me->{"reader"}B= defined $me->{"accessor"}C= $me->{"accessor"} eq $name
ABCresult
1XX1
0111
00X0
0100
286 $me->{writer} = "_set_$name"
287 0 ▶ unless exists $me->{writer};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"writer"} 0 0 0
288 }
289 elsif ($me->{is} eq 'lazy')
290 {
291 $me->{reader} = $name
292 0 ▶ unless exists $me->{reader} or ( defined $me->{accessor} and $me->{accessor} eq $name );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"reader"} or defined $me->{"accessor"} and $me->{"accessor"} eq $name 0 0 0
Condition0%0/6
exists $me->{"reader"} or defined $me->{"accessor"} and $me->{"accessor"} eq $name
l!l&&r!l&&!r
000
defined $me->{"accessor"} and $me->{"accessor"} eq $name
!ll&&!rl&&r
000
MC/DC0%0/3
exists $me->{"reader"} or defined $me->{"accessor"} and $me->{"accessor"} eq $name
exists $me->{"reader"} defined $me->{"accessor"} $me->{"accessor"} eq $name
Truth table0%0/4
A or B and C
A= exists $me->{"reader"}B= defined $me->{"accessor"}C= $me->{"accessor"} eq $name
ABCresult
1XX1
0111
00X0
0100
293 }
294 }
295  
296 34 ▶sub canonicalize_default : method
Subroutine canonicalize_default: called CC=8 SCAR=28.8
Pod undocumented
297 {
298 34 my $me = shift;
299 34 ▶ return unless exists $me->{default};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"default"} 29 5 34
300
301 5 my $ref = ref $me->{default};
302
303 0 ▶ if ( $ref eq 'ARRAY' and not @{$me->{default}} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'ARRAY' and not @{$me->{'default'};}) { } 0 5 5
elsif ($ref eq 'HASH' and not %{$me->{'default'};}) { } 0 10 10
Condition33%1/3
$ref eq "ARRAY" and not @{$me->{"default"};}
!ll&&!rl&&r
500
MC/DC0%0/2
$ref eq "ARRAY" and not @{$me->{"default"};}
$ref eq "ARRAY" not @{$me->{"default"};}
Truth table33%1/3
A and not(B)
A= $ref eq "ARRAY"B= not @{$me->{"default"};}
ABresult
0X0
100
111
304 0 $ref = 'SCALAR';
305 0 $me->{default} = \'[]';
306 }
307 0 ▶ elsif ( $ref eq 'HASH' and not %{$me->{default}} ) {
Condition33%1/3
$ref eq "HASH" and not %{$me->{"default"};}
!ll&&!rl&&r
500
MC/DC0%0/2
$ref eq "HASH" and not %{$me->{"default"};}
$ref eq "HASH" not %{$me->{"default"};}
Truth table33%1/3
A and not(B)
A= $ref eq "HASH"B= not %{$me->{"default"};}
ABresult
0X0
100
111
308 0 $ref = 'SCALAR';
309 0 $me->{default} = \'{}';
310 }
311
312 5 ▶ !$ref or $ref =~ /^(CODE|SCALAR)$/ or croak("Invalid default; expected a non-reference, CODE ref, or SCALAR ref");
Branch: 1 branch
BranchTrueFalseTotal
not $ref or $ref =~ /^(CODE|SCALAR)$/ or croak("Invalid default; expected a non-reference, CODE ref, or SCALAR ref") 5 0 5
Condition33%1/3
not $ref or $ref =~ /^(CODE|SCALAR)$/
l!l&&r!l&&!r
050
MC/DC0%0/2
not $ref or $ref =~ /^(CODE|SCALAR)$/
not $ref $ref =~ /^(CODE|SCALAR)$/
Truth table33%1/3
not(A) or B
A= not $refB= $ref =~ /^(CODE|SCALAR)$/
ABresult
1X1
011
000
313 }
314  
315 34 ▶sub canonicalize_isa : method
Subroutine canonicalize_isa: called CC=10 SCAR=38.3
Pod undocumented
316 {
317 34 my $me = shift;
318
319 34 ▶ if (my $does = $me->{does})
Branch: 1 branch
BranchTrueFalseTotal
if (my $does = $me->{"does"}) 0 34 34
320 {
321 0 ▶ $me->{isa} ||= sub { blessed($_[0]) && $_[0]->DOES($does) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) and $_[0]->DOES($does) 0 0 0
Condition0%0/3
$me->{"isa"} ||= sub { builtin::blessed($_[0]) and $_[0]->DOES($does); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$me->{"isa"} ||= sub { builtin::blessed($_[0]) and $_[0]->DOES($does); }
$me->{"isa"} sub { builtin::blessed($_[0]) and $_[0]->DOES($does); }
Truth table0%0/3
A ||= B
A= $me->{"isa"}B= sub { builtin::blessed($_[0]) and $_[0]->DOES($does); }
ABresult
1X1
011
000
322 }
323
324 34 ▶ if ( $me->{enum} )
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"enum"}) 0 34 34
325 {
326 0 require Types::Standard;
327 0 ▶ $me->{isa} = Types::Standard::Enum()->of( $me->{coerce} ? \1: (), @{$me->{enum}} );
Branch: 1 branch
BranchTrueFalseTotal
$me->{'coerce'} ? : 0 0 0
328 }
329
330 34 ▶ if (defined $me->{isa} and not ref $me->{isa})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $me->{"isa"} and not ref $me->{"isa"}) 0 34 34
Condition66%2/3
defined $me->{"isa"} and not ref $me->{"isa"}
!ll&&!rl&&r
2950
MC/DC0%0/2
defined $me->{"isa"} and not ref $me->{"isa"}
defined $me->{"isa"} not ref $me->{"isa"}
Truth table66%2/3
A and not(B)
A= defined $me->{"isa"}B= not ref $me->{"isa"}
ABresult
0X0
100
111
331 {
332 0 my $type_name = $me->{isa};
333 0 ▶ eval { require Type::Utils }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Type::Utils } } or croak("Missing requirement; type constraint strings require Type::Utils") 0 0 0
334 or croak("Missing requirement; type constraint strings require Type::Utils");
335
336 $me->{isa} = $me->{package}
337 ? Type::Utils::dwim_type($type_name, for => $me->{package})
338 0 ▶ : Type::Utils::dwim_type($type_name);
Branch: 1 branch
BranchTrueFalseTotal
$me->{'package'} ? : 0 0 0
339 }
340
341 34 ▶ if ( 'CODE' eq ref $me->{isa} )
Branch: 1 branch
BranchTrueFalseTotal
if ("CODE" eq ref $me->{"isa"}) 0 34 34
342 {
343 0 require Type::Tiny;
344 0 $me->{isa} = Type::Tiny->new( constraint => $me->{isa} );
345 }
346 }
347  
348 34 ▶sub canonicalize_trigger : method
Subroutine canonicalize_trigger: called CC=2 SCAR=6.9
Pod undocumented
349 {
350 34 my $me = shift;
351 34 ▶ if ( defined $me->{trigger} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $me->{"trigger"}) 6 28 34
352 # Create an additional slot to hold a mutex, preventing the trigger
353 # from triggering itself. This slot won't have any accessors, etc
354 # so the slot name doesn't need to consist of wordlike characters.
355 # Indeed, it's better to include a non-wordlike character to avoid
356 # collisions.
357 6 my $slot = sprintf( '%s:trigger_mutex', $me->{slot} );
358 6 $me->{trigger_mutex} = $me->_create_child( $slot );
359 }
360 }
361  
362 34 ▶sub canonicalize_chain : method
Subroutine canonicalize_chain: called CC=9 SCAR=30.1
Pod undocumented
363 {
364 34 my $me = shift;
365 34 my $okay = qr/^(accessor|writer|clearer)$/;
366
367 34 ▶ if ( exists $me->{chain} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $me->{"chain"}) 2 32 34
368 2 ▶ if ( 'ARRAY' eq ref $me->{chain} ) {
Branch: 4 branches
BranchTrueFalseTotal
if ('ARRAY' eq ref $me->{'chain'}) { } 0 2 2
elsif (ref $me->{'chain'}) { } 0 2 2
elsif ($me->{'chain'} =~ /$okay/) { } 0 2 2
elsif ($me->{'chain'} eq '0' or $me->{'chain'} eq '1' or $me->{'chain'} eq '') { } 2 0 2
369 0 ▶ croak("Unrecognized chain option") if grep { !/$okay/ } @{$me->{chain}};
Branch: 1 branch
BranchTrueFalseTotal
if grep {not /$okay/;} @{$$me{"chain"};} 0 0 0
370 }
371 elsif ( ref $me->{chain} ) {
372 0 croak("Unrecognized chain option");
373 }
374 elsif ( $me->{chain} =~ $okay ) {
375 0 $me->{chain} = [ $me->{chain} ]
376 }
377 ▶ elsif ( $me->{chain} eq '0' or $me->{chain} eq '1' or $me->{chain} eq '' ) {
Condition50%3/6
$me->{"chain"} eq 0 or $me->{"chain"} eq 1 or $me->{"chain"} eq ""
l!l&&r!l&&!r
200
$me->{"chain"} eq 0 or $me->{"chain"} eq 1
l!l&&r!l&&!r
110
MC/DC0%0/3
$me->{"chain"} eq 0 or $me->{"chain"} eq 1 or $me->{"chain"} eq ""
$me->{"chain"} eq 0 $me->{"chain"} eq 1 $me->{"chain"} eq ""
Truth table50%2/4
A or B or C
A= $me->{"chain"} eq 0B= $me->{"chain"} eq 1C= $me->{"chain"} eq ""
ABCresult
1XX1
01X1
0011
0000
378 2 $me->{chain} = !!$me->{chain};
379 }
380 else {
381 0 croak("Unrecognized chain option");
382 }
383 }
384 }
385  
386 34 ▶sub canonicalize_opts : method
Subroutine canonicalize_opts: called CC=4 SCAR=14.1
Pod undocumented
387 {
388 34 my $me = shift;
389
390 34 ▶ croak("Initializers are not supported") if $me->{initializer};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"initializer"} 0 34 34
391 34 ▶ croak("Traits are not supported") if $me->{traits};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"traits"} 0 34 34
392 34 ▶ croak("The lazy_build option is not supported") if $me->{lazy_build};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"lazy_build"} 0 34 34
393
394 34 $me->canonicalize_1;
395 34 $me->canonicalize_is;
396 34 $me->canonicalize_isa;
397 34 $me->canonicalize_default;
398 34 $me->canonicalize_builder;
399 34 $me->canonicalize_trigger;
400 34 $me->canonicalize_chain;
401 }
402  
403 0 ▶sub has_simple_accessor : method
Subroutine has_simple_accessor: not called CC=3 SCAR=24.8
Pod undocumented
404 {
405 0 my $me = shift;
406 0 ▶ return !!0 if !$me->has_simple_reader;
Branch: 1 branch
BranchTrueFalseTotal
unless $me->has_simple_reader 0 0 0
407 0 ▶ return !!0 if !$me->has_simple_writer;
Branch: 1 branch
BranchTrueFalseTotal
unless $me->has_simple_writer 0 0 0
408 0 return !!1;
409 }
410  
411 1 ▶sub has_simple_reader : method
Subroutine has_simple_reader: called CC=2 SCAR=7.1
Pod undocumented
412 {
413 1 my $me = shift;
414 1 ▶ return !!0 if $me->{lazy};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"lazy"} 0 1 1
415 1 return !!1;
416 }
417  
418 1 ▶sub has_simple_writer : method
Subroutine has_simple_writer: called CC=4 SCAR=18.9
Pod undocumented
419 {
420 1 my $me = shift;
421 1 ▶ return !!0 if exists $me->{trigger};
Branch: 1 branch
BranchTrueFalseTotal
if exists $me->{"trigger"} 0 1 1
422 1 ▶ return !!0 if exists $me->{isa};
Branch: 1 branch
BranchTrueFalseTotal
if exists $me->{"isa"} 1 0 1
423 0 ▶ return !!0 if $me->{weak_ref};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"weak_ref"} 0 0 0
424 0 return !!1;
425 }
426  
427 0 ▶sub has_simple_predicate : method
Subroutine has_simple_predicate: not called CC=1 SCAR=6.9
Pod undocumented
428 {
429 0 my $me = shift;
430 0 return !!1;
431 }
432  
433 0 ▶sub has_simple_clearer : method
Subroutine has_simple_clearer: not called CC=1 SCAR=6.9
Pod undocumented
434 {
435 0 my $me = shift;
436 0 return !!1;
437 }
438  
439 20 ▶sub has_chainable_writer : method
Subroutine has_chainable_writer: called CC=2 SCAR=8.4
Pod undocumented
440 {
441 20 my $me = shift;
442 0 ▶ return !!grep { $_ eq 'writer' } @{ $me->{chain} } if 'ARRAY' eq ref $me->{chain};
Branch: 1 branch
BranchTrueFalseTotal
if "ARRAY" eq ref $me->{"chain"} 0 20 20
443 20 return !!$me->{chain};
444 }
445  
446 32 ▶sub has_chainable_accessor : method
Subroutine has_chainable_accessor: called CC=2 SCAR=8.4
Pod undocumented
447 {
448 32 my $me = shift;
449 0 ▶ return !!grep { $_ eq 'accessor' } @{ $me->{chain} } if 'ARRAY' eq ref $me->{chain};
Branch: 1 branch
BranchTrueFalseTotal
if "ARRAY" eq ref $me->{"chain"} 0 32 32
450 32 return !!$me->{chain};
451 }
452  
453 16 ▶sub has_chainable_clearer : method
Subroutine has_chainable_clearer: called CC=2 SCAR=8.4
Pod undocumented
454 {
455 16 my $me = shift;
456 0 ▶ return !!grep { $_ eq 'clearer' } @{ $me->{chain} } if 'ARRAY' eq ref $me->{chain};
Branch: 1 branch
BranchTrueFalseTotal
if "ARRAY" eq ref $me->{"chain"} 0 16 16
457 16 return !!$me->{chain};
458 }
459  
460 10 ▶sub accessor_kind : method
Subroutine accessor_kind: called CC=1 SCAR=0.0
Pod undocumented
461 {
462 10 return 'small';
463 }
464  
465 52 ▶sub inline_to_coderef : method
Subroutine inline_to_coderef: called CC=2 SCAR=7.0
Pod undocumented
466 {
467 52 my $me = shift;
468 52 my ($method_type, $code) = @_;
469  
470 52 my $kind = $me->accessor_kind;
471 52 my $src = sprintf(q[sub { %s }], $code);
472 my $desc = defined($me->{slot})
473 ? sprintf('%s %s for %s', $kind, $method_type, $me->{slot})
474 52 ▶ : sprintf('%s %s', $kind, $method_type);
Branch: 1 branch
BranchTrueFalseTotal
defined $me->{'slot'} ? : 52 0 52
475 # warn "#### $desc\n$src\n";
476
477 Eval::TypeTiny::eval_closure(
478 source => $src,
479 environment => $me->{inline_environment},
480 52 description => $desc,
481 );
482 }
483  
484 6 ▶sub clearer : method
Subroutine clearer: called CC=1 SCAR=0.0
Pod undocumented
485 {
486 6 my $me = shift;
487
488 6 $me->inline_to_coderef(
489 clearer => $me->inline_clearer,
490 );
491 }
492  
493 16 ▶sub inline_clearer : method
Subroutine inline_clearer: called CC=3 SCAR=11.0
Pod undocumented
494 {
495 16 my $me = shift;
496 16 ▶ my $selfvar = shift || '$_[0]';
Condition100%2/2
shift() || '$_[0]'
l!l
106
MC/DC100%1/1
shift() || '$_[0]'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
497
498 16 ▶ my $maybe_chain = $me->has_chainable_clearer ? sub { $_[0] . "; $selfvar" } : sub { $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$me->has_chainable_clearer ? : 1 15 16
499
500 16 $maybe_chain->( sprintf(
501 q[ delete(%s) ],
502 $me->inline_access( $selfvar ),
503 ) );
504 }
505  
506 151 ▶sub inline_access : method
Subroutine inline_access: called CC=2 SCAR=7.1
Pod undocumented
507 {
508 151 my $me = shift;
509 151 ▶ my $selfvar = shift || '$_[0]';
Condition50%1/2
shift() || '$_[0]'
l!l
1510
MC/DC0%0/1
shift() || '$_[0]'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
510  
511 sprintf(
512 q[ $Sub::Accessor::Small::FIELDS{%s}{%d} ],
513 $selfvar,
514 $me->{id},
515 151 );
516 }
517  
518 42 ▶sub inline_access_w : method
Subroutine inline_access_w: called CC=3 SCAR=11.4
Pod undocumented
519 {
520 42 my $me = shift;
521 42 ▶ my $selfvar = shift || '$_[0]';
Condition50%1/2
shift() || '$_[0]'
l!l
420
MC/DC0%0/1
shift() || '$_[0]'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
522 42 ▶ my $expr = shift || die;
Condition50%1/2
shift() || die()
l!l
420
MC/DC0%0/1
shift() || die()
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
523
524 42 sprintf(
525 q[ %s = %s ],
526 $me->inline_access( $selfvar ),
527 $expr,
528 );
529 }
530  
531 4 ▶sub predicate : method
Subroutine predicate: called CC=1 SCAR=0.0
Pod undocumented
532 {
533 4 my $me = shift;
534
535 4 $me->inline_to_coderef(
536 predicate => $me->inline_predicate,
537 );
538 }
539  
540 21 ▶sub inline_predicate : method
Subroutine inline_predicate: called CC=2 SCAR=6.9
Pod undocumented
541 {
542 21 my $me = shift;
543 21 ▶ my $selfvar = shift || '$_[0]';
Condition100%2/2
shift() || '$_[0]'
l!l
174
MC/DC100%1/1
shift() || '$_[0]'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
544
545 21 sprintf(
546 q[ exists(%s) ],
547 $me->inline_access( $selfvar ),
548 );
549 }
550  
551 0 ▶sub handles : method
Subroutine handles: not called CC=1 SCAR=6.9
Pod undocumented
552 {
553 0 my $me = shift;
554 0 my ($method) = @_;
555
556 0 $me->inline_to_coderef(
557 'delegated method' => $me->inline_handles,
558 );
559 }
560  
561 10 my $handler_uniq = 0;
562 0 ▶sub inline_handles : method
Subroutine inline_handles: not called CC=4 SCAR=30.0
Pod undocumented
563 {
564 0 my $me = shift;
565 0 ▶ my $selfvar = shift || '$_[0]';
Condition0%0/2
shift() || '$_[0]'
l!l
00
MC/DC0%0/1
shift() || '$_[0]'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
566 0 ▶ my $method = shift || die;
Condition0%0/2
shift() || die()
l!l
00
MC/DC0%0/1
shift() || die()
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
567
568 0 my $get = $me->inline_access( $selfvar );
569
570 0 my $varname = $me->make_var_name( sprintf 'handler_%d', ++$handler_uniq );
571 0 $me->{inline_environment}{$varname} = \($method);
572
573 0 my $death = 'Scalar::Util::blessed($h) or Carp::croak("Expected blessed object to delegate to; got $h")';
574
575 0 ▶ if (ref $method eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $method eq 'ARRAY') { } 0 0 0
576 {
577 0 return sprintf(
578 q[ %s; my $h = %s; %s; shift; my ($m, @a) = @%s; $h->$m(@a, @_) ],
579 $me->inline_maybe_write_default( $selfvar ),
580 $get,
581 $death,
582 $varname,
583 );
584 }
585 else
586 {
587 0 return sprintf(
588 q[ %s; my $h = %s; %s; shift; $h->%s(@_) ],
589 $me->inline_maybe_write_default( $selfvar ),
590 $get,
591 $death,
592 $varname,
593 );
594 }
595 }
596  
597 39 ▶sub inline_get : method
Subroutine inline_get: called CC=3 SCAR=11.8
Pod undocumented
598 {
599 39 my $me = shift;
600 39 ▶ my $selfvar = shift || '$_[0]';
Condition50%1/2
shift() || '$_[0]'
l!l
390
MC/DC0%0/1
shift() || '$_[0]'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
601
602 39 my $get = $me->inline_access( $selfvar );
603
604 39 ▶ if ($me->{auto_deref})
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"auto_deref"}) 0 39 39
605 {
606 0 $get = sprintf(
607 q[ do { my $x = %s; wantarray ? (ref($x) eq 'ARRAY' ? @$x : ref($x) eq 'HASH' ? %$x : $x ) : $x } ],
608 $get,
609 );
610 }
611
612 39 return $get;
613 }
614  
615 0 ▶sub inline_maybe_write_default : method
Subroutine inline_maybe_write_default: not called CC=3 SCAR=24.8
Pod undocumented
616 {
617 0 my $me = shift;
618 0 ▶ my $selfvar = shift || '$_[0]';
Condition0%0/2
shift() || '$_[0]'
l!l
00
MC/DC0%0/1
shift() || '$_[0]'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
619
620 0 ▶ if ($me->{lazy})
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"lazy"}) 0 0 0
621 {
622 0 return sprintf(
623 q[ %s unless %s; ],
624 $me->inline_access_w( $selfvar, $me->inline_default( $selfvar ) ),
625 $me->inline_predicate( $selfvar ),
626 );
627 }
628
629 0 return '';
630 }
631  
632 sub _is_bool ($)
633 0 ▶{
Subroutine _is_bool: not called CC=10 SCAR=47.0
634 0 my $value = shift;
635 0 ▶ return !!0 unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
636 0 ▶ return !!0 if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 0 0
637 0 ▶ return !!0 unless Scalar::Util::isdual( $value );
Branch: 1 branch
BranchTrueFalseTotal
unless &Scalar::Util::isdual($value) 0 0 0
638 0 ▶ return !!1 if $value && "$value" eq '1' && $value+0 == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $value and "$value" eq 1 and $value + 0 == 1 0 0 0
Condition0%0/6
$value and "$value" eq 1 and $value + 0 == 1
!ll&&!rl&&r
000
$value and "$value" eq 1
!ll&&!rl&&r
000
MC/DC0%0/3
$value and "$value" eq 1 and $value + 0 == 1
$value "$value" eq 1 $value + 0 == 1
Truth table0%0/4
A and B and C
A= $valueB= "$value" eq 1C= $value + 0 == 1
ABCresult
0XX0
10X0
1100
1111
639 0 ▶ return !!1 if !$value && "$value" eq q'' && $value+0 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $value and "$value" eq "" and $value + 0 == 0 0 0 0
Condition0%0/6
not $value and "$value" eq "" and $value + 0 == 0
!ll&&!rl&&r
000
not $value and "$value" eq ""
!ll&&!rl&&r
000
MC/DC0%0/3
not $value and "$value" eq "" and $value + 0 == 0
not $value "$value" eq "" $value + 0 == 0
Truth table0%0/4
not(A) and B and C
A= not $valueB= "$value" eq ""C= $value + 0 == 0
ABCresult
0XX0
10X0
1100
1111
640 0 return !!0;
641 }
642  
643 sub _created_as_number ($)
644 0 ▶{
Subroutine _created_as_number: not called CC=6 SCAR=37.4
645 0 my $value = shift;
646 0 ▶ return !!0 if utf8::is_utf8($value);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($value) 0 0 0
647 0 ▶ return !!0 unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
648 0 ▶ return !!0 if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 0 0
649 0 require B;
650 0 my $b_obj = B::svref_2object(\$value);
651 0 my $flags = $b_obj->FLAGS;
652 0 ▶ return !!1 if $flags & ( B::SVp_IOK() | B::SVp_NOK() ) and !( $flags & B::SVp_POK() );
Branch: 1 branch
BranchTrueFalseTotal
if $flags & 12288 and not $flags & 16384 0 0 0
Condition0%0/3
$flags & 12288 and not $flags & 16384
!ll&&!rl&&r
000
MC/DC0%0/2
$flags & 12288 and not $flags & 16384
$flags & 12288 not $flags & 16384
Truth table0%0/3
A and not(B)
A= $flags & 12288B= not $flags & 16384
ABresult
0X0
100
111
653 0 return !!0;
654 }
655  
656 sub _created_as_string ($)
657 0 ▶{
Subroutine _created_as_string: not called CC=4 SCAR=30.0
658 0 my $value = shift;
659 0 ▶ defined($value)
Branch: 1 branch
BranchTrueFalseTotal
defined $value and not ref $value and not &_is_bool($value) and not &_created_as_number($value) 0 0 0
Condition0%0/6
defined $value and not ref $value and not &_is_bool($value)
!ll&&!rl&&r
000
defined $value and not ref $value
!ll&&!rl&&r
000
MC/DC0%0/3
defined $value and not ref $value and not &_is_bool($value)
defined $value not ref $value not &_is_bool($value)
Truth table0%0/4
A and not(B) and not(C)
A= defined $valueB= not ref $valueC= not &_is_bool($value)
ABCresult
0XX0
10X0
1100
1111
660 && !ref($value)
661 && !_is_bool($value)
662 && !_created_as_number($value);
663 }
664  
665 6 ▶sub inline_default : method
Subroutine inline_default: called CC=12 SCAR=41.2
Pod undocumented
666 {
667 6 my $me = shift;
668 6 ▶ my $selfvar = shift || '$_[0]';
Condition50%1/2
shift() || '$_[0]'
l!l
60
MC/DC0%0/1
shift() || '$_[0]'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
669 6 ▶ my $preferred_closeover_var = shift || $me->make_var_name('default');
Condition33%1/3
shift() || $me->make_var_name('default')
l!l&&r!l&&!r
060
MC/DC0%0/2
shift() || $me->make_var_name('default')
shift() $me->make_var_name('default')
Truth table33%1/3
A || B
A= shift()B= $me->make_var_name('default')
ABresult
1X1
011
000
670
671 6 ▶ if (exists $me->{default})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $me->{'default'}) { } 6 0 6
elsif (defined $me->{'builder'}) { } 0 0 0
672 {
673 6 my $ref = ref $me->{default};
674 6 ▶ if ( $ref eq 'CODE' )
Branch: 6 branches
BranchTrueFalseTotal
if ($ref eq 'CODE') { } 6 0 6
elsif ($ref eq 'SCALAR') { } 0 0 0
elsif (not defined $me->{'default'}) { } 0 0 0
elsif (&_is_bool($me->{'default'})) { } 0 0 0
elsif (&_created_as_number($me->{'default'})) { } 0 0 0
elsif (&_created_as_string($me->{'default'})) { } 0 0 0
675 {
676 6 $me->{inline_environment}{$preferred_closeover_var} = \($me->{default});
677 6 return qq[$preferred_closeover_var\->($selfvar)];
678 }
679 elsif ( $ref eq 'SCALAR' )
680 {
681 0 return ${$me->{default}};
682 }
683 elsif ( !defined $me->{default} )
684 {
685 0 return 'undef';
686 }
687 elsif ( _is_bool $me->{default} )
688 {
689 0 ▶ return $me->{default} ? '!!1' : '!!0';
Branch: 1 branch
BranchTrueFalseTotal
$me->{'default'} ? : 0 0 0
690 }
691 elsif ( _created_as_number $me->{default} )
692 {
693 0 return $me->{default} + 0;
694 }
695 elsif ( _created_as_string $me->{default} )
696 {
697 0 require B;
698 0 return B::perlstring( $me->{default} );
699 }
700 }
701 elsif (defined $me->{builder})
702 {
703 0 return $selfvar . '->' . $me->{builder};
704 }
705
706 0 return undef;
707 }
708  
709 16 ▶sub reader : method
Subroutine reader: called CC=1 SCAR=0.0
Pod undocumented
710 {
711 16 my $me = shift;
712
713 16 $me->inline_to_coderef(
714 reader => $me->inline_reader,
715 );
716 }
717  
718 30 ▶sub inline_reader : method
Subroutine inline_reader: called CC=4 SCAR=13.9
Pod undocumented
719 {
720 30 my $me = shift;
721 30 ▶ my $selfvar = shift || '$_[0]';
Condition100%2/2
shift() || '$_[0]'
l!l
1416
MC/DC100%1/1
shift() || '$_[0]'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
722
723 30 ▶ if ( $me->{lazy} )
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"lazy"}) 6 24 30
724 {
725 6 my $flag;
726 6 delete local $me->{trigger};
727 6 my $w = $me->inline_writer( $selfvar, $me->inline_default( $selfvar ), \$flag );
728
729 6 ▶ if ( $flag )
Branch: 1 branch
BranchTrueFalseTotal
if ($flag) { } 0 6 6
730 {
731 0 return sprintf(
732 '( (%s) ? (%s) : (%s) )',
733 $me->inline_predicate( $selfvar ),
734 $me->inline_get( $selfvar ),
735 $w,
736 );
737 }
738 else
739 {
740 6 return sprintf(
741 '( (%s) ? (%s) : do { %s } )',
742 $me->inline_predicate( $selfvar ),
743 $me->inline_get( $selfvar ),
744 $w,
745 );
746 }
747 }
748
749 24 return $me->inline_get( $selfvar );
750 }
751  
752 10 ▶sub writer : method
Subroutine writer: called CC=1 SCAR=0.0
Pod undocumented
753 {
754 10 my $me = shift;
755
756 10 $me->inline_to_coderef(
757 writer => $me->inline_writer,
758 );
759 }
760  
761 16 ▶sub inline_writer : method
Subroutine inline_writer: called CC=19 SCAR=34.4
Pod undocumented
762 {
763 16 my $me = shift;
764 16 ▶ my $selfvar = shift || '$_[0]';
Condition100%2/2
shift() || '$_[0]'
l!l
610
MC/DC100%1/1
shift() || '$_[0]'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
765 16 ▶ my $expr = shift || '$_[1]';
Condition100%2/2
shift() || '$_[1]'
l!l
610
MC/DC100%1/1
shift() || '$_[1]'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
766 16 ▶ my $flag = shift || undef;
Condition100%2/2
shift() || undef
l!l
610
MC/DC100%1/1
shift() || undef
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
767
768 16 my $get = $me->inline_access( $selfvar );
769 16 my $coerce = $me->inline_type_coercion( $selfvar, $expr );
770
771 16 ▶ my $maybe_chain = $me->has_chainable_writer ? sub { $_[0] . "; $selfvar" } : sub { $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$me->has_chainable_writer ? : 1 15 16
772
773 # no coercion and simple variable
774 16 ▶ if ($coerce eq $expr and $expr =~ /^\$\w+(?:[-][>])?(?:\[\d+\]|\{[^}]\})*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($coerce eq $expr and $expr =~ /^\$\w+(?:[-][>])?(?:\[\d+\]|\{[^}]\})*$/) 6 10 16
Condition100%3/3
$coerce eq $expr and $expr =~ /^\$\w+(?:[-][>])?(?:\[\d+\]|\{[^}]\})*$/
!ll&&!rl&&r
466
MC/DC100%2/2
$coerce eq $expr and $expr =~ /^\$\w+(?:[-][>])?(?:\[\d+\]|\{[^}]\})*$/
$coerce eq $expr $expr =~ /^\$\w+(?:[-][>])?(?:\[\d+\]|\{[^}]\})*$/
Truth table100%3/3
A and B
A= $coerce eq $exprB= $expr =~ /^\$\w+(?:[-][>])?(?:\[\d+\]|\{[^}]\})*$/
ABresult
0X0
100
111
775 {
776 6 ▶ if (!$me->{trigger} and !$me->{weak_ref})
Branch: 2 branches
BranchTrueFalseTotal
if (not $me->{'trigger'} || $me->{'weak_ref'}) { } 6 0 6
elsif (not $me->{'weak_ref'}) { } 0 0 0
Condition33%1/3
$me->{'trigger'} || $me->{'weak_ref'}
l!l&&r!l&&!r
006
MC/DC0%0/2
$me->{'trigger'} || $me->{'weak_ref'}
$me->{'trigger'} $me->{'weak_ref'}
Truth table33%1/3
A || B
A= $me->{'trigger'}B= $me->{'weak_ref'}
ABresult
1X1
011
000
777 {
778 6 ▶ $$flag = 1 if $flag;
Branch: 1 branch
BranchTrueFalseTotal
if $flag 0 6 6
779 6 return $maybe_chain->( $me->inline_access_w(
780 $selfvar,
781 $me->inline_type_assertion( $selfvar, $expr ),
782 ) );
783 }
784 elsif ( !$me->{weak_ref} )
785 {
786 0 ▶ return sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$me->has_chainable_writer ? : 0 0 0
787 '%s; my @old = (%s) ? (%s) : (); %s; %s; %s',
788 $me->inline_type_assertion( $selfvar, $expr ),
789 $me->inline_predicate( $selfvar ),
790 $me->inline_access( $selfvar ),
791 $me->inline_access_w( $selfvar, $expr ),
792 $me->inline_trigger( $selfvar, undef, '@old' ),
793 $me->has_chainable_writer ? $selfvar : $me->inline_get( $selfvar ),
794 );
795 }
796 else
797 {
798 0 ▶ return sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$me->has_chainable_writer ? : 0 0 0
799 '%s; my @old = (%s) ? (%s) : (); %s; %s; %s; %s',
800 $me->inline_type_assertion( $selfvar, $expr ),
801 $me->inline_predicate( $selfvar ),
802 $me->inline_access( $selfvar ),
803 $me->inline_access_w( $selfvar, $expr ),
804 $me->inline_trigger( $selfvar, undef, '@old' ),
805 $me->inline_weaken( $selfvar ),
806 $me->has_chainable_writer ? $selfvar : $me->inline_get( $selfvar ),
807 );
808 }
809 }
810
811
812 # Use intermediate variable to store result of coercion and/or default
813 10 ▶ if ( !$me->{trigger} and !$me->{weak_ref} )
Branch: 2 branches
BranchTrueFalseTotal
if (not $me->{'trigger'} || $me->{'weak_ref'}) { } 6 4 10
elsif (not $me->{'weak_ref'}) { } 4 0 4
Condition66%2/3
$me->{'trigger'} || $me->{'weak_ref'}
l!l&&r!l&&!r
406
MC/DC50%1/2
$me->{'trigger'} || $me->{'weak_ref'}
$me->{'trigger'} $me->{'weak_ref'}
Truth table66%2/3
A || B
A= $me->{'trigger'}B= $me->{'weak_ref'}
ABresult
1X1
011
000
814 {
815 6 my $ass = $me->inline_type_assertion( $selfvar, '$val' );
816 6 ▶ return $maybe_chain->( sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$ass =~ /^do/ ? : 0 6 6
817 'my $val = %s; %s',
818 $coerce,
819 $me->inline_access_w( $selfvar, $ass =~ /^do/ ? $ass : "do { $ass }" ),
820 ) );
821 }
822 elsif ( !$me->{weak_ref} )
823 {
824 4 ▶ return sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$me->has_chainable_writer ? : 0 4 4
825 'my $val = %s; %s; my @old = (%s) ? (%s) : (); %s; %s; %s',
826 $coerce,
827 $me->inline_type_assertion( $selfvar, '$val' ),
828 $me->inline_predicate( $selfvar ),
829 $me->inline_access( $selfvar ),
830 $me->inline_access_w( $selfvar, '$val' ),
831 $me->inline_trigger( $selfvar, undef, '@old' ),
832 $me->has_chainable_writer ? $selfvar : $me->inline_access( $selfvar ),
833 );
834 }
835 else
836 {
837 0 ▶ return sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$me->has_chainable_writer ? : 0 0 0
838 'my $val = %s; %s; my @old = (%s) ? (%s) : (); %s; %s; %s; %s',
839 $coerce,
840 $me->inline_type_assertion( $selfvar, '$val' ),
841 $me->inline_predicate( $selfvar ),
842 $me->inline_access( $selfvar ),
843 $me->inline_access_w( $selfvar, '$val' ),
844 $me->inline_trigger( $selfvar, undef, '@old' ),
845 $me->inline_weaken( $selfvar ),
846 $me->has_chainable_writer ? $selfvar : $me->inline_access( $selfvar ),
847 );
848 }
849 }
850  
851 16 ▶sub accessor : method
Subroutine accessor: called CC=1 SCAR=0.0
Pod undocumented
852 {
853 16 my $me = shift;
854
855 16 $me->inline_to_coderef(
856 accessor => $me->inline_accessor,
857 );
858 }
859  
860 16 ▶sub inline_accessor : method
Subroutine inline_accessor: called CC=15 SCAR=30.4
Pod undocumented
861 {
862 16 my $me = shift;
863 16 ▶ my $selfvar = shift || '$_[0]';
Condition50%1/2
shift() || '$_[0]'
l!l
016
MC/DC0%0/1
shift() || '$_[0]'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
864 16 ▶ my $expr = shift || '$_[1]';
Condition50%1/2
shift() || '$_[1]'
l!l
016
MC/DC0%0/1
shift() || '$_[1]'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
865 16 ▶ my $toggle = shift || '@_ > 1';
Condition50%1/2
shift() || '@_ > 1'
l!l
016
MC/DC0%0/1
shift() || '@_ > 1'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
866  
867 16 my $get = $me->inline_access( $selfvar );
868 16 my $coerce = $me->inline_type_coercion( $selfvar, $expr );
869
870 0 ▶ my $maybe_chain = $me->has_chainable_accessor ? sub { $_[0] . "; $selfvar" } : sub { $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=0.6
Subroutine __ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
BranchTrueFalseTotal
$me->has_chainable_accessor ? : 1 15 16
871
872 16 ▶ if ($coerce eq $expr) # i.e. no coercion
Branch: 1 branch
BranchTrueFalseTotal
if ($coerce eq $expr) 12 4 16
873 {
874 12 ▶ if (!$me->{lazy} and !$me->{trigger} and !$me->{weak_ref})
Branch: 1 branch
BranchTrueFalseTotal
unless ($me->{"lazy"} or $me->{"trigger"} or $me->{"weak_ref"}) 9 3 12
Condition83%5/6
$me->{"lazy"} or $me->{"trigger"} or $me->{"weak_ref"}
l!l&&r!l&&!r
309
$me->{"lazy"} or $me->{"trigger"}
l!l&&r!l&&!r
129
MC/DC66%2/3
$me->{"lazy"} or $me->{"trigger"} or $me->{"weak_ref"}
$me->{"lazy"} $me->{"trigger"} $me->{"weak_ref"}
Truth table75%3/4
A or B or C
A= $me->{"lazy"}B= $me->{"trigger"}C= $me->{"weak_ref"}
ABCresult
1XX1
01X1
0011
0000
875 {
876 9 ▶ return sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$me->has_chainable_accessor ? : 1 8 9
877 '(%s) ? (%s) : %s',
878 $toggle,
879 $me->has_chainable_accessor
880 ? sprintf(
881 'do { %s; %s }',
882 $me->inline_access_w( $selfvar, $me->inline_type_assertion( $selfvar, $expr ) ),
883 $selfvar,
884 )
885 : $me->inline_access_w( $selfvar, $me->inline_type_assertion( $selfvar, $expr ) ),
886 $me->inline_get( $selfvar ),
887 );
888 }
889
890 3 ▶ return sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$me->has_chainable_accessor ? : 0 3 3
891 'if (%s) { %s; my @old = (%s) ? (%s) : (); %s; %s; %s; %s } else { %s }',
892 $toggle,
893 $me->inline_type_assertion( $selfvar, $expr ),
894 $me->inline_predicate( $selfvar ),
895 $me->inline_access( $selfvar ),
896 $me->inline_access_w( $selfvar, $expr ),
897 $me->inline_trigger( $selfvar, undef, '@old' ),
898 $me->inline_weaken( $selfvar ),
899 $me->has_chainable_accessor ? $selfvar : $me->inline_reader( $selfvar ),
900 $me->inline_reader( $selfvar ),
901 );
902 }
903
904 4 ▶ if ( !$me->{trigger} and !$me->{weak_ref} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($me->{"trigger"} or $me->{"weak_ref"}) 0 4 4
Condition33%1/3
$me->{"trigger"} or $me->{"weak_ref"}
l!l&&r!l&&!r
400
MC/DC0%0/2
$me->{"trigger"} or $me->{"weak_ref"}
$me->{"trigger"} $me->{"weak_ref"}
Truth table33%1/3
A or B
A= $me->{"trigger"}B= $me->{"weak_ref"}
ABresult
1X1
011
000
905 0 ▶ return sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$me->has_chainable_accessor ? : 0 0 0
906 'if (%s) { my $val = %s; %s; %s; %s } else { %s }',
907 $toggle,
908 $coerce,
909 $me->inline_type_assertion( $selfvar, '$val' ),
910 $me->inline_access_w( $selfvar, '$val' ),
911 $me->has_chainable_accessor ? $selfvar : $me->inline_reader( $selfvar ),
912 $me->inline_reader( $selfvar ),
913 );
914 }
915
916 4 ▶ return sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$me->has_chainable_accessor ? : 0 4 4
917 'if (%s) { my $val = %s; %s; my @old = (%s) ? (%s) : (); %s; %s; %s; %s } else { %s }',
918 $toggle,
919 $coerce,
920 $me->inline_type_assertion( $selfvar, '$val' ),
921 $me->inline_predicate( $selfvar ),
922 $me->inline_access( $selfvar ),
923 $me->inline_access_w( $selfvar, '$val' ),
924 $me->inline_trigger( $selfvar, undef, '@old' ),
925 $me->inline_weaken( $selfvar ),
926 $me->has_chainable_accessor ? $selfvar : $me->inline_reader( $selfvar ),
927 $me->inline_reader( $selfvar ),
928 );
929 }
930  
931 32 ▶sub inline_type_coercion : method
Subroutine inline_type_coercion: called CC=16 SCAR=42.5
Pod undocumented
932 {
933 32 my $me = shift;
934 32 ▶ my $selfvar = shift || '$_[0]'; # usually ignored
Condition50%1/2
shift() || '$_[0]'
l!l
320
MC/DC0%0/1
shift() || '$_[0]'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
935 32 ▶ my $var = shift || die;
Condition50%1/2
shift() || die()
l!l
320
MC/DC0%0/1
shift() || die()
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
936
937 32 ▶ my $coercion = $me->{coerce} or return $var;
Branch: 1 branch
BranchTrueFalseTotal
my $coercion = $me->{"coerce"} or return $var 8 24 32
938
939 8 ▶ unless (ref $coercion)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $coercion) 8 0 8
940 {
941 8 my $type = $me->{isa};
942
943 8 ▶ if (blessed($type) and $type->can('coercion'))
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($type) and $type->can('coercion')) { } 8 0 8
elsif (builtin::blessed($type) and $type->can('coerce')) { } 0 0 0
Condition33%1/3
builtin::blessed($type) and $type->can("coercion")
!ll&&!rl&&r
008
MC/DC0%0/2
builtin::blessed($type) and $type->can("coercion")
builtin::blessed($type) $type->can("coercion")
Truth table33%1/3
A and B
A= builtin::blessed($type)B= $type->can("coercion")
ABresult
0X0
100
111
944 {
945 8 $coercion = $type->coercion;
946 }
947 ▶ elsif (blessed($type) and $type->can('coerce'))
Condition0%0/3
builtin::blessed($type) and $type->can("coerce")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($type) and $type->can("coerce")
builtin::blessed($type) $type->can("coerce")
Truth table0%0/3
A and B
A= builtin::blessed($type)B= $type->can("coerce")
ABresult
0X0
100
111
948 {
949 0 ▶ $coercion = sub { $type->coerce(@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
950 }
951 else
952 {
953 0 croak("Invalid coerce; type constraint cannot be probed for coercion");
954 }
955
956 8 ▶ unless (ref $coercion)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $coercion) 0 8 8
957 {
958 0 carp("Invalid coerce; type constraint has no coercion");
959 0 return $var;
960 }
961 }
962
963 8 ▶ if ( blessed($coercion)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($coercion) and $coercion->can("can_be_inlined") and $coercion->can_be_inlined and $coercion->can("inline_coercion")) 8 0 8
Condition33%3/9
builtin::blessed($coercion) and $coercion->can("can_be_inlined") and $coercion->can_be_inlined and $coercion->can("inline_coercion")
!ll&&!rl&&r
008
builtin::blessed($coercion) and $coercion->can("can_be_inlined") and $coercion->can_be_inlined
!ll&&!rl&&r
008
builtin::blessed($coercion) and $coercion->can("can_be_inlined")
!ll&&!rl&&r
008
MC/DC0%0/4
builtin::blessed($coercion) and $coercion->can("can_be_inlined") and $coercion->can_be_inlined and $coercion->can("inline_coercion")
builtin::blessed($coercion) $coercion->can("can_be_inlined") $coercion->can_be_inlined $coercion->can("inline_coercion")
Truth table20%1/5
A and B and C and D
A= builtin::blessed($coercion)B= $coercion->can("can_be_inlined")C= $coercion->can_be_inlinedD= $coercion->can("inline_coercion")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
964 and $coercion->can('can_be_inlined')
965 and $coercion->can_be_inlined
966 and $coercion->can('inline_coercion') )
967 {
968 8 return $coercion->inline_coercion($var);
969 }
970
971 # Otherwise need to close over $coerce
972 0 my $coercion_varname = $me->make_var_name('coercion');
973 0 $me->{inline_environment}{$coercion_varname} = \$coercion;
974
975 0 ▶ if ( blessed($coercion)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($coercion) and $coercion->can("coerce")) 0 0 0
Condition0%0/3
builtin::blessed($coercion) and $coercion->can("coerce")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($coercion) and $coercion->can("coerce")
builtin::blessed($coercion) $coercion->can("coerce")
Truth table0%0/3
A and B
A= builtin::blessed($coercion)B= $coercion->can("coerce")
ABresult
0X0
100
111
976 and $coercion->can('coerce') )
977 {
978 0 return sprintf('%s->coerce(%s)', $coercion_varname, $var);
979 }
980
981 0 return sprintf('%s->(%s)', $coercion_varname, $var);
982 }
983  
984 32 ▶sub inline_type_assertion : method
Subroutine inline_type_assertion: called CC=16 SCAR=46.8
Pod undocumented
985 {
986 32 my $me = shift;
987 32 ▶ my $selfvar = shift || '$_[0]'; # usually ignored
Condition50%1/2
shift() || '$_[0]'
l!l
320
MC/DC0%0/1
shift() || '$_[0]'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
988 32 ▶ my $var = shift || die;
Condition50%1/2
shift() || die()
l!l
320
MC/DC0%0/1
shift() || die()
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
989
990 32 ▶ my $type = $me->{isa} or return $var;
Branch: 1 branch
BranchTrueFalseTotal
my $type = $me->{"isa"} or return $var 9 23 32
991
992 9 ▶ if ( blessed($type)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type) and $type->isa("Type::Tiny") and $type->can_be_inlined) 9 0 9
Condition33%2/6
builtin::blessed($type) and $type->isa("Type::Tiny") and $type->can_be_inlined
!ll&&!rl&&r
009
builtin::blessed($type) and $type->isa("Type::Tiny")
!ll&&!rl&&r
009
MC/DC0%0/3
builtin::blessed($type) and $type->isa("Type::Tiny") and $type->can_be_inlined
builtin::blessed($type) $type->isa("Type::Tiny") $type->can_be_inlined
Truth table25%1/4
A and B and C
A= builtin::blessed($type)B= $type->isa("Type::Tiny")C= $type->can_be_inlined
ABCresult
0XX0
10X0
1100
1111
993 and $type->isa('Type::Tiny')
994 and $type->can_be_inlined )
995 {
996 9 my $ass = $type->inline_assert($var);
997 9 ▶ if ($ass =~ /\Ado \{(.+)\};\z/sm)
Branch: 1 branch
BranchTrueFalseTotal
if ($ass =~ /\Ado \{(.+)\};\z/ms) 9 0 9
998 {
999 9 return "do { $1 }"; # i.e. drop trailing ";"
1000 }
1001 # otherwise protect expression from trailing ";"
1002 0 return "do { $ass }"
1003 }
1004
1005 # Otherwise need to close over $type
1006 0 my $type_varname = $me->make_var_name('type');
1007 0 $me->{inline_environment}{$type_varname} = \$type;
1008
1009 # non-Type::Tiny but still supports inlining
1010 0 ▶ if ( blessed($type)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type) and $type->can("can_be_inlined") and $type->can_be_inlined) 0 0 0
Condition0%0/6
builtin::blessed($type) and $type->can("can_be_inlined") and $type->can_be_inlined
!ll&&!rl&&r
000
builtin::blessed($type) and $type->can("can_be_inlined")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($type) and $type->can("can_be_inlined") and $type->can_be_inlined
builtin::blessed($type) $type->can("can_be_inlined") $type->can_be_inlined
Truth table0%0/4
A and B and C
A= builtin::blessed($type)B= $type->can("can_be_inlined")C= $type->can_be_inlined
ABCresult
0XX0
10X0
1100
1111
1011 and $type->can('can_be_inlined')
1012 and $type->can_be_inlined )
1013 {
1014 0 ▶ my $inliner = $type->can('inline_check') || $type->can('_inline_check');
Condition0%0/3
$type->can('inline_check') || $type->can('_inline_check')
l!l&&r!l&&!r
000
MC/DC0%0/2
$type->can('inline_check') || $type->can('_inline_check')
$type->can('inline_check') $type->can('_inline_check')
Truth table0%0/3
A || B
A= $type->can('inline_check')B= $type->can('_inline_check')
ABresult
1X1
011
000
1015 0 ▶ if ($inliner)
Branch: 1 branch
BranchTrueFalseTotal
if ($inliner) 0 0 0
1016 {
1017 0 return sprintf('do { %s } ? %s : Carp::croak(%s->get_message(%s))', $type->$inliner($var), $var, $type_varname, $var);
1018 }
1019 }
1020
1021 0 ▶ if ( blessed($type)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type) and $type->can("check") and $type->can("get_message")) 0 0 0
Condition0%0/6
builtin::blessed($type) and $type->can("check") and $type->can("get_message")
!ll&&!rl&&r
000
builtin::blessed($type) and $type->can("check")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($type) and $type->can("check") and $type->can("get_message")
builtin::blessed($type) $type->can("check") $type->can("get_message")
Truth table0%0/4
A and B and C
A= builtin::blessed($type)B= $type->can("check")C= $type->can("get_message")
ABCresult
0XX0
10X0
1100
1111
1022 and $type->can('check')
1023 and $type->can('get_message') )
1024 {
1025 0 return sprintf('%s->check(%s) ? %s : Carp::croak(%s->get_message(%s))', $type_varname, $var, $var, $type_varname, $var);
1026 }
1027
1028 0 return sprintf('%s->(%s) ? %s : Carp::croak("Value %s failed type constraint check")', $type_varname, $var, $var, $var);
1029 }
1030  
1031 7 ▶sub inline_weaken : method
Subroutine inline_weaken: called CC=3 SCAR=12.5
Pod undocumented
1032 {
1033 7 my $me = shift;
1034 7 ▶ my $selfvar = shift || '$_[0]';
Condition50%1/2
shift() || '$_[0]'
l!l
70
MC/DC0%0/1
shift() || '$_[0]'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1035
1036 7 ▶ return '' unless $me->{weak_ref};
Branch: 1 branch
BranchTrueFalseTotal
unless $me->{"weak_ref"} 7 0 7
1037
1038 0 sprintf(
1039 q[ Scalar::Util::weaken(%s) if ref(%s) ],
1040 $me->inline_access( $selfvar ),
1041 $me->inline_access( $selfvar ),
1042 );
1043 }
1044  
1045 11 ▶sub inline_trigger : method
Subroutine inline_trigger: called CC=6 SCAR=18.2
Pod undocumented
1046 {
1047 11 my $me = shift;
1048 11 ▶ my $selfvar = shift || '$_[0]';
Condition50%1/2
shift() || '$_[0]'
l!l
110
MC/DC0%0/1
shift() || '$_[0]'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1049 11 ▶ my $new = shift || $me->inline_access( $selfvar );
Condition33%1/3
shift() || $me->inline_access($selfvar)
l!l&&r!l&&!r
0110
MC/DC0%0/2
shift() || $me->inline_access($selfvar)
shift() $me->inline_access($selfvar)
Truth table33%1/3
A || B
A= shift()B= $me->inline_access($selfvar)
ABresult
1X1
011
000
1050 11 ▶ my $old = shift || '';
Condition50%1/2
shift() || ''
l!l
110
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1051
1052 11 ▶ my $trigger = $me->{trigger} or return '';
Branch: 1 branch
BranchTrueFalseTotal
my $trigger = $me->{"trigger"} or return "" 10 1 11
1053 10 my $run_trigger_code;
1054
1055 10 ▶ if ( ref($trigger) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $trigger) { } 9 1 10
1056 9 my $trigger_varname = $me->make_var_name('trigger');
1057 9 $me->{inline_environment}{$trigger_varname} = \$trigger;
1058 9 $run_trigger_code = sprintf('%s->(%s, %s, %s)', $trigger_varname, $selfvar, $new, $old);
1059 }
1060 else {
1061 1 $run_trigger_code = sprintf('%s->%s(%s, %s)', $selfvar, $trigger, $new, $old);
1062 }
1063
1064 # Need to assign invocant to a temp lexical variable in case it's still
1065 # (probably is!) $_[0] because the guard will not be able to close over
1066 # $_[0].
1067 10 my $mutex = $me->{trigger_mutex};
1068 10 return sprintf(
1069 '%s || do { my $tmp = %s; my $g = %s->new(sub { %s }); %s; %s }',
1070 $mutex->inline_access($selfvar),
1071 $selfvar,
1072 $mutex->_guard_class,
1073 $mutex->inline_clearer('$tmp'), # $mutex hasn't inherited `chain` option
1074 $mutex->inline_access_w($selfvar, '!!1'),
1075 $run_trigger_code,
1076 );
1077 }
1078  
1079 10 ▶sub _guard_class : method
Subroutine _guard_class: called CC=1 SCAR=0.0
1080 {
1081 10 return __PACKAGE__ . "::_Guard";
1082 }
1083  
1084 {
1085 package #hide
1086 Sub::Accessor::Small::_Guard;
1087 12 ▶ sub new { bless( [ $_[1], $_[2] ], $_[0] ) }
Subroutine new: called CC=1 SCAR=0.0
1088 0 ▶ sub defang { $_[0][1] = ( @_==2 ? $_[1] : 1 ) }
Subroutine defang: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
1089 12 ▶ sub DESTROY { $_[0][0]->() unless $_[0][1] }
Subroutine DESTROY: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0][1] 12 0 12
1090 }
1091  
1092 10 1;
1093  
1094 __END__
↑ Summary Lexical/Accessor.pm »