blib/lib/Object/Proto/Sugar.pm

filter: Statementstmt 97.4% 347 / 356 Branchbran 88.2% 143 / 162 Conditioncond 83.8% 57 / 68 MC/DCmcdc 64.2% 27 / 42 Subroutinesub 98.4% 64 / 65 Podpod n/a totaltotal 92.0% 638 / 693 CC 117 SCAR 21.2
CC
117
Cov
93%
_configure_default_and_builder
17.3
_install_func_accessors
15.1
__ANON__
14.0
CRAP 8.3
↑ Summary
1 package Object::Proto::Sugar;
2  
3 23 ▶use 5.008003;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 23 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 23 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6 23 ▶use BEGIN::Lift;
Subroutine __ANON__: called CC=1 SCAR=0.0
7 23 ▶use Devel::Hook;
Subroutine __ANON__: called CC=1 SCAR=0.0
8 23 ▶use Object::Proto;
Subroutine __ANON__: called CC=1 SCAR=0.0
9 23 ▶use Carp qw/croak/;
Subroutine __ANON__: called CC=1 SCAR=0.0
10  
11 23 our $VERSION = '1.01';
12  
13 23 ▶use constant ro => 'ro';
Subroutine __ANON__: called CC=1 SCAR=0.0
14 23 ▶use constant is_ro => ( is => ro );
Subroutine __ANON__: called CC=1 SCAR=0.0
15 23 ▶use constant rw => 'rw';
Subroutine __ANON__: called CC=1 SCAR=0.0
16 23 ▶use constant is_rw => ( is => rw );
Subroutine __ANON__: called CC=1 SCAR=0.0
17 23 ▶use constant nan => undef;
Subroutine __ANON__: called CC=1 SCAR=0.0
18 23 ▶use constant lzy => ( lazy => 1 );
Subroutine __ANON__: called CC=1 SCAR=0.0
19 23 ▶use constant bld => ( builder => 1 );
Subroutine __ANON__: called CC=1 SCAR=0.0
20 23 ▶use constant lzy_bld => ( lazy_build => 1 );
Subroutine __ANON__: called CC=1 SCAR=0.0
21 23 ▶use constant trg => ( trigger => 1 );
Subroutine __ANON__: called CC=1 SCAR=0.0
22 23 ▶use constant clr => ( clearer => 1 );
Subroutine __ANON__: called CC=1 SCAR=0.0
23 23 ▶use constant req => ( required => 1 );
Subroutine __ANON__: called CC=1 SCAR=0.0
24 23 ▶use constant coe => ( coerce => 1 );
Subroutine __ANON__: called CC=1 SCAR=0.0
25 23 ▶use constant prv => ( private => 1 );
Subroutine __ANON__: called CC=1 SCAR=0.0
26 23 ▶use constant lzy_hash => (lazy => 1, isa => 'HashRef', default => {} );
Subroutine __ANON__: called CC=1 SCAR=0.0
27 23 ▶use constant lzy_array => (lazy => 1, isa => 'ArrayRef', default => [] );
Subroutine __ANON__: called CC=1 SCAR=0.0
28 23 ▶use constant lzy_str => (lazy => 1, isa => 'Str', default => "");
Subroutine __ANON__: called CC=1 SCAR=0.0
29 23 ▶use constant dhash => (isa => 'HashRef', default => {});
Subroutine __ANON__: called CC=1 SCAR=0.0
30 23 ▶use constant darray => (isa => 'ArrayRef', default => []);
Subroutine __ANON__: called CC=1 SCAR=0.0
31 23 ▶use constant dstr => (isa => 'Str', default => "");
Subroutine __ANON__: called CC=1 SCAR=0.0
32  
33 23 our (%valid_types, @type_list, %valid_constants, %modifier_dispatch, %accessor_aliases);
34  
35 23 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
36 23 @type_list = @{ Object::Proto::list_types() };
37 23 %valid_types = map { $_ => 1 } @type_list;
38 23 %valid_constants = map { $_ => 1 } qw(
39 ro rw is_ro is_rw nan
40 lzy bld lzy_bld trg clr req coe prv
41 lzy_hash lzy_array lzy_str dhash darray dstr
42 );
43 23 %modifier_dispatch = (
44 before => \&Object::Proto::before,
45 after => \&Object::Proto::after,
46 around => \&Object::Proto::around,
47 );
48 }
49  
50 39 ▶sub import {
Subroutine import: called CC=12 SCAR=24.9
51 39 my ($pkg, @import) = @_;
52 39 my $caller = caller();
53 39 my (@spec, @modifiers, @extends, @with, @requires, $is_role, $accessor_alias);
54 39 ▶ $is_role = 1 if grep { $_ eq '-role' } @import;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "-role";} @import 1 38 39
55  
56 39 ▶ if (grep { $_ eq '-types' } @import) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "-types";} @import) 0 39 39
57 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
58 0 ▶ *{"${caller}::${_}"} = sub { $_ } for @type_list;
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 }
60 39 ▶ if (grep { $_ eq '-constants' } @import) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "-constants";} @import) 2 37 39
61 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
62 2 *{"${caller}::${_}"} = \&{"Object::Proto::Sugar::${_}"} for keys %valid_constants;
63 }
64  
65 39 for my $name (@import) {
66 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
67 11 ▶ next if $name =~ /^-/;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /^-/ 3 8 11
68 8 ▶ if ($name =~ /^[A-Z]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^[A-Z]/) { } 1 7 8
69 croak "Unknown type '$name' requested from Object::Proto::Sugar"
70 1 ▶ unless $valid_types{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $Object::Proto::Sugar::valid_types{$name} 0 1 1
71 1 ▶ *{"${caller}::${name}"} = sub { $name };
Subroutine __ANON__: called CC=1 SCAR=0.0
72 } else {
73 croak "Unknown constant '$name' requested from Object::Proto::Sugar"
74 7 ▶ unless $valid_constants{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $Object::Proto::Sugar::valid_constants{$name} 0 7 7
75 7 *{"${caller}::${name}"} = \&{"Object::Proto::Sugar::${name}"};
76 }
77 }
78  
79 BEGIN::Lift::install(
80 96 ▶ ($caller, 'has') => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
81 96 my ($name, %params) = @_;
82 96 ▶ if (ref $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $name) { } 3 93 96
83 3 for (@{$name}) {
84 9 push @spec, $_, \%params;
85 }
86 } else {
87 93 push @spec, $name, \%params;
88 }
89 }
90 39 );
91  
92 BEGIN::Lift::install(
93 3 ▶ ($caller, 'attributes') => sub {
Subroutine __ANON__: called CC=14 SCAR=26.4
94 3 my @attr = @_;
95 3 ▶ while (@attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@attr) 26 3 29
96 26 ▶ my @names = ref $attr[0] eq 'ARRAY' ? @{ shift @attr } : shift @attr;
Branch: 1 branch
BranchTrueFalseTotal
ref $attr[0] eq 'ARRAY' ? : 2 24 26
97 26 my @sp = @{ shift(@attr) };
98 splice @sp, $#sp < 1 ? 0 : 1, 0, delete $sp[-1]->{default}
99 26 ▶ if ref $sp[-1] eq 'HASH' && exists $sp[-1]->{default};
Branch: 2 branches
BranchTrueFalseTotal
if ref $sp[-1] eq "HASH" and exists $sp[-1]{"default"} 4 22 26
$#sp < 1 ? : 1 3 4
Condition100%3/3
ref $sp[-1] eq "HASH" and exists $sp[-1]{"default"}
!ll&&!rl&&r
1574
MC/DC100%2/2
ref $sp[-1] eq "HASH" and exists $sp[-1]{"default"}
ref $sp[-1] eq "HASH" exists $sp[-1]{"default"}
Truth table100%3/3
A and B
A= ref $sp[-1] eq "HASH"B= exists $sp[-1]{"default"}
ABresult
0X0
100
111
100 26 ▶ unshift @sp, 'ro' unless (!$sp[0] || !ref $sp[0]) && ($sp[0] || "") =~ m/^(ro|rw|set)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless not $sp[0] && ref $sp[0] and ($sp[0] || "") =~ /^(ro|rw|set)$/ 10 16 26
Condition100%8/8
not $sp[0] && ref $sp[0] and ($sp[0] || "") =~ /^(ro|rw|set)$/
!ll&&!rl&&r
4616
$sp[0] && ref $sp[0]
!ll&&!rl&&r
2204
$sp[0] || ''
l!l
202
MC/DC100%3/3
not $sp[0] && ref $sp[0] and ($sp[0] || "") =~ /^(ro|rw|set)$/
$sp[0] ref $sp[0] $sp[0]
Truth table60%3/5
not(A && B) and C
A= $sp[0]B= ref $sp[0]C= $sp[0]
ABCresult
11X0
0X00
1000
0X11
1011
101 26 my %params = (is => $sp[0]);
102 25 ▶ $params{default} = ref $sp[1] eq 'CODE' ? $sp[1] : sub { Object::Proto::clone($sp[1]) }
Subroutine __ANON__: called CC=1 SCAR=0.0
103 26 ▶ if defined $sp[1];
Branch: 2 branches
BranchTrueFalseTotal
if defined $sp[1] 22 4 26
ref $sp[1] eq 'CODE' ? : 1 21 22
104 26 ▶ %params = (%params, %{ $sp[2] }) if ref $sp[2] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $sp[2] eq "HASH" 7 19 26
105 26 push @spec, $_, \%params for @names;
106 }
107 }
108 39 );
109  
110  
111 BEGIN::Lift::install(
112 7 ▶ ($caller, 'extends') => sub { push @extends, @_ }
Subroutine __ANON__: called CC=1 SCAR=0.0
113 39 );
114  
115 BEGIN::Lift::install(
116 1 ▶ ($caller, 'with') => sub { push @with, @_ }
Subroutine __ANON__: called CC=1 SCAR=0.0
117 39 );
118  
119 BEGIN::Lift::install(
120 1 ▶ ($caller, 'requires') => sub { push @requires, @_ }
Subroutine __ANON__: called CC=1 SCAR=0.0
121 39 );
122  
123 BEGIN::Lift::install(
124 9 ▶ ($caller, 'accessor_alias') => sub { $accessor_alias = $_[0] }
Subroutine __ANON__: called CC=1 SCAR=0.0
125 39 );
126  
127 39 for my $mod_type (qw/before after around/) {
128 BEGIN::Lift::install(
129 3 ▶ ($caller, $mod_type) => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
130 3 my ($name, $code) = @_;
131 3 push @modifiers, [$mod_type, $name, $code];
132 }
133 117 );
134 }
135  
136 39 ▶ Devel::Hook->push_UNITCHECK_hook(sub {
Subroutine __ANON__: called CC=13 SCAR=25.7
137 39 my @spec_copy = @spec;
138 39 my (@func_names, $attr, $spec, %isa, @attributes);
139 39 ▶ while (@spec) {
Branch: 1 branch
BranchTrueFalseTotal
if (@spec) 132 39 171
140 132 ($attr, $spec) = (shift @spec, shift @spec);
141 132 $attr = _configure_is($attr, $spec);
142 132 $attr = _configure_required($attr, $spec);
143 132 $attr = _configure_lazy($attr, $spec);
144 132 $attr = _configure_isa_and_coerce($attr, $spec, \%isa, $caller);
145 132 $attr = _configure_default_and_builder($attr, $spec, \%isa, $caller);
146 132 $attr = _configure_trigger($attr, $spec, \%isa, $caller);
147 132 $attr = _configure_predicate($attr, $spec, $caller, 'predicate');
148 132 $attr = _configure_clearer($attr, $spec, $caller, 'clearer');
149 132 $attr = _configure_reader_and_writer($attr, $spec, $caller);
150 132 $attr = _configure_init_arg($attr, $spec, $caller);
151 132 $attr = _configure_weak_ref($attr, $spec, $caller);
152 132 $attr = _configure_private($attr, $spec);
153 132 push @attributes, $attr;
154 }
155  
156 39 ▶ my @extends_arg = @extends > 1
Branch: 2 branches
BranchTrueFalseTotal
@extends > 1 ? : 0 39 39
@extends ? : 7 32 39
157 ? (extends => \@extends)
158 : @extends
159 ? (extends => $extends[0])
160 : ();
161 39 ▶ if ($is_role) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_role) { } 1 38 39
162 1 Object::Proto::role($caller, @attributes);
163 1 ▶ Object::Proto::requires($caller, @requires) if @requires;
Branch: 1 branch
BranchTrueFalseTotal
if @requires 1 0 1
164 } else {
165 38 Object::Proto::define($caller, @extends_arg, @attributes);
166 }
167 39 ▶ Object::Proto::with($caller, @with) if @with;
Branch: 1 branch
BranchTrueFalseTotal
if @with 1 38 39
168  
169 39 ▶ $accessor_aliases{$caller} = $accessor_alias if $accessor_alias;
Branch: 1 branch
BranchTrueFalseTotal
if $accessor_alias 9 30 39
170  
171 39 my %func_to_attr;
172 39 ▶ while (@spec_copy) {
Branch: 1 branch
BranchTrueFalseTotal
if (@spec_copy) 132 39 171
173 132 my ($name, $spec) = (shift @spec_copy, shift @spec_copy);
174 132 my @fnames = _install_func_accessors($caller, $name, $spec, $accessor_alias);
175 132 $func_to_attr{$_} = $name for @fnames;
176 132 push @func_names, @fnames;
177 }
178  
179 39 ▶ if (@func_names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@func_names) 15 24 39
180 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
181 15 push @{"${caller}::EXPORT_FUNC"}, @func_names;
182 }
183  
184 {
185 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
186 23 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
187 39 ▶ *{"${caller}::import_accessors"} = sub {
Subroutine __ANON__: called CC=9 SCAR=22.1
188 7 my ($class, @names) = @_;
189 7 my $target = caller();
190 # Use C-level installer - creates CVs with call checkers
191 # so code compiled after this gets custom ops
192 7 ▶ unless (@names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names) { } 3 4 7
193 4 for my $pkg (_mro($class)) {
194 7 ▶ my $alias = $accessor_aliases{$pkg} || '';
Condition100%2/2
$Object::Proto::Sugar::accessor_aliases{$pkg} || ''
l!l
34
MC/DC100%1/1
$Object::Proto::Sugar::accessor_aliases{$pkg} || ''
$Object::Proto::Sugar::accessor_aliases{$pkg}
Truth table100%2/2
A
A= $Object::Proto::Sugar::accessor_aliases{$pkg}
Aresult
11
00
195 7 ▶ Object::Proto::import_accessors($pkg, ($alias ? "${alias}_" : ""), $target);
Branch: 1 branch
BranchTrueFalseTotal
$alias ? : 3 4 7
196 }
197 } else {
198 3 for my $name (@names) {
199 3 ▶ my $attr = $func_to_attr{$name} || $name;
Condition33%1/3
$func_to_attr{$name} || $name
l!l&&r!l&&!r
300
MC/DC0%0/2
$func_to_attr{$name} || $name
$func_to_attr{$name} $name
Truth table33%1/3
A || B
A= $func_to_attr{$name}B= $name
ABresult
1X1
011
000
200 3 for my $pkg (_mro($class)) {
201 3 ▶ if (defined &{"${pkg}::${name}"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &{"${pkg}::$name";}) 3 0 3
202 3 Object::Proto::import_accessor($pkg, $attr, $name, $target);
203 3 last;
204 }
205 }
206 }
207 }
208 39 };
209 }
210  
211 39 for my $mod (@modifiers) {
212 3 my ($type, $name, $code) = @{$mod};
213 3 ▶ my $meth = $name =~ /::/ ? $name : "${caller}::${name}";
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /::/ ? : 0 3 3
214 3 $modifier_dispatch{$type}->($meth, $code);
215 }
216 39 });
217 }
218  
219 7 ▶sub _mro {
Subroutine _mro: called CC=3 SCAR=11.0
220 7 my ($class) = @_;
221 7 my (@queue, @order, %seen) = ($class);
222 7 ▶ while (my $pkg = shift @queue) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pkg = shift @queue) 12 7 19
223 12 ▶ next if $seen{$pkg}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$pkg}++ 0 12 12
224 12 push @order, $pkg;
225 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
226 12 push @queue, @{"${pkg}::ISA"};
227 }
228 7 return @order;
229 }
230  
231 132 ▶sub _configure_is {
Subroutine _configure_is: called CC=3 SCAR=11.0
232 132 my ($attr, $spec) = @_;
233 132 ▶ if (defined $spec->{is}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{"is"}) 127 5 132
234 127 ▶ if ($spec->{is} eq 'ro') {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"is"} eq "ro") 54 73 127
235 54 $attr .= ":readonly";
236 }
237 }
238 132 return $attr;
239 }
240  
241  
242 132 ▶sub _configure_required {
Subroutine _configure_required: called CC=2 SCAR=6.9
243 132 my ($attr, $spec) = @_;
244 132 ▶ if ($spec->{required}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"required"}) 1 131 132
245 1 $attr .= ":required";
246 }
247 132 return $attr;
248 }
249  
250 132 ▶sub _configure_lazy {
Subroutine _configure_lazy: called CC=2 SCAR=6.9
251 132 my ($attr, $spec) = @_;
252 132 ▶ if ( $spec->{lazy} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"lazy"}) 9 123 132
253 9 $attr .= ":lazy";
254 }
255 132 return $attr;
256 }
257  
258 132 ▶sub _configure_isa_and_coerce {
Subroutine _configure_isa_and_coerce: called CC=13 SCAR=25.8
259 132 my ($attr, $spec, $isa, $caller) = @_;
260 132 my ($ref, $val1, $val2);
261 132 ▶ if (defined $spec->{isa} || defined $spec->{coerce}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{"isa"} or defined $spec->{"coerce"}) 50 82 132
Condition100%3/3
defined $spec->{"isa"} or defined $spec->{"coerce"}
l!l&&r!l&&!r
47382
MC/DC100%2/2
defined $spec->{"isa"} or defined $spec->{"coerce"}
defined $spec->{"isa"} defined $spec->{"coerce"}
Truth table100%3/3
A or B
A= defined $spec->{"isa"}B= defined $spec->{"coerce"}
ABresult
1X1
011
000
262 50 ▶ $ref = ref $spec->{isa} || "";
Condition100%2/2
ref $spec->{'isa'} || ''
l!l
248
MC/DC100%1/1
ref $spec->{'isa'} || ''
ref $spec->{'isa'}
Truth table100%2/2
A
A= ref $spec->{'isa'}
Aresult
11
00
263 50 ▶ if ($ref eq 'CODE' || defined $spec->{coerce}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'CODE' or defined $spec->{'coerce'}) { } 5 45 50
elsif (not $ref) { } 45 0 45
Condition100%3/3
$ref eq "CODE" or defined $spec->{"coerce"}
l!l&&r!l&&!r
2345
MC/DC100%2/2
$ref eq "CODE" or defined $spec->{"coerce"}
$ref eq "CODE" defined $spec->{"coerce"}
Truth table100%3/3
A or B
A= $ref eq "CODE"B= defined $spec->{"coerce"}
ABresult
1X1
011
000
264 5 ▶ $val1 = (exists $spec->{isa} ? $spec->{isa} + 0 : '0000');
Branch: 1 branch
BranchTrueFalseTotal
exists $spec->{'isa'} ? : 2 3 5
265 5 ▶ $val2 = (exists $spec->{coerce} ? $spec->{coerce} + 0 : '0000');
Branch: 1 branch
BranchTrueFalseTotal
exists $spec->{'coerce'} ? : 3 2 5
266 5 ▶ if (!$isa->{$val1 . $val2}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$isa{$val1 . $val2}++) 4 1 5
267 Object::Proto::register_type('T' . $val1 . $val2,
268 4 ▶ $spec->{isa} || sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
269 4 ▶ $spec->{coerce} || sub { $_[0] }
Subroutine __ANON__: called CC=1 SCAR=0.0
270 4 ▶ );
Condition66%4/6
$spec->{'isa'} || sub { 1; }
l!l&&r!l&&!r
220
$spec->{'coerce'} || sub { $_[0]; }
l!l&&r!l&&!r
220
MC/DC0%0/2
$spec->{'isa'} || sub { 1; }
$spec->{'isa'} sub { 1; }
MC/DC0%0/2
$spec->{'coerce'} || sub { $_[0]; }
$spec->{'coerce'} sub { $_[0]; }
Truth table66%2/3
A || B
A= $spec->{'isa'}B= sub { 1; }
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $spec->{'coerce'}B= sub { $_[0]; }
ABresult
1X1
011
000
271 }
272 5 $attr .= sprintf(":T%s%s", $val1, $val2);
273 } elsif ( !$ref ) {
274 45 $val1 = ucfirst($spec->{isa});
275 45 ▶ if ($valid_types{$val1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Object::Proto::Sugar::valid_types{$val1}) 45 0 45
276 45 $attr .= sprintf(":%s", $val1);
277 }
278 } else {
279 0 croak "Failed to attach isa for $attr in $caller";
280 }
281 }
282  
283 132 return $attr;
284 }
285  
286 132 ▶sub _configure_default_and_builder {
Subroutine _configure_default_and_builder: called CC=17 SCAR=28.5
287 132 my ($attr, $spec, $isa, $caller) = @_;
288 132 my ($ref1, $ref2, $val1, $cb);
289 132 ▶ return $attr unless exists $spec->{default} || exists $spec->{builder};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $spec->{"default"} or exists $spec->{"builder"} 58 74 132
Condition100%3/3
exists $spec->{"default"} or exists $spec->{"builder"}
l!l&&r!l&&!r
611358
MC/DC100%2/2
exists $spec->{"default"} or exists $spec->{"builder"}
exists $spec->{"default"} exists $spec->{"builder"}
Truth table100%3/3
A or B
A= exists $spec->{"default"}B= exists $spec->{"builder"}
ABresult
1X1
011
000
290 74 ▶ $ref1 = ref($spec->{default}) || "";
Condition100%2/2
ref $spec->{'default'} || ''
l!l
5420
MC/DC100%1/1
ref $spec->{'default'} || ''
ref $spec->{'default'}
Truth table100%2/2
A
A= ref $spec->{'default'}
Aresult
11
00
291 74 ▶ if (exists $spec->{builder} || $ref1 eq 'CODE') {
Branch: 4 branches
BranchTrueFalseTotal
if (exists $spec->{'builder'} or $ref1 eq 'CODE') { } 64 10 74
elsif (not $ref1) { } 7 3 10
elsif ($ref1 eq 'ARRAY') { } 2 1 3
elsif ($ref1 eq 'HASH') { } 1 0 1
Condition100%3/3
exists $spec->{"builder"} or $ref1 eq "CODE"
l!l&&r!l&&!r
135110
MC/DC100%2/2
exists $spec->{"builder"} or $ref1 eq "CODE"
exists $spec->{"builder"} $ref1 eq "CODE"
Truth table100%3/3
A or B
A= exists $spec->{"builder"}B= $ref1 eq "CODE"
ABresult
1X1
011
000
292 64 $ref2 = ref($spec->{builder});
293 64 ▶ if (! $ref2 && $ref1 ne 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ref2 and $ref1 ne 'CODE') { } 6 58 64
elsif ($ref2 eq 'CODE' or $ref1 eq 'CODE') { } 58 0 58
Condition100%3/3
not $ref2 and $ref1 ne "CODE"
!ll&&!rl&&r
7516
MC/DC100%2/2
not $ref2 and $ref1 ne "CODE"
not $ref2 $ref1 ne "CODE"
Truth table100%3/3
not(A) and B
A= not $ref2B= $ref1 ne "CODE"
ABresult
0X0
100
111
294 6 ▶ if ($spec->{builder} =~ m/^1$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{'builder'} =~ /^1$/) { } 6 0 6
295 6 $attr .= ':builder()';
296 } else {
297 0 $attr .= sprintf(":builder(%s)", $spec->{builder});
298 }
299 ▶ } elsif ( $ref2 eq 'CODE' || $ref1 eq 'CODE' ) {
Condition66%2/3
$ref2 eq "CODE" or $ref1 eq "CODE"
l!l&&r!l&&!r
7510
MC/DC0%0/2
$ref2 eq "CODE" or $ref1 eq "CODE"
$ref2 eq "CODE" $ref1 eq "CODE"
Truth table66%2/3
A or B
A= $ref2 eq "CODE"B= $ref1 eq "CODE"
ABresult
1X1
011
000
300 58 ▶ my $cb = exists $spec->{builder} ? $spec->{builder} : $spec->{default};
Branch: 1 branch
BranchTrueFalseTotal
exists $spec->{'builder'} ? : 7 51 58
301 58 $val1 = 'BUILDER' . ($cb + 0);
302 58 ▶ if (!$isa->{$val1}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isa->{$val1}++) 50 8 58
303 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
304 50 *{"${caller}::${val1}"} = $cb;
305 }
306 58 $attr .= sprintf(":builder(%s)", $val1);
307 } else {
308 0 croak "Failed to attach builder for $attr in $caller";
309 }
310 } elsif ( ! $ref1 ) {
311 7 ▶ $attr .= sprintf(":default(%s)", defined $spec->{default} ? $spec->{default} : 'undef' );
Branch: 1 branch
BranchTrueFalseTotal
defined $spec->{'default'} ? : 6 1 7
312 } elsif ( $ref1 eq 'ARRAY') {
313 2 $attr .= ":default([])";
314 } elsif ( $ref1 eq 'HASH' ) {
315 1 $attr .= ":default({})";
316 }
317 74 return $attr;
318 }
319  
320 132 ▶sub _configure_trigger {
Subroutine _configure_trigger: called CC=5 SCAR=16.2
321 132 my ($attr, $spec, $isa, $caller) = @_;
322 132 my ($ref, $val1);
323 132 ▶ if (exists $spec->{trigger}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec->{"trigger"}) 2 130 132
324 2 $ref = ref $spec->{trigger};
325 2 ▶ if ( ! $ref ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ref) { } 0 2 2
elsif ($ref eq 'CODE') { } 2 0 2
326 0 $attr .= sprintf(":trigger(%s)", $spec->{trigger});
327 } elsif ( $ref eq 'CODE' ) {
328 2 $val1 = 'TRIG' . ($spec->{trigger} + 0);
329 2 ▶ if (!$isa->{$val1}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isa->{$val1}++) 1 1 2
330 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
331 1 *{"${caller}::${val1}"} = $spec->{trigger};
332 }
333 2 $attr .= sprintf(":trigger(%s::%s)", $caller, $val1);
334 }
335  
336 }
337 132 return $attr;
338 }
339  
340 132 ▶sub _configure_predicate {
Subroutine _configure_predicate: called CC=4 SCAR=14.0
341 132 my ($attr, $spec, $caller) = @_;
342 132 ▶ if (defined $spec->{predicate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{"predicate"}) 3 129 132
343 3 ▶ if ($spec->{predicate} =~ 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec->{'predicate'} =~ /1/) { } 2 1 3
elsif (not ref $spec->{'predicate'}) { } 1 0 1
344 2 $attr .= ":predicate";
345 } elsif (! ref $spec->{predicate}) {
346 1 $attr .= sprintf(":predicate(%s)", $spec->{predicate});
347 } else {
348 0 croak "Failed to attach predicate for $attr in $caller";
349 }
350 }
351 132 return $attr;
352 }
353  
354 132 ▶sub _configure_clearer {
Subroutine _configure_clearer: called CC=4 SCAR=14.0
355 132 my ($attr, $spec, $caller) = @_;
356 132 ▶ if (defined $spec->{clearer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{"clearer"}) 5 127 132
357 5 ▶ if ($spec->{clearer} =~ 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec->{'clearer'} =~ /1/) { } 4 1 5
elsif (not ref $spec->{'clearer'}) { } 1 0 1
358 4 $attr .= ":clearer";
359 } elsif (! ref $spec->{clearer}) {
360 1 $attr .= sprintf(":clearer(%s)", $spec->{clearer});
361 } else {
362 0 croak "Failed to attach clearer for $attr in $caller";
363 }
364 }
365 132 return $attr;
366 }
367  
368 132 ▶sub _configure_reader_and_writer {
Subroutine _configure_reader_and_writer: called CC=7 SCAR=19.5
369 132 my ($attr, $spec, $caller) = @_;
370 132 my ($name) = $attr =~ m/^([^\:]+)/;
371 132 ▶ if (exists $spec->{reader}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec->{"reader"}) 4 128 132
372 4 ▶ croak "Failed to attach reader for $attr in $caller" unless ! ref $spec->{reader};
Branch: 1 branch
BranchTrueFalseTotal
if ref $spec->{"reader"} 0 4 4
373 4 ▶ if ($spec->{reader} =~ m/^1$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{'reader'} =~ /^1$/) { } 3 1 4
374 3 $attr .= sprintf(":reader(get_%s)", $name);
375 } else {
376 1 $attr .= sprintf(":reader(%s)", $spec->{reader});
377 }
378 }
379 132 ▶ if (exists $spec->{writer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec->{"writer"}) 4 128 132
380 4 ▶ croak "Failed to attach writer for $attr in $caller" unless ! ref $spec->{writer};
Branch: 1 branch
BranchTrueFalseTotal
if ref $spec->{"writer"} 0 4 4
381 4 ▶ if ($spec->{writer} =~ m/^1$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{'writer'} =~ /^1$/) { } 3 1 4
382 3 $attr .= sprintf(":writer(set_%s)", $name);
383 } else {
384 1 $attr .= sprintf(":writer(%s)", $spec->{writer});
385 }
386 }
387 132 return $attr;
388 }
389  
390 132 ▶sub _configure_init_arg {
Subroutine _configure_init_arg: called CC=4 SCAR=13.9
391 132 my ($attr, $spec) = @_;
392 132 ▶ if (defined $spec->{init_arg} || defined $spec->{arg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{"init_arg"} or defined $spec->{"arg"}) 2 130 132
Condition100%3/3
defined $spec->{"init_arg"} or defined $spec->{"arg"}
l!l&&r!l&&!r
11130
MC/DC100%2/2
defined $spec->{"init_arg"} or defined $spec->{"arg"}
defined $spec->{"init_arg"} defined $spec->{"arg"}
Truth table100%3/3
A or B
A= defined $spec->{"init_arg"}B= defined $spec->{"arg"}
ABresult
1X1
011
000
393 2 ▶ $attr .= sprintf(":arg(%s)", $spec->{init_arg} || $spec->{arg});
Condition66%2/3
$spec->{'init_arg'} || $spec->{'arg'}
l!l&&r!l&&!r
110
MC/DC0%0/2
$spec->{'init_arg'} || $spec->{'arg'}
$spec->{'init_arg'} $spec->{'arg'}
Truth table66%2/3
A || B
A= $spec->{'init_arg'}B= $spec->{'arg'}
ABresult
1X1
011
000
394 }
395 132 return $attr;
396 }
397  
398 132 ▶sub _configure_weak_ref {
Subroutine _configure_weak_ref: called CC=3 SCAR=11.0
399 132 my ($attr, $spec) = @_;
400 132 ▶ if ($spec->{weak_ref} || $spec->{weak}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"weak_ref"} or $spec->{"weak"}) 1 131 132
Condition66%2/3
$spec->{"weak_ref"} or $spec->{"weak"}
l!l&&r!l&&!r
10131
MC/DC50%1/2
$spec->{"weak_ref"} or $spec->{"weak"}
$spec->{"weak_ref"} $spec->{"weak"}
Truth table66%2/3
A or B
A= $spec->{"weak_ref"}B= $spec->{"weak"}
ABresult
1X1
011
000
401 1 $attr .= ':weak';
402 }
403 132 return $attr;
404 }
405  
406 132 ▶sub _configure_private {
Subroutine _configure_private: called CC=2 SCAR=6.9
407 132 my ($attr, $spec) = @_;
408 132 ▶ if ($spec->{private}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"private"}) 2 130 132
409 2 $attr .= ':private';
410 }
411 132 return $attr;
412 }
413  
414 132 ▶sub _install_func_accessors {
Subroutine _install_func_accessors: called CC=15 SCAR=27.2
415 132 my ($caller, $name, $spec, $alias) = @_;
416 132 my @installed;
417 132 ▶ if (exists $spec->{accessor}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec->{"accessor"}) 21 111 132
418 my $fname = ($alias && $spec->{accessor} eq '1')
419 ? $alias . '_' . $name
420 21 ▶ : $spec->{accessor} eq '1' ? $name : $spec->{accessor};
Branch: 2 branches
BranchTrueFalseTotal
$alias && $spec->{'accessor'} eq '1' ? : 13 8 21
$spec->{'accessor'} eq '1' ? : 6 2 8
Condition100%3/3
$alias and $spec->{"accessor"} eq 1
!ll&&!rl&&r
7113
MC/DC100%2/2
$alias and $spec->{"accessor"} eq 1
$alias $spec->{"accessor"} eq 1
Truth table100%3/3
A and B
A= $aliasB= $spec->{"accessor"} eq 1
ABresult
0X0
100
111
421 21 Object::Proto::import_accessor($caller, $name, $fname, $caller);
422 21 push @installed, $fname;
423 }
424 132 ▶ if (exists $spec->{reader} && !ref $spec->{reader}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec->{"reader"} and not ref $spec->{"reader"}) 4 128 132
Condition66%2/3
exists $spec->{"reader"} and not ref $spec->{"reader"}
!ll&&!rl&&r
12804
MC/DC50%1/2
exists $spec->{"reader"} and not ref $spec->{"reader"}
exists $spec->{"reader"} not ref $spec->{"reader"}
Truth table66%2/3
A and not(B)
A= exists $spec->{"reader"}B= not ref $spec->{"reader"}
ABresult
0X0
100
111
425 4 ▶ my $fname = $spec->{reader} eq '1' ? "get_$name" : $spec->{reader};
Branch: 1 branch
BranchTrueFalseTotal
$spec->{'reader'} eq '1' ? : 3 1 4
426 4 ▶ $fname = $alias . '_' . $fname if $alias && $spec->{reader} eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $alias and $spec->{"reader"} eq 1 1 3 4
Condition66%2/3
$alias and $spec->{"reader"} eq 1
!ll&&!rl&&r
301
MC/DC50%1/2
$alias and $spec->{"reader"} eq 1
$alias $spec->{"reader"} eq 1
Truth table66%2/3
A and B
A= $aliasB= $spec->{"reader"} eq 1
ABresult
0X0
100
111
427 4 Object::Proto::import_accessor($caller, $name, $fname, $caller);
428 4 push @installed, $fname;
429 }
430 132 ▶ if (exists $spec->{writer} && !ref $spec->{writer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec->{"writer"} and not ref $spec->{"writer"}) 4 128 132
Condition66%2/3
exists $spec->{"writer"} and not ref $spec->{"writer"}
!ll&&!rl&&r
12804
MC/DC50%1/2
exists $spec->{"writer"} and not ref $spec->{"writer"}
exists $spec->{"writer"} not ref $spec->{"writer"}
Truth table66%2/3
A and not(B)
A= exists $spec->{"writer"}B= not ref $spec->{"writer"}
ABresult
0X0
100
111
431 4 ▶ my $fname = $spec->{writer} eq '1' ? "set_$name" : $spec->{writer};
Branch: 1 branch
BranchTrueFalseTotal
$spec->{'writer'} eq '1' ? : 3 1 4
432 4 ▶ $fname = $alias . '_' . $fname if $alias && $spec->{writer} eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $alias and $spec->{"writer"} eq 1 1 3 4
Condition66%2/3
$alias and $spec->{"writer"} eq 1
!ll&&!rl&&r
301
MC/DC50%1/2
$alias and $spec->{"writer"} eq 1
$alias $spec->{"writer"} eq 1
Truth table66%2/3
A and B
A= $aliasB= $spec->{"writer"} eq 1
ABresult
0X0
100
111
433 4 Object::Proto::import_accessor($caller, $name, $fname, $caller);
434 4 push @installed, $fname;
435 }
436 132 return @installed;
437 }
438  
439 23 1;
440  
441 __END__
↑ Summary