blib/lib/YAOO.pm

filter: Statementstmt 83.5% 244 / 292 Branchbran 67.6% 88 / 130 Conditioncond 55.1% 27 / 49 MC/DCmcdc 13.3% 4 / 30 Subroutinesub 76.2% 45 / 59 Podpod 35.2% 12 / 34 totaltotal 70.7% 420 / 594 CC 94 SCAR 19.4
CC
94
Cov
76%
build_attribute
24.0
float
12.0
object
12.0
CRAP 7.0
↑ Summary
1 package YAOO;
2 7 ▶use strict; no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use Carp qw/croak/; use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use feature qw/state/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Blessed::Merge;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Hash::Typed;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 our $VERSION = '0.09';
9  
10 7 our (%TYPES, %object, $LAST);
11  
12 sub make_keyword {
13 379 ▶ my ($called, $key, $cb) = @_;
Subroutine make_keyword: called CC=1 SCAR=0.0
Pod undocumented
14 379 *{"${called}::$key"} = $cb;
15 379 $LAST = 10000000000000000000;
16 }
17  
18 sub import {
19 11 ▶ my ($package, @attributes) = @_;
Subroutine import: called CC=4 SCAR=13.9
20  
21 11 my $called = caller();
22  
23 11 strict->import();
24 11 warnings->import();
25  
26 11 for my $is (qw/ro rw/) {
27 22 ▶ make_keyword($called, $is, sub { is => $is });
Subroutine __ANON__: called CC=1 SCAR=0.0
28 }
29  
30 11 for my $key (qw/isa default coerce required trigger lazy delay build_order/) {
31 make_keyword($called, $key, sub {
32 32 ▶ my (@value) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
33 32 ▶ return $key => scalar @value > 1 ? @value : ($value[0] || 1);
Branch: 1 branch
BranchTrueFalseTotal
scalar @value > 1 ? : 28 4 32
Condition100%2/2
$value[0] or 1
l!l
22
MC/DC100%1/1
$value[0] or 1
$value[0]
Truth table100%2/2
A
A= $value[0]
Aresult
11
00
34 88 });
35 }
36  
37 11 for my $isa ( qw/any string scalarref integer float boolean ordered_hash hash array object fh/ ) {
38 make_keyword($called, $isa, sub {
39 27 ▶ my (@args) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
40 my @return = (
41 27 \&{"${package}::${isa}"},
42 type => $isa,
43 27 build_default => \&{"${package}::build_${isa}"}
44 );
45 27 ▶ push @return, (default => ($isa eq 'ordered_hash' ? sub { deep_clone_ordered_hash(@args) } : sub { deep_clone( scalar @args > 1 ? $isa eq 'hash' ? {@args} : \@args : @args) }))
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 4 branches
BranchTrueFalseTotal
if scalar @args 13 14 27
$isa eq 'ordered_hash' ? : 4 9 13
scalar @args > 1 ? : 8 1 9
$isa eq 'hash' ? : 4 4 8
46 if (scalar @args);
47 27 @return;
48 121 });
49 }
50  
51 make_keyword($called, 'typed_hash', sub {
52 3 ▶ my (@args) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
53 3 my $spec = shift @args;
54 3 ▶ if (! scalar $spec) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar $spec) 0 3 3
55 0 die 'Invalid declaration of a typed_hash no Hash::Typed spec passed'
56 }
57 3 ▶ if (caller(1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (caller 1) 2 1 3
58 return Hash::Typed->new(
59 deep_clone($spec),
60 2 %{ deep_clone_ordered_hash(@args) }
61 );
62 }
63 my @return = (
64 1 \&{"${package}::typed_hash"},
65 type => 'typed_hash',
66 );
67 push @return, default => sub {
68 Hash::Typed->new(
69 deep_clone($spec),
70 1 ▶ %{ deep_clone_ordered_hash(@args) }
Subroutine __ANON__: called CC=1 SCAR=0.0
71 );
72 1 };
73 @return
74 11 });
75  
76  
77 11 ▶ make_keyword($called, 'auto_build', sub { $object{$called}{auto_build} = 1; });
Subroutine __ANON__: called CC=1 SCAR=0.0
78  
79 make_keyword($called, 'extends', sub {
80 4 ▶ my (@args) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.2
81 4 my $extend = caller();
82 4 for my $inherit (@args) {
83 4 load($inherit);
84 4 push @{*{\*{"${extend}::ISA"}}{ARRAY}}, $inherit;
85 4 ▶ return unless $object{$inherit};
Branch: 1 branch
BranchTrueFalseTotal
unless $YAOO::object{$inherit} 0 4 4
86 4 my $bm = Blessed::Merge->new(blessed => 0, same => 0);
87 4 $object{$extend} = $bm->merge($object{$extend}, $object{$inherit});
88 4 for my $name (keys %{$object{$extend}{has}}) {
89 make_keyword($extend, $name, sub {
90 17 ▶ my ($self, $value) = @_;
Subroutine __ANON__: called CC=7 SCAR=19.9
91 17 ▶ if ($value && (
Branch: 1 branch
BranchTrueFalseTotal
if ($value and $YAOO::object{$extend}{"has"}{$name}{"is"} eq "rw" || [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/) 13 4 17
Condition83%5/6
$value and $YAOO::object{$extend}{"has"}{$name}{"is"} eq "rw" || [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/
!ll&&!rl&&r
467
$YAOO::object{$extend}{"has"}{$name}{"is"} eq "rw" or [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/
l!l&&r!l&&!r
1030
MC/DC33%1/3
$value and $YAOO::object{$extend}{"has"}{$name}{"is"} eq "rw" || [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/
$value $YAOO::object{$extend}{"has"}{$name}{"is"} eq "rw" [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/
Truth table50%2/4
A and B or C
A= $valueB= $YAOO::object{$extend}{"has"}{$name}{"is"} eq "rw"C= [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/
ABCresult
0XX0
1000
11X1
1011
92 $object{$extend}{has}{$name}->{is} eq 'rw'
93 || [split '::', [caller(1)]->[3]]->[-1] =~ m/^new|build|set_defaults|auto_build$/
94 )) {
95 $value = $object{$extend}{has}{$name}->{coerce}($self, $value, $name)
96 13 ▶ if ($object{$extend}{has}{$name}->{coerce});
Branch: 1 branch
BranchTrueFalseTotal
if $YAOO::object{$extend}{"has"}{$name}{"coerce"} 0 13 13
97 $object{$extend}{has}{$name}->{required}($self, $value, $name)
98 13 ▶ if ($object{$extend}{$name}->{required});
Branch: 1 branch
BranchTrueFalseTotal
if $YAOO::object{$extend}{$name}{"required"} 0 13 13
99 13 $value = $object{$extend}{has}{$name}->{isa}($value, $name, $called);
100 13 $self->{$name} = $value;
101 $object{$extend}{has}{$name}->{trigger}($self, $value, $name)
102 13 ▶ if ($object{$extend}{has}{$name}->{trigger});
Branch: 1 branch
BranchTrueFalseTotal
if $YAOO::object{$extend}{"has"}{$name}{"trigger"} 0 13 13
103 }
104 17 $self->{$name};
105 16 });
106 }
107 4 for my $name (keys %{$object{$extend}{method}}) {
108 0 make_keyword($extend, $name, $object{$called}{method}{$name});
109 }
110 }
111 11 });
112  
113 make_keyword($called, 'require_has', sub {
114 2 ▶ my (@args) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
115 2 push @{ $object{$called}{require_has} }, @args;
116 11 });
117  
118 make_keyword($called, 'require_sub', sub {
119 1 ▶ my (@args) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
120 1 push @{ $object{$called}{require_sub} }, @args;
121 11 });
122  
123 make_keyword($called, 'require_method', sub {
124 0 ▶ my (@args) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
125 0 push @{ $object{$called}{require_sub} }, @args;
126 11 });
127  
128 11 $object{$called}{has} = {};
129 11 $object{$called}{method} = {};
130  
131 make_keyword($called, "method", sub {
132 1 ▶ my ($name, $sub) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
133  
134 1 $object{$called}{method}{$name} = $sub;
135 1 make_keyword($called, $name, $sub);
136 11 });
137  
138 11 ▶ make_keyword($called, 'has', sub { build_attribute($called, @_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
139  
140 make_keyword($called, "new", sub {
141 13 ▶ my ($pkg) = shift;
Subroutine __ANON__: called CC=5 SCAR=16.2
142 13 my $self = bless { }, $pkg;
143 13 require_has($called);
144 12 require_sub($self, $called);
145 12 require_method($called);
146 12 ▶ auto_ld($self, $called, 'lazy') if ($object{$called}{lazy});
Branch: 1 branch
BranchTrueFalseTotal
if $YAOO::object{$called}{"lazy"} 1 11 12
147 12 set_defaults($self, $called);
148 12 ▶ auto_build($self, $called, @_) if ($object{$called}{auto_build});
Branch: 1 branch
BranchTrueFalseTotal
if $YAOO::object{$called}{"auto_build"} 12 0 12
149 12 ▶ $self->build(@_) if ($self->can('build'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("build") 0 12 12
150 12 ▶ auto_ld($self, $called, 'delay') if ($object{$called}{delay});
Branch: 1 branch
BranchTrueFalseTotal
if $YAOO::object{$called}{"delay"} 1 11 12
151 12 return $self;
152 11 });
153 }
154  
155 sub build_attribute {
156 32 ▶ my ($called, $name, @attrs) = @_;
Subroutine build_attribute: called CC=20 SCAR=31.8
Pod undocumented
157  
158 32 ▶ my $ref = ref $name || 'STRING';
Condition100%2/2
ref $name || 'STRING'
l!l
230
MC/DC100%1/1
ref $name || 'STRING'
ref $name
Truth table100%2/2
A
A= ref $name
Aresult
11
00
159  
160 32 my $attribute_extend;
161 32 ▶ if ($name =~ s/^_([a-zA-Z].*)/$1/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/^_([a-zA-Z].*)/$1/) 0 32 32
162 0 $attribute_extend = 1;
163 }
164  
165 32 ▶ if ($ref eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'ARRAY') { } 1 31 32
elsif ($ref eq 'HASH') { } 1 30 31
166 1 build_attribute($called, $_, @attrs) for @{ $name };
167 } elsif ($ref eq 'HASH') {
168 1 build_attribute($called, $_, %{ $name->{$_} }) for keys %{ $name };
169 }
170  
171 32 ▶ if ( !$attribute_extend && $object{$called}{has}{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $attribute_extend and $YAOO::object{$called}{"has"}{$name}) 0 32 32
Condition33%1/3
not $attribute_extend and $YAOO::object{$called}{"has"}{$name}
!ll&&!rl&&r
0320
MC/DC0%0/2
not $attribute_extend and $YAOO::object{$called}{"has"}{$name}
not $attribute_extend $YAOO::object{$called}{"has"}{$name}
Truth table33%1/3
not(A) and B
A= not $attribute_extendB= $YAOO::object{$called}{"has"}{$name}
ABresult
0X0
100
111
172 0 croak sprintf "%s attribute already defined for %s object.", $name, $called;
173 }
174  
175 32 ▶ if ( scalar @attrs % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @attrs % 2) 0 32 32
176 0 croak sprintf "Invalid attribute definition odd number of key/value pairs (%s) passed with %s in %s object", scalar @attrs, $name, $called;
177 }
178  
179 32 $object{$called}{has}{$name} = {@attrs};
180  
181 $object{$called}{has}{$name}{is} = 'rw'
182 32 ▶ if (! $object{$called}{has}{$name}{is});
Branch: 1 branch
BranchTrueFalseTotal
unless $YAOO::object{$called}{"has"}{$name}{"is"} 9 23 32
183  
184 $object{$called}{has}{$name}{isa} = $TYPES{all}
185 32 ▶ if (not defined $object{$called}{has}{$name}{isa});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $YAOO::object{$called}{"has"}{$name}{"isa"} 1 31 32
186  
187 32 ▶ if ($object{$called}{has}{$name}{default}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YAOO::object{$called}{"has"}{$name}{"default"}) 14 18 32
188 14 ▶ if ($object{$called}{has}{$name}{default} =~ m/^1$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($YAOO::object{$called}{'has'}{$name}{'default'} =~ /^1$/) { } 0 14 14
elsif (ref $YAOO::object{$called}{'has'}{$name}{'default'} eq 'CODE') { } 14 0 14
189 0 $object{$called}{has}{$name}{value} = $object{$called}{has}{$name}{build_default}();
190 } elsif (ref $object{$called}{has}{$name}{default} eq 'CODE') {
191 14 $object{$called}{has}{$name}{value} = $object{$called}{has}{$name}{default}();
192 } else {
193 $object{$called}{has}{$name}{value} = $object{$called}{has}{$name}{type} eq 'ordered_hash'
194 ? deep_clone_ordered_hash($object{$called}{has}{$name}{default})
195 0 ▶ : deep_clone($object{$called}{has}{$name}{default});
Branch: 1 branch
BranchTrueFalseTotal
$YAOO::object{$called}{'has'}{$name}{'type'} eq 'ordered_hash' ? : 0 0 0
196 }
197 }
198  
199 32 ▶ if ($object{$called}{has}{$name}{required}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YAOO::object{$called}{"has"}{$name}{"required"}) 0 32 32
200 0 $object{$called}{has}{$name}{required} = \&required;
201 }
202  
203 32 ▶ if ($object{$called}{has}{$name}{lazy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YAOO::object{$called}{"has"}{$name}{"lazy"}) 4 28 32
204 4 push @{$object{$called}{lazy}}, $name;
205 }
206  
207 32 ▶ if ($object{$called}{has}{$name}{delay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YAOO::object{$called}{"has"}{$name}{"delay"}) 1 31 32
208 1 push @{$object{$called}{delay}}, $name;
209 }
210  
211 make_keyword($called, $name, sub {
212 65 ▶ my ($self, $value) = @_;
Subroutine __ANON__: called CC=8 SCAR=20.9
213 65 ▶ if (@_ > 1 && (
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1 and $YAOO::object{$called}{"has"}{$name}{"is"} eq "rw" || [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/) 36 29 65
Condition83%5/6
@_ > 1 and $YAOO::object{$called}{"has"}{$name}{"is"} eq "rw" || [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/
!ll&&!rl&&r
29279
$YAOO::object{$called}{"has"}{$name}{"is"} eq "rw" or [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/
l!l&&r!l&&!r
3240
MC/DC33%1/3
@_ > 1 and $YAOO::object{$called}{"has"}{$name}{"is"} eq "rw" || [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/
@_ > 1 $YAOO::object{$called}{"has"}{$name}{"is"} eq "rw" [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/
Truth table50%2/4
A and B or C
A= @_ > 1B= $YAOO::object{$called}{"has"}{$name}{"is"} eq "rw"C= [split(/::/, [caller 1]->[3], 0)]->[-1] =~ /^new|build|set_defaults|auto_build$/
ABCresult
0XX0
1000
11X1
1011
214 $object{$called}{has}{$name}->{is} eq 'rw'
215 || [split '::', [caller(1)]->[3]]->[-1] =~ m/^new|build|set_defaults|auto_build$/
216 )) {
217 36 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 35 1 36
218 $value = $object{$called}{has}{$name}->{coerce}($self, $value, $name)
219 35 ▶ if ($object{$called}{has}{$name}->{coerce});
Branch: 1 branch
BranchTrueFalseTotal
if $YAOO::object{$called}{"has"}{$name}{"coerce"} 2 33 35
220 $object{$called}{has}{$name}{required}($self, $value, $name)
221 35 ▶ if ($object{$called}{$name}->{required});
Branch: 1 branch
BranchTrueFalseTotal
if $YAOO::object{$called}{$name}{"required"} 0 35 35
222 35 $value = $object{$called}{has}{$name}{isa}($value, $name, $called);
223 35 $self->{$name} = $value;
224 $object{$called}{has}{$name}{trigger}($self, $value, $name)
225 35 ▶ if ($object{$called}{has}{$name}->{trigger});
Branch: 1 branch
BranchTrueFalseTotal
if $YAOO::object{$called}{"has"}{$name}{"trigger"} 0 35 35
226 } else {
227 1 $self->{$name} = undef;
228 }
229 }
230 65 $self->{$name};
231 32 ▶ }) unless $attribute_extend;
Branch: 1 branch
BranchTrueFalseTotal
unless $attribute_extend 32 0 32
232 }
233  
234 sub require_has {
235 13 ▶ my ($called) = shift;
Subroutine require_has: called CC=3 SCAR=11.0
Pod undocumented
236 13 for (@{ $object{$called}{require_has} }) {
237 croak sprintf "The required %s attribute is not defined in the %s object.", $_, $called
238 6 ▶ if (! $object{$called}{has}{$_} );
Branch: 1 branch
BranchTrueFalseTotal
unless $YAOO::object{$called}{"has"}{$_} 1 5 6
239 }
240 }
241  
242 sub require_sub {
243 12 ▶ my ($self, $called) = @_;
Subroutine require_sub: called CC=3 SCAR=11.1
Pod undocumented
244 12 for (@{ $object{$called}{require_sub} }) {
245 1 ▶ croak sprintf "The required %s sub is not defined in the %s object.", $_, $called
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($_) 0 1 1
246 if (! $self->can($_) );
247 }
248 }
249  
250 sub require_method {
251 12 ▶ my ($called) = shift;
Subroutine require_method: called CC=3 SCAR=14.2
Pod undocumented
252 12 for (@{ $object{$called}{require_method} }) {
253 croak sprintf "The required %s method is not defined in the %s object.", $_, $called
254 0 ▶ if (! $object{$called}{method}{$_} );
Branch: 1 branch
BranchTrueFalseTotal
unless $YAOO::object{$called}{"method"}{$_} 0 0 0
255 }
256 }
257  
258 sub set_defaults {
259 12 ▶ my ($self, $called) = @_;
Subroutine set_defaults: called CC=5 SCAR=16.2
Pod undocumented
260 map {
261 defined $object{$called}{has}{$_}{value} && $self->$_($object{$called}{has}{$_}{type} eq 'ordered_hash'
262 ? deep_clone_ordered_hash($object{$called}{has}{$_}{value})
263 50 ▶ : deep_clone($object{$called}{has}{$_}{value}))
Branch: 2 branches
BranchTrueFalseTotal
defined $YAOO::object{$called}{"has"}{$_}{"value"} and $self->$_($YAOO::object{$called}{"has"}{$_}{"type"} eq "ordered_hash" ? deep_clone_ordered_hash($YAOO::object{$called}{"has"}{$_}{"value"}) : deep_clone($YAOO::object{$called}{"has"}{$_}{"value"})) 26 24 50
$YAOO::object{$called}{'has'}{$_}{'type'} eq 'ordered_hash' ? : 7 19 26
264 73 ▶ } sort { ($object{$called}{has}{$a}{build_order} || $LAST) <=> ($object{$called}{has}{$b}{build_order} || $LAST) }
Condition66%4/6
$YAOO::object{$called}{'has'}{$a}{'build_order'} || $YAOO::LAST
l!l&&r!l&&!r
11620
$YAOO::object{$called}{'has'}{$b}{'build_order'} || $YAOO::LAST
l!l&&r!l&&!r
5680
MC/DC0%0/2
$YAOO::object{$called}{'has'}{$a}{'build_order'} || $YAOO::LAST
$YAOO::object{$called}{'has'}{$a}{'build_order'} $YAOO::LAST
MC/DC0%0/2
$YAOO::object{$called}{'has'}{$b}{'build_order'} || $YAOO::LAST
$YAOO::object{$called}{'has'}{$b}{'build_order'} $YAOO::LAST
Truth table66%2/3
A || B
A= $YAOO::object{$called}{'has'}{$a}{'build_order'}B= $YAOO::LAST
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $YAOO::object{$called}{'has'}{$b}{'build_order'}B= $YAOO::LAST
ABresult
1X1
011
000
265 12 keys %{$object{$called}{has}};
266 12 return $self;
267 }
268  
269 sub auto_build {
270 12 ▶ my ($self, $called, %build) = (shift, shift, scalar @_ == 1 ? %{ $_[0] } : @_);
Subroutine auto_build: called CC=5 SCAR=17.5
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 ? : 0 12 12
271 map {
272 17 ▶ if ($self->can($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($_)) 17 0 17
273 17 $self->$_($build{$_});
274 }
275 12 ▶ } sort { ($object{$called}{has}{$a}{build_order} || $LAST) <=> ($object{$called}{has}{$b}{build_order} || $LAST) }
Condition66%4/6
$YAOO::object{$called}{'has'}{$a}{'build_order'} || $YAOO::LAST
l!l&&r!l&&!r
560
$YAOO::object{$called}{'has'}{$b}{'build_order'} || $YAOO::LAST
l!l&&r!l&&!r
560
MC/DC0%0/2
$YAOO::object{$called}{'has'}{$a}{'build_order'} || $YAOO::LAST
$YAOO::object{$called}{'has'}{$a}{'build_order'} $YAOO::LAST
MC/DC0%0/2
$YAOO::object{$called}{'has'}{$b}{'build_order'} || $YAOO::LAST
$YAOO::object{$called}{'has'}{$b}{'build_order'} $YAOO::LAST
Truth table66%2/3
A || B
A= $YAOO::object{$called}{'has'}{$a}{'build_order'}B= $YAOO::LAST
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $YAOO::object{$called}{'has'}{$b}{'build_order'}B= $YAOO::LAST
ABresult
1X1
011
000
276 keys %build;
277 }
278  
279 sub auto_ld {
280 2 ▶ my ($self, $called, $type) = @_;
Subroutine auto_ld: called CC=5 SCAR=19.1
Pod undocumented
281 map {
282 5 ▶ my $cb_value = ref $object{$called}{has}{$_}{$type} || $object{$called}{has}{$_}{$type} !~ m/^1$/ ? $object{$called}{has}{$_}{$type} : $object{$called}{has}{$_}{build_default}->();
Branch: 1 branch
BranchTrueFalseTotal
ref $YAOO::object{$called}{'has'}{$_}{$type} || !($YAOO::object{$called}{'has'}{$_}{$type} =~ /^1$/) ? : 0 5 5
Condition33%1/3
ref $YAOO::object{$called}{"has"}{$_}{$type} or not $YAOO::object{$called}{"has"}{$_}{$type} =~ /^1$/
l!l&&r!l&&!r
005
MC/DC0%0/2
ref $YAOO::object{$called}{"has"}{$_}{$type} or not $YAOO::object{$called}{"has"}{$_}{$type} =~ /^1$/
ref $YAOO::object{$called}{"has"}{$_}{$type} not $YAOO::object{$called}{"has"}{$_}{$type} =~ /^1$/
Truth table33%1/3
A or not(B)
A= ref $YAOO::object{$called}{"has"}{$_}{$type}B= not $YAOO::object{$called}{"has"}{$_}{$type} =~ /^1$/
ABresult
1X1
011
000
283 5 $self->$_($cb_value);
284 } sort {
285 4 ▶ ($object{$called}{has}{$a}{build_order} || $LAST) <=> ($object{$called}{has}{$b}{build_order} || $LAST)
Condition33%2/6
$YAOO::object{$called}{'has'}{$a}{'build_order'} || $YAOO::LAST
l!l&&r!l&&!r
400
$YAOO::object{$called}{'has'}{$b}{'build_order'} || $YAOO::LAST
l!l&&r!l&&!r
400
MC/DC0%0/2
$YAOO::object{$called}{'has'}{$a}{'build_order'} || $YAOO::LAST
$YAOO::object{$called}{'has'}{$a}{'build_order'} $YAOO::LAST
MC/DC0%0/2
$YAOO::object{$called}{'has'}{$b}{'build_order'} || $YAOO::LAST
$YAOO::object{$called}{'has'}{$b}{'build_order'} $YAOO::LAST
Truth table33%1/3
A || B
A= $YAOO::object{$called}{'has'}{$a}{'build_order'}B= $YAOO::LAST
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $YAOO::object{$called}{'has'}{$b}{'build_order'}B= $YAOO::LAST
ABresult
1X1
011
000
286 2 } @{ $object{$called}{$type} };
287 }
288  
289 sub required {
290 0 ▶ my ($self, $value, $name) = @_;
Subroutine required: not called CC=2 SCAR=17.9
Pod documented
291 0 ▶ if ( not defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value) 0 0 0
292 0 croak sprintf "No defined value passed to the required %s attribute.",
293 $name;
294 }
295 }
296  
297 0 ▶sub any { $_[0] }
Subroutine any: not called CC=1 SCAR=6.9
Pod documented
298  
299 1 ▶sub build_string { "" }
Subroutine build_string: called CC=1 SCAR=0.0
Pod undocumented
300  
301 sub string {
302 6 ▶ my ($value, $name) = @_;
Subroutine string: called CC=2 SCAR=7.6
Pod documented
303 6 ▶ if (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) 0 6 6
304 0 croak sprintf "The value passed to the %s attribute does not match the string type constraint.",
305 $name;
306 }
307 6 return $value;
308 }
309  
310 4 ▶sub build_integer { 0 }
Subroutine build_integer: called CC=1 SCAR=0.0
Pod undocumented
311  
312 sub integer {
313 12 ▶ my ($value, $name) = @_;
Subroutine integer: called CC=3 SCAR=13.3
Pod documented
314 12 ▶ if (ref $value || $value !~ m/^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value or not $value =~ /^\d+$/) 0 12 12
Condition33%1/3
ref $value or not $value =~ /^\d+$/
l!l&&r!l&&!r
0012
MC/DC0%0/2
ref $value or not $value =~ /^\d+$/
ref $value not $value =~ /^\d+$/
Truth table33%1/3
A or not(B)
A= ref $valueB= not $value =~ /^\d+$/
ABresult
1X1
011
000
315 0 croak sprintf "The value passed to the %s attribute does not match the type constraint.",
316 $name;
317 }
318 12 return $value;
319 }
320  
321 0 ▶sub build_float { 0.00 }
Subroutine build_float: not called CC=1 SCAR=6.9
Pod undocumented
322  
323 sub float {
324 0 ▶ my ($value, $name) = @_;
Subroutine float: not called CC=3 SCAR=24.8
Pod documented
325 0 ▶ if (ref $value || $value !~ m/^\d+\.\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value or not $value =~ /^\d+\.\d+$/) 0 0 0
Condition0%0/3
ref $value or not $value =~ /^\d+\.\d+$/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $value or not $value =~ /^\d+\.\d+$/
ref $value not $value =~ /^\d+\.\d+$/
Truth table0%0/3
A or not(B)
A= ref $valueB= not $value =~ /^\d+\.\d+$/
ABresult
1X1
011
000
326 0 croak sprintf "The value passed to the %s attribute does not match the float constraint.",
327 $name;
328 }
329 0 return $value;
330 }
331  
332 0 ▶sub build_scalarref { \"" }
Subroutine build_scalarref: not called CC=1 SCAR=6.9
Pod undocumented
333  
334 sub scalarref {
335 0 ▶ my ($value, $name) = @_;
Subroutine scalarref: not called CC=2 SCAR=17.9
Pod documented
336 0 ▶ if (ref $value ne 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value ne "SCALAR") 0 0 0
337 0 croak sprintf "The value passed to the %s attribute does not match the scalarref constraint.",
338 $name;
339 }
340 0 return $value;
341 }
342  
343 0 ▶sub build_boolean { \1 }
Subroutine build_boolean: not called CC=1 SCAR=6.9
Pod undocumented
344  
345 sub boolean {
346 2 ▶ my ($value, $name) = @_;
Subroutine boolean: called CC=3 SCAR=11.8
Pod documented
347 2 ▶ if (! ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value) 2 0 2
348 2 $value = \!!$value;
349 }
350 2 ▶ if (ref $value ne 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value ne "SCALAR") 0 2 2
351 0 croak sprintf "The value passed to the %s attribute does not match the scalarref constraint.",
352 $name;
353 }
354 2 return $value;
355 }
356  
357 0 ▶sub build_ordered_hash { { } }
Subroutine build_ordered_hash: not called CC=1 SCAR=6.9
Pod undocumented
358  
359 7 ▶sub ordered_hash { hash(@_); }
Subroutine ordered_hash: called CC=1 SCAR=0.0
Pod documented
360  
361 sub typed_hash {
362 6 ▶ my ($value, $name, $called) = @_;
Subroutine typed_hash: called CC=3 SCAR=11.1
Pod undocumented
363  
364 6 ▶ if (ref $value ne 'Hash::Typed') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value ne "Hash::Typed") 4 2 6
365 4 my $hash = $object{$called}{has}{$name}{value};
366  
367 4 ▶ if (!$hash) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hash) 0 4 4
368 0 croak sprintf "The value passed to the %s attribute does not match the typed_hash constraint.",
369 $name;
370 }
371  
372 4 set_typed_hash($hash, $value);
373  
374 4 $value = $hash;
375 }
376  
377 6 return $value;
378 }
379  
380 sub set_typed_hash {
381 5 ▶ my ($hash, $value) = @_;
Subroutine set_typed_hash: called CC=5 SCAR=16.1
Pod undocumented
382  
383 5 for my $k (keys %{$value}) {
384 13 ▶ if (ref $hash->{$k} eq 'Hash::Typed') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash->{$k} eq 'Hash::Typed') { } 1 12 13
385 1 $hash->{$k} = set_typed_hash($hash->{$k}, $value->{$k});
386 } else {
387 12 $hash->{$k} = $value->{$k};
388 }
389 }
390
391 5 for my $k (keys %{ $hash }) {
392 14 ▶ if (! exists $value->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $value->{$k}) 1 13 14
393 1 delete $hash->{$k};
394 }
395 }
396
397 5 return $hash;
398 }
399  
400  
401 0 ▶sub build_hash { {} }
Subroutine build_hash: not called CC=1 SCAR=6.9
Pod undocumented
402  
403 sub hash {
404 15 ▶ my ($value, $name) = @_;
Subroutine hash: called CC=2 SCAR=7.6
Pod documented
405 15 ▶ if (ref $value ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value ne "HASH") 0 15 15
406 0 croak sprintf "The value passed to the %s attribute does not match the hash type constraint.",
407 $name;
408 }
409 15 return $value;
410 }
411  
412 0 ▶sub build_array { [] }
Subroutine build_array: not called CC=1 SCAR=6.9
Pod undocumented
413  
414 sub array {
415 7 ▶ my ($value, $name) = @_;
Subroutine array: called CC=2 SCAR=7.6
Pod documented
416 7 ▶ if (ref $value ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value ne "ARRAY") 0 7 7
417 0 croak sprintf "The value passed to the %s attribute does not match the array type constraint.",
418 $name;
419 }
420 7 return $value;
421 }
422  
423 sub fh {
424 0 ▶ my ($value, $name) = @_;
Subroutine fh: not called CC=2 SCAR=17.9
Pod documented
425 0 ▶ if (ref $value ne 'GLOB') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value ne "GLOB") 0 0 0
426 0 croak sprintf "The value passed to the %s attribute does not match the glob type constraint.",
427 $name;
428 }
429 0 return $value;
430 }
431  
432 0 ▶sub build_object { { } }
Subroutine build_object: not called CC=1 SCAR=6.9
Pod undocumented
433  
434 sub object {
435 0 ▶ my ($value, $name) = @_;
Subroutine object: not called CC=3 SCAR=24.8
Pod documented
436 0 ▶ if ( ! ref $value || ref $value !~ m/SCALAR|ARRAY|HASH|GLOB/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $value or ref !($value =~ /SCALAR|ARRAY|HASH|GLOB/)) 0 0 0
Condition0%0/3
not ref $value or ref !($value =~ /SCALAR|ARRAY|HASH|GLOB/)
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $value or ref !($value =~ /SCALAR|ARRAY|HASH|GLOB/)
not ref $value ref !($value =~ /SCALAR|ARRAY|HASH|GLOB/)
Truth table0%0/3
not(A) or not(B)
A= not ref $valueB= ref !($value =~ /SCALAR|ARRAY|HASH|GLOB/)
ABresult
1X1
011
000
437 0 croak sprintf "The value passed to the %s attribute does not match the object type constraint.",
438 $name;
439 }
440 0 return $value;
441 }
442  
443 sub deep_clone {
444 259 ▶ my ($data) = @_;
Subroutine deep_clone: called CC=5 SCAR=16.3
Pod undocumented
445 259 my $ref = ref $data;
446 259 ▶ if (!$ref) { return $data; }
Branch: 4 branches
BranchTrueFalseTotal
if (not $ref) { } 174 85 259
elsif ($ref eq 'SCALAR') { } 0 85 85
elsif ($ref eq 'ARRAY') { } 29 56 85
elsif ($ref eq 'HASH') { } 49 7 56
447 0 elsif ($ref eq 'SCALAR') { my $r = deep_clone($$data); return \$r; }
448 29 elsif ($ref eq 'ARRAY') { return [ map { deep_clone($_) } @{ $data } ]; }
449 49 elsif ($ref eq 'HASH') { return { map +( $_ => deep_clone($data->{$_}) ), keys %{ $data } }; }
450 7 return $data;
451 }
452  
453 sub deep_clone_ordered_hash {
454 14 ▶ my (@hash) = scalar @_ == 1 ? %{ $_[0] } : @_;
Subroutine deep_clone_ordered_hash: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 ? : 7 7 14
455 14 my %hash = ();
456 14 tie(%hash, 'Tie::IxHash');
457 14 ▶ while (@hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (@hash) 39 14 53
458 39 my ($key, $value) = (shift @hash, shift @hash);
459 39 $hash{$key} = deep_clone($value)
460 }
461 14 return \%hash;
462 }
463  
464 sub load {
465 4 ▶ my ($module) = shift;
Subroutine load: called CC=1 SCAR=0.0
Pod undocumented
466 4 $module =~ s/\:\:/\//g;
467 4 require $module . '.pm';
468 }
469  
470 7 1
471  
472 __END__
↑ Summary