Class/Accessor.pm

filter: Statementstmt 93.7% 317 / 338 Branchbran 82.7% 197 / 238 Conditioncond 62.6% 47 / 75 MC/DCmcdc 36.9% 17 / 46 Subroutinesub 94.4% 51 / 54 Podpod 100% 17 / 17 totaltotal 84.1% 646 / 768 CC 154 SCAR 21.2
CC
154
Cov
86%
__validate_type
22.0
dereference
18.2
__validate_obj_type
12.0
CRAP 8.4
« Class.pm ↑ Summary Class/Multiton.pm »
1 #!/usr/bin/perl
2 # $Id$
3 # $Author$
4 # $HeadURL$
5 # $Date$
6 # $Revision$
7 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 {
10  
11 package OOP::Perlish::Class::Accessor;
12 7 our $VERSION = 0.0100;
13 7 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶ use Scalar::Util qw(weaken blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶ use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶ use OOP::Perlish::Class::Abstract; # for implementation method exclusion
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 ##########************************************************************************##########
21 #!!!!!!!!! BEGIN Inherit constructor from OOP::Perlish::Class; and overload methods associated
22 #!!!!!!!!! with accessors (because we are accessors...)
23 ##########************************************************************************##########
24  
25 ############################################################################################
26 ## We override ____OOP_PERLISH_CLASS_REQUIRED_FIELDS, _accessors, ___inherit_accessors, and
27 ## ___OOP_PERLISH_CLASS__ACCESSORS below
28 ############################################################################################
29 7 ▶ use base 'OOP::Perlish::Class';
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 ############################################################################################
32 ## We must override __OOP_PERLISH_CLASS__REQUIRED_FIELDS because we will not initialize required fileds
33 ## via _accessors in the normal way
34 ############################################################################################
35 sub ____OOP_PERLISH_CLASS_REQUIRED_FIELDS
36 368 ▶ {
Subroutine ____OOP_PERLISH_CLASS_REQUIRED_FIELDS: called CC=1 SCAR=0.0
37 368 return ( [qw(name type)] );
38 }
39  
40 ############################################################################################
41 ## We are accessors, we cannot inherit them
42 ############################################################################################
43 sub ____inherit_accessors
44 92 ▶ {
Subroutine ____inherit_accessors: called CC=1 SCAR=0.0
45 92 return;
46 }
47  
48 ############################################################################################
49 ## We are accessors, we cannot have accessors.
50 ############################################################################################
51 sub ____OOP_PERLISH_CLASS_ACCESSORS
52 183 ▶ {
Subroutine ____OOP_PERLISH_CLASS_ACCESSORS: called CC=1 SCAR=0.0
53 183 return {};
54 }
55  
56 ############################################################################################
57 ## We are accessors, we cannot have accessors.
58 ############################################################################################
59 sub _accessors
60 0 ▶ {
Subroutine _accessors: not called CC=1 SCAR=6.9
61 0 return;
62 }
63  
64 ##########************************************************************************##########
65 #!!!!!!!!! END overloads/inheritance from OOP::Perlish::Class
66 ##########************************************************************************##########
67  
68 ############################################################################################
69 ## get/set the value stored in this accessor.
70 ############################################################################################
71 sub value
72 299 ▶ {
Subroutine value: called CC=5 SCAR=17.5
Pod documented
73 299 my ( $self, @values ) = @_;
74  
75 299 ▶ if( @values && ( $self->readonly() && $self->self()->{__initialized} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values and ($self->readonly and $self->self->{"__initialized"})) 0 299 299
Condition50%3/6
@values and ($self->readonly and $self->self->{"__initialized"})
!ll&&!rl&&r
1671320
$self->readonly and $self->self->{"__initialized"}
!ll&&!rl&&r
13200
MC/DC0%0/3
@values and ($self->readonly and $self->self->{"__initialized"})
@values $self->readonly $self->self->{"__initialized"}
Truth table50%2/4
A and B and C
A= @valuesB= $self->readonlyC= $self->self->{"__initialized"}
ABCresult
0XX0
10X0
1100
1111
76 0 carp( 'Cannot set ' . $self->name() . 'With ' . Dumper( \@values ) . 'Because it is readonly and we\'re already initialized' );
77 }
78  
79 299 ▶ if(@values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values) 132 167 299
80 132 $self->__set_value(@values);
81 }
82 299 return $self->__get_value();
83 }
84  
85 ############################################################################################
86 ## determine if a value (even undef) has been set on this accessor for a specific instance
87 ############################################################################################
88 sub is_set
89 397 ▶ {
Subroutine is_set: called CC=2 SCAR=6.9
Pod documented
90 397 my ($self) = @_;
91 397 ▶ return( (defined($self->self()->{___fields}->{ $self->name() }->{_Set})) ? $self->self()->{___fields}->{ $self->name() }->{_Set} : -1 );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->self->{'___fields'}{$self->name}{'_Set'} ? : 352 45 397
92 }
93  
94 ############################################################################################
95 ## get/set whether this should be treated as readonly after initialization
96 ############################################################################################
97 sub readonly
98 264 ▶ {
Subroutine readonly: called CC=4 SCAR=16.4
Pod documented
99 264 my ( $self, $readonly ) = @_;
100  
101 264 ▶ if( defined($readonly) && !exists( $self->{_readonly} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $readonly and not exists $self->{"_readonly"}) 0 264 264
Condition33%1/3
defined $readonly and not exists $self->{"_readonly"}
!ll&&!rl&&r
26400
MC/DC0%0/2
defined $readonly and not exists $self->{"_readonly"}
defined $readonly not exists $self->{"_readonly"}
Truth table33%1/3
A and not(B)
A= defined $readonlyB= not exists $self->{"_readonly"}
ABresult
0X0
100
111
102 0 $self->{_readonly} = $readonly;
103 }
104 264 ▶ $self->{_readonly} = undef unless( $self->{_readonly} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_readonly"} 264 0 264
105 264 return $self->{_readonly};
106 }
107  
108 ############################################################################################
109 ## get/set the type of the data stored in this
110 ############################################################################################
111 sub type
112 1831 ▶ {
Subroutine type: called CC=5 SCAR=16.4
Pod documented
113 1831 my ( $self, $type ) = @_;
114 1831 $type = uc($type);
115 1831 ▶ if($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 90 1741 1831
116 90 ▶ confess("Invalid type specified") unless( $self->__valid_type_lookup($type) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->__valid_type_lookup($type) 1 89 90
117  
118 89 ▶ if( !$self->{_Type} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_Type"}) 89 0 89
119 89 $self->{_Type} = $type;
120 89 $self->base_type($type);
121 }
122 }
123 1830 ▶ return $self->{_Type} if( defined( $self->{_Type} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_Type"} 1830 0 1830
124 0 return;
125 }
126  
127 ############################################################################################
128 ## get/set '$self' of this accessor to be used by ->validator() subroutines that need to see the class
129 ## for which we are an accessor of, rather than this accessor class itself.
130 ## In principal, this should only be set by the class which defines this accessor, but this is not enforced.
131 ############################################################################################
132 sub self
133 1968 ▶ {
Subroutine self: called CC=6 SCAR=19.9
Pod documented
134 1968 my ( $self, $class_self ) = @_;
135  
136 1968 ▶ if( defined $class_self ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $class_self) 315 1653 1968
137 315 ▶ confess('argument to ->self() is not a blessed reference') unless( ref($class_self) && blessed($class_self) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $class_self and builtin::blessed($class_self) 0 315 315
Condition33%1/3
ref $class_self and builtin::blessed($class_self)
!ll&&!rl&&r
00315
MC/DC0%0/2
ref $class_self and builtin::blessed($class_self)
ref $class_self builtin::blessed($class_self)
Truth table33%1/3
A and B
A= ref $class_selfB= builtin::blessed($class_self)
ABresult
0X0
100
111
138  
139 315 weaken($class_self); # weaken to avoid cyclic reference leaks
140 315 ▶ $self->{_class_self} = $class_self if( defined($class_self) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $class_self 315 0 315
141 }
142 1968 ▶ return $self->{_class_self} if( defined( $self->{_class_self} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_class_self"} 1968 0 1968
143 0 return;
144 }
145  
146 ############################################################################################
147 ## get/set the name of this accessor
148 ############################################################################################
149 sub name
150 1660 ▶ {
Subroutine name: called CC=3 SCAR=11.3
Pod documented
151 1660 my ( $self, $name ) = @_;
152  
153 1660 ▶ if( defined($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 89 1571 1660
154 89 $self->{_name} = $name;
155 }
156 1660 ▶ return $self->{_name} if( defined( $self->{_name} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_name"} 1660 0 1660
157 0 return;
158 }
159  
160 ############################################################################################
161 ## get/set whether this is a required attribute to the constructor
162 ############################################################################################
163 sub required
164 70 ▶ {
Subroutine required: called CC=3 SCAR=11.0
Pod documented
165 70 my ( $self, $required ) = @_;
166  
167 70 ▶ if( defined($required) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $required) 8 62 70
168 8 $self->{_required} = $required;
169 }
170 70 ▶ return $self->{_required} if( defined( $self->{_required} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_required"} 25 45 70
171 45 return;
172 }
173  
174 ############################################################################################
175 ## get/set the default value
176 ############################################################################################
177 sub default ## no critic (ProhibitBuiltinHomonyms)
178 30 ▶ {
Subroutine default: called CC=6 SCAR=19.7
Pod documented
179 30 my ( $self, @values ) = @_;
180  
181 30 ▶ if( @values && !$self->default_is_set() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values and not $self->default_is_set) 10 20 30
Condition100%3/3
@values and not $self->default_is_set
!ll&&!rl&&r
101010
MC/DC100%2/2
@values and not $self->default_is_set
@values not $self->default_is_set
Truth table100%3/3
A and not(B)
A= @valuesB= not $self->default_is_set
ABresult
0X0
100
111
182 10 $self->{_default_is_set} = 1;
183 10 ▶ if( !defined( $values[0] ) && scalar @values == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $values[0] and scalar @values == 1) 0 10 10
Condition33%1/3
not defined $values[0] and scalar @values == 1
!ll&&!rl&&r
1000
MC/DC0%0/2
not defined $values[0] and scalar @values == 1
not defined $values[0] scalar @values == 1
Truth table33%1/3
not(A) and B
A= not defined $values[0]B= scalar @values == 1
ABresult
0X0
100
111
184 0 $self->{_default} = undef;
185 0 return;
186 }
187 10 ( $self->{_default} ) = $self->reference( $self->__dereference_always(@values) );
188 }
189 30 ▶ if( defined( $self->{_default} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_default"}) 30 0 30
190 30 return $self->dereference( $self->{_default} );
191 }
192  
193 0 return;
194 }
195  
196 ############################################################################################
197 ## Specify whether we will permit direct mutation of this reference
198 ############################################################################################
199 sub mutable
200 62 ▶ {
Subroutine mutable: called CC=3 SCAR=11.0
Pod documented
201 62 my ($self, $mutable) = @_;
202  
203 62 ▶ if(defined($mutable)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mutable) 2 60 62
204 2 $self->{_mutable} = $mutable;
205 }
206  
207 62 ▶ if(defined($self->{_mutable})) { # && $self->type() && $self->type() =~ m/REF/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_mutable"}) 8 54 62
208 8 return $self->{_mutable};
209 }
210 54 return 0;
211 }
212  
213 ############################################################################################
214 ## Check if default value has been set
215 ############################################################################################
216 sub default_is_set
217 52 ▶ {
Subroutine default_is_set: called CC=1 SCAR=0.0
Pod documented
218 52 my ($self) = @_;
219  
220 52 return $self->{_default_is_set};
221 }
222  
223 ############################################################################################
224 ## get the basetype of either the type of this object, or the type passed as an argument
225 ############################################################################################
226 sub base_type
227 274 ▶ {
Subroutine base_type: called CC=3 SCAR=11.4
Pod documented
228 274 my ( $self, $type ) = @_;
229 274 ▶ $type ||= $self->type();
Condition66%2/3
$type ||= $self->type
l!l&&r!l&&!r
891850
MC/DC0%0/2
$type ||= $self->type
$type $self->type
Truth table66%2/3
A ||= B
A= $typeB= $self->type
ABresult
1X1
011
000
230  
231 274 ▶ return $self->__valid_type_lookup($type) if( $self->__valid_type_lookup($type) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->__valid_type_lookup($type) 274 0 274
232 }
233  
234 ############################################################################################
235 ## based on the type, and basetype of this object, dereferences (if necessary) the data
236 ## so that the requester obtains what they expect.
237 ############################################################################################
238 sub dereference
239 292 ▶ {
Subroutine dereference: called CC=18 SCAR=29.0
Pod documented
240 292 my ( $self, $ref ) = @_;
241  
242 292 for( $self->type() ) {
243 292 ▶ /REF/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/REF/i and do { unless ($self->mutable) { /HASH/ and ref $ref eq "HASH" and do { my(%tmp) = %{$ref;}; return \%tmp }; /ARRAY/ and ref $ref eq "ARRAY" and do { my(@tmp) = @{$ref;}; return \@tmp }; /SCALAR/ and ref $ref eq "SCALAR" and do { my $tmp = ${$ref;}; return \$tmp }; } ; return $ref } 60 232 292
244 ## Re-reference with temporary storage to protect encapsulation unless defined as mutable
245 60 ▶ if(! $self->mutable()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->mutable) 54 6 60
246 54 ▶ /HASH/ && ref($ref) eq 'HASH' && do {
Branch: 1 branch
BranchTrueFalseTotal
/HASH/ and ref $ref eq "HASH" and do { my(%tmp) = %{$ref;}; return \%tmp } 18 36 54
Condition66%2/3
/HASH/ and ref $ref eq "HASH"
!ll&&!rl&&r
36018
MC/DC50%1/2
/HASH/ and ref $ref eq "HASH"
/HASH/ ref $ref eq "HASH"
Truth table66%2/3
A and B
A= /HASH/B= ref $ref eq "HASH"
ABresult
0X0
100
111
247 18 my %tmp = ( %{ $ref } );
248 18 return \%tmp;
249 };
250 36 ▶ /ARRAY/ && ref($ref) eq 'ARRAY' && do {
Branch: 1 branch
BranchTrueFalseTotal
/ARRAY/ and ref $ref eq "ARRAY" and do { my(@tmp) = @{$ref;}; return \@tmp } 15 21 36
Condition66%2/3
/ARRAY/ and ref $ref eq "ARRAY"
!ll&&!rl&&r
21015
MC/DC50%1/2
/ARRAY/ and ref $ref eq "ARRAY"
/ARRAY/ ref $ref eq "ARRAY"
Truth table66%2/3
A and B
A= /ARRAY/B= ref $ref eq "ARRAY"
ABresult
0X0
100
111
251 15 my @tmp = ( @{ $ref } );
252 15 return \@tmp;
253 };
254 21 ▶ /SCALAR/ && ref($ref) eq 'SCALAR' && do {
Branch: 1 branch
BranchTrueFalseTotal
/SCALAR/ and ref $ref eq "SCALAR" and do { my $tmp = ${$ref;}; return \$tmp } 15 6 21
Condition66%2/3
/SCALAR/ and ref $ref eq "SCALAR"
!ll&&!rl&&r
6015
MC/DC50%1/2
/SCALAR/ and ref $ref eq "SCALAR"
/SCALAR/ ref $ref eq "SCALAR"
Truth table66%2/3
A and B
A= /SCALAR/B= ref $ref eq "SCALAR"
ABresult
0X0
100
111
255 15 my $tmp = ${$ref};
256 15 return \$tmp;
257 };
258 }
259 12 return $ref;
260 };
261 232 ▶ /CODE/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/CODE/i and do { return $ref } 17 215 232
262 17 return $ref;
263 };
264 215 ▶ /OBJECT/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/OBJECT/ and do { return $ref } 21 194 215
265 21 return $ref;
266 };
267 194 ▶ /HASH/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/HASH/ and do { return %{$ref;} if ref $ref eq "HASH" } 28 166 194
268 28 ▶ return %{$ref} if( ref($ref) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref eq "HASH" 28 0 28
269 };
270 166 ▶ /ARRAY/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/ARRAY/ and do { return @{$ref;} if ref $ref eq "ARRAY" } 28 138 166
271 28 ▶ return @{$ref} if( ref($ref) eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref eq "ARRAY" 28 0 28
272 };
273 138 ▶ /SCALAR/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/SCALAR/ and do { return ${$ref;} if ref $ref eq "SCALAR" } 128 10 138
274 128 ▶ return ${$ref} if( ref($ref) eq 'SCALAR' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref eq "SCALAR" 128 0 128
275 };
276 }
277 10 return $ref;
278 }
279  
280 ############################################################################################
281 ## based on the basetype and type of this object, created a reference to it for insertion into $self
282 ############################################################################################
283 sub reference
284 183 ▶ {
Subroutine reference: called CC=10 SCAR=23.1
Pod documented
285 183 my ( $self, @stuff ) = @_;
286  
287 183 for( $self->type() ) {
288 183 ▶ /^REF/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^REF/ and do { return $stuff[0] } 8 175 183
289 8 return $stuff[0];
290 };
291 175 ▶ /CODE/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/CODE/i and do { return $stuff[0] } 6 169 175
292 6 return $stuff[0];
293 };
294 169 ▶ /GLOB/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/GLOB/ and do { return $stuff[0] } 4 165 169
295 4 return $stuff[0];
296 };
297 165 ▶ /REGEXP/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/REGEXP/i and do { return $stuff[0] } 3 162 165
298 3 return $stuff[0];
299 };
300 162 ▶ /OBJECT/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/OBJECT/ and do { return $stuff[0] } 17 145 162
301 17 return $stuff[0];
302 };
303 145 ▶ /HASH/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/HASH/ and do { return {@stuff} } 32 113 145
304 32 return { (@stuff) };
305 };
306 113 ▶ /ARRAY/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/ARRAY/ and do { return \@stuff } 26 87 113
307 26 return \@stuff;
308 };
309 87 ▶ /SCALAR/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/SCALAR/ and do { return \$stuff[0] } 87 0 87
310 87 return \$stuff[0];
311 };
312 }
313 0 return; @stuff;
314 }
315  
316 ############################################################################################
317 ## set/get the validator sub-routine used for set operations of this accessor
318 ############################################################################################
319 sub validator
320 465 ▶ {
Subroutine validator: called CC=6 SCAR=18.5
Pod documented
321 465 my ( $self, $validator ) = @_;
322  
323 465 ▶ if( $validator && ref($validator) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($validator and ref $validator) { } 47 418 465
Condition66%2/3
$validator and ref $validator
!ll&&!rl&&r
418047
MC/DC50%1/2
$validator and ref $validator
$validator ref $validator
Truth table66%2/3
A and B
A= $validatorB= ref $validator
ABresult
0X0
100
111
324 47 for( ref($validator) ) {
325 47 ▶ /CODE/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/CODE/i and do { return $self->{"_Validator"} = $validator } 11 36 47
326 11 return ( $self->{_Validator} = $validator );
327 };
328 36 ▶ /REGEXP/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/REGEXP/i and do { return $self->{"_Validator"} = $self->__regexp_sub_factory($validator) } 36 0 36
329 36 return ( $self->{_Validator} = $self->__regexp_sub_factory($validator) );
330 };
331 }
332 0 ▶ return ( $self->{_Validator} = sub {return} );
Subroutine __ANON__: not called CC=1 SCAR=6.9
333 }
334 else {
335 418 return $self->{_Validator};
336 }
337 }
338  
339 ############################################################################################
340 ## get/set the classes an object must "is-a" to be valid as a value for this accessor
341 ############################################################################################
342 sub object_isa
343 55 ▶ {
Subroutine object_isa: called CC=4 SCAR=13.9
Pod documented
344 55 my ( $self, $classes ) = @_;
345  
346 55 ▶ if($classes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($classes) 2 53 55
347 2 ▶ $classes = [$classes] unless( ref($classes) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $classes 0 2 2
348 2 $self->{_Object_Classes} = [ @{$classes} ];
349 }
350 55 ▶ return @{ $self->{_Object_Classes} } if( defined( $self->{_Object_Classes} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_Object_Classes"} 14 41 55
351 }
352  
353 ############################################################################################
354 ## get/set the methods an object must "can" to be valid as a value for this accessor
355 ############################################################################################
356 sub object_can
357 60 ▶ {
Subroutine object_can: called CC=4 SCAR=13.9
Pod documented
358 60 my ( $self, $interfaces ) = @_;
359  
360 60 ▶ if($interfaces) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interfaces) 6 54 60
361 6 ▶ $interfaces = [$interfaces] unless( ref($interfaces) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $interfaces 0 6 6
362 6 $self->{_Object_Interfaces} = [ @{$interfaces} ];
363 }
364 60 ▶ return @{ $self->{_Object_Interfaces} } if( defined( $self->{_Object_Interfaces} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_Object_Interfaces"} 24 36 60
365 }
366  
367 ############################################################################################
368 ## get/set the classes (packages) that an object must be like
369 ############################################################################################
370 sub implements
371 58 ▶ {
Subroutine implements: called CC=4 SCAR=13.9
Pod documented
372 58 my ( $self, $classes ) = @_;
373  
374 58 ▶ if($classes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($classes) 4 54 58
375 4 ▶ $classes = [$classes] unless( ref($classes) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $classes 0 4 4
376 4 $self->{_Object_Implements} = [ @{$classes} ];
377 }
378 58 ▶ return @{ $self->{_Object_Implements} } if( defined( $self->{_Object_Implements} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_Object_Implements"} 28 30 58
379 }
380  
381 ##########************************************************************************##########
382 #!!!!!!!!! Internal foo
383 ##########************************************************************************##########
384  
385 ############################################################################################
386 ## Lookup a type and determin if its a) valid, and b) if it has a basetype
387 ############################################################################################
388 sub __valid_type_lookup
389 638 ▶ {
Subroutine __valid_type_lookup: called CC=3 SCAR=11.0
390 638 my ( $self, $type ) = @_;
391  
392 638 my %valid_types_map = (
393 SCALAR => 'SCALARREF',
394 ARRAY => 'ARRAYREF',
395 HASH => 'HASHREF',
396 CODE => 'CODEREF',
397 REF => 'REF',
398 GLOB => 'GLOBREF',
399 OBJECT => 'OBJECT',
400 Regexp => 'REGEXP',
401 # TODO: CLASS => 'CLASS',
402 );
403 638 my %valid_types_lut = reverse %valid_types_map;
404  
405 638 ▶ if( exists( $valid_types_map{$type} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $valid_types_map{$type}) { } 409 229 638
elsif (exists $valid_types_lut{$type}) { } 228 1 229
406 409 return $type;
407 }
408 elsif( exists( $valid_types_lut{$type} ) ) {
409 228 return $valid_types_lut{$type};
410 }
411 else {
412 1 return;
413 }
414 }
415  
416 ############################################################################################
417 ## Verify that a value specified as a default is valid for the accessor; this allows post-validation in object instantiation
418 ############################################################################################
419 sub __validate_default
420 59 ▶ {
Subroutine __validate_default: called CC=5 SCAR=16.2
421 59 my ($self) = @_;
422  
423 59 ▶ return unless( exists( $self->{_default} ) && $self->default_is_set() );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_default"} and $self->default_is_set 49 10 59
Condition66%2/3
exists $self->{"_default"} and $self->default_is_set
!ll&&!rl&&r
49010
MC/DC50%1/2
exists $self->{"_default"} and $self->default_is_set
exists $self->{"_default"} $self->default_is_set
Truth table66%2/3
A and B
A= exists $self->{"_default"}B= $self->default_is_set
ABresult
0X0
100
111
424  
425 10 my @orig_values = $self->__dereference_always( $self->{_default} );
426 10 my @valid_values = $self->__validate( $self->{_default} );
427  
428 10 ▶ if( !@valid_values ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@valid_values) 5 5 10
429 5 ▶ confess( 'Invalid default value ' . ( (@orig_values) ? Dumper( \@orig_values ) : '`undef\'' ) . ' for field ' . $self->name() );
Branch: 1 branch
BranchTrueFalseTotal
@orig_values ? : 5 0 5
430 }
431  
432 5 $self->{_default} = $self->reference(@valid_values);
433 5 return;
434 }
435  
436 ############################################################################################
437 ## Jump through requisite hoops to set a value; marking _Set appropriately for is_set method
438 ############################################################################################
439 sub __set_value
440 132 ▶ {
Subroutine __set_value: called CC=7 SCAR=23.6
441 132 my ( $self, @values ) = @_;
442  
443 132 ▶ if( @values && !( $self->readonly() && $self->self()->{__initialized} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values and not $self->readonly && $self->self->{"__initialized"}) 132 0 132
Condition33%2/6
@values and not $self->readonly && $self->self->{"__initialized"}
!ll&&!rl&&r
00132
$self->readonly && $self->self->{'__initialized'}
!ll&&!rl&&r
13200
MC/DC0%0/3
@values and not $self->readonly && $self->self->{"__initialized"}
@values $self->readonly $self->self->{'__initialized'}
Truth table25%1/4
A and not(B && C)
A= @valuesB= $self->readonlyC= $self->self->{'__initialized'}
ABCresult
0XX0
1110
10X1
1101
444 ## Handle explicit setting to undef; bypass validation, bypass everything.
445 132 $self->self()->{___fields}->{ $self->name() }->{_Set} = 1;
446 132 ▶ if( !defined( $values[0] ) && scalar @values == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $values[0] and scalar @values == 1) 0 132 132
Condition33%1/3
not defined $values[0] and scalar @values == 1
!ll&&!rl&&r
13200
MC/DC0%0/2
not defined $values[0] and scalar @values == 1
not defined $values[0] scalar @values == 1
Truth table33%1/3
not(A) and B
A= not defined $values[0]B= scalar @values == 1
ABresult
0X0
100
111
447 0 $self->self()->{___fields}->{ $self->name() }->{_Value} = undef;
448 0 return;
449 }
450 132 ▶ $self->self()->{___fields}->{ $self->name() }->{_Set} = 0 unless($self->__validate(@values));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->__validate(@values) 30 102 132
451 132 $self->self()->{___fields}->{ $self->name() }->{_Value} = $self->reference( $self->__validate(@values) );
452 }
453 132 return;
454 }
455  
456 ############################################################################################
457 ## return empty references if our type is a *REF
458 ############################################################################################
459 sub __appropriate_undef_value
460 77 ▶ {
Subroutine __appropriate_undef_value: called CC=3 SCAR=11.0
461 77 my ($self) = @_;
462 77 ▶ if($self->type() =~ m/REF/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->type =~ /REF/) { } 36 41 77
elsif ($self->type eq 'SCALAR') { } 9 32 41
463 36 return $self->reference();
464 }
465 elsif($self->type() eq 'SCALAR') {
466 9 return undef;
467 }
468 else {
469 32 return( () );
470 }
471 }
472
473  
474 ############################################################################################
475 ## Jump through requisite hoops to obtain a value; either set or default
476 ############################################################################################
477 sub __get_value
478 299 ▶ {
Subroutine __get_value: called CC=8 SCAR=21.8
479 299 my ($self) = @_;
480  
481 299 ▶ if($self->is_set() == 1 ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->is_set == 1) { } 217 82 299
elsif ($self->is_set == 0) { } 67 15 82
elsif ($self->is_set == -1 and not $self->default_is_set) { } 10 5 15
elsif ($self->default_is_set) { } 5 0 5
482 217 ▶ if( ! defined( $self->self()->{___fields}->{ $self->name() }->{_Value} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->self->{'___fields'}{$self->name}{'_Value'}) { } 0 217 217
483 0 return $self->__appropriate_undef_value();
484 } else {
485 217 return $self->dereference( $self->self()->{___fields}->{ $self->name() }->{_Value} );
486 }
487 }
488 elsif( $self->is_set() == 0 ) {
489 67 return $self->__appropriate_undef_value();
490 }
491 ▶ elsif( $self->is_set() == -1 && ! $self->default_is_set() ) {
Condition66%2/3
$self->is_set == -1 and not $self->default_is_set
!ll&&!rl&&r
0510
MC/DC50%1/2
$self->is_set == -1 and not $self->default_is_set
$self->is_set == -1 not $self->default_is_set
Truth table66%2/3
A and not(B)
A= $self->is_set == -1B= not $self->default_is_set
ABresult
0X0
100
111
492 10 return $self->__appropriate_undef_value();
493 }
494 elsif( $self->default_is_set() ) {
495 5 ▶ return $self->__appropriate_undef_value() unless(defined( $self->default() ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->default 0 5 5
496 5 return $self->default();
497 }
498 0 return $self->reference();
499 }
500  
501  
502 ############################################################################################
503 ## Perform the extra validation required of objects (polymorphism/inheritance)
504 ############################################################################################
505 sub __validate_obj_type
506 49 ▶ {
Subroutine __validate_obj_type: called CC=12 SCAR=24.9
507 49 my ( $self, $thing ) = @_;
508  
509 49 ▶ return unless( ref($thing) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $thing 2 47 49
510 47 ▶ return unless( blessed($thing) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($thing) 0 47 47
511  
512 47 ▶ if( $self->object_isa() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->object_isa) 6 41 47
513 6 for my $class ( $self->object_isa() ) {
514 6 ▶ return unless( $thing->isa($class) );
Branch: 1 branch
BranchTrueFalseTotal
unless $thing->isa($class) 2 4 6
515 }
516 }
517 45 ▶ if( $self->object_can() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->object_can) 9 36 45
518 9 for my $method ( $self->object_can() ) {
519 17 ▶ return unless( $thing->can($method) );
Branch: 1 branch
BranchTrueFalseTotal
unless $thing->can($method) 3 14 17
520 }
521 }
522 42 ▶ if( $self->implements() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->implements) 12 30 42
523 12 for my $class ( $self->implements() ) {
524 12 ▶ return unless( $self->__validate_class_implementation( $class, $thing ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->__validate_class_implementation($class, $thing) 4 8 12
525 }
526 }
527 38 return 1;
528 }
529  
530 ############################################################################################
531 ## Verify that a class implements interfaces (excluding interfaces from OOP::Perlish::Class itself)
532 ############################################################################################
533 sub __validate_class_implementation
534 12 ▶ {
Subroutine __validate_class_implementation: called CC=7 SCAR=19.8
535 12 my ( $self, $class, $thing ) = @_;
536  
537 12 my @interfaces;
538  
539 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
540 12 ▶ if( scalar keys %{ '::' . $class . '::' } == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{'::' . $class . '::';} == 0) 0 12 12
541 0 eval "require $class";
542 0 ▶ confess("$@") if("$@");
Branch: 1 branch
BranchTrueFalseTotal
if "$@" 0 0 0
543 }
544 7 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
545  
546 ### XXX: Hash slice assignment for lookup
547 12 my %oop_perlish_class_interfaces;
548 12 @oop_perlish_class_interfaces{ OOP::Perlish::Class::Abstract->new()->_all_methods() } = undef;
549  
550 12 my $class_ref = bless( {}, $class );
551  
552 12 ▶ if( $class_ref->can('_all_methods') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_ref->can('_all_methods')) { } 6 6 12
553 6 @interfaces = grep { ! exists( $oop_perlish_class_interfaces{$_} ) } $class_ref->_all_methods();
554 }
555 else {
556 6 @interfaces = grep { ! exists( $oop_perlish_class_interfaces{$_} ) } $self->_all_methods($class);
557 }
558 12 ▶ confess("No interfaces from $class") unless(@interfaces);
Branch: 1 branch
BranchTrueFalseTotal
unless @interfaces 0 12 12
559  
560 12 for my $method (@interfaces) {
561 276 ▶ return unless( $thing->can($method) );
Branch: 1 branch
BranchTrueFalseTotal
unless $thing->can($method) 4 272 276
562 }
563 8 return 1;
564 }
565  
566 ############################################################################################
567 ## Verify that the underlying type of a reference is correct for the type of this accessor
568 ############################################################################################
569 sub __validate_ref_type
570 102 ▶ {
Subroutine __validate_ref_type: called CC=4 SCAR=13.9
571 102 my ( $self, $thing ) = @_;
572  
573 102 ▶ if( $self->type() eq 'OBJECT' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type eq 'OBJECT') { } 49 53 102
574 49 ▶ return unless( $self->__validate_obj_type($thing) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->__validate_obj_type($thing) 11 38 49
575 }
576 else {
577 53 ▶ return unless( ref($thing) eq $self->base_type() );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $thing eq $self->base_type 15 38 53
578 }
579 76 return 1;
580 }
581  
582 ############################################################################################
583 ## Validate that the type of the thing passed to this object is a valid type for our storage.
584 ############################################################################################
585 sub __validate_type
586 274 ▶ {
Subroutine __validate_type: called CC=21 SCAR=30.9
587 274 my ( $self, @values ) = @_;
588  
589 ## Don't validate_ref_type for REF type (backwards sounding I know; but if we are a REF type, we don't care about the underlying _type_)
590 ## We also cannot fail an array, unfortunately, because it could be an array containing one member, a reference to something...
591 274 ▶ if( ( ref( $values[0] ) && scalar(@values) == 1 ) && $self->type() !~ m/(?:^REF|ARRAY)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $values[0] and scalar @values == 1 and not $self->type =~ /(?:^REF|ARRAY)/) 63 211 274
Condition83%5/6
ref $values[0] and scalar @values == 1 and not $self->type =~ /(?:^REF|ARRAY)/
!ll&&!rl&&r
1912063
ref $values[0] and scalar @values == 1
!ll&&!rl&&r
191083
MC/DC66%2/3
ref $values[0] and scalar @values == 1 and not $self->type =~ /(?:^REF|ARRAY)/
ref $values[0] scalar @values == 1 not $self->type =~ /(?:^REF|ARRAY)/
Truth table75%3/4
A and B and not(C)
A= ref $values[0]B= scalar @values == 1C= not $self->type =~ /(?:^REF|ARRAY)/
ABCresult
0XX0
10X0
1100
1111
592 63 ▶ return unless( $self->__validate_ref_type( $values[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->__validate_ref_type($values[0]) 17 46 63
593 }
594  
595 257 ▶ if( $self->type() =~ m/REF|CODE|REGEXP|OBJECT/ && $self->type() !~ m/(?:^REF|SCALAR|ARRAY|HASH)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type =~ /REF|CODE|REGEXP|OBJECT/ and not $self->type =~ /(?:^REF|SCALAR|ARRAY|HASH)/) 39 218 257
Condition100%3/3
$self->type =~ /REF|CODE|REGEXP|OBJECT/ and not $self->type =~ /(?:^REF|SCALAR|ARRAY|HASH)/
!ll&&!rl&&r
1546439
MC/DC100%2/2
$self->type =~ /REF|CODE|REGEXP|OBJECT/ and not $self->type =~ /(?:^REF|SCALAR|ARRAY|HASH)/
$self->type =~ /REF|CODE|REGEXP|OBJECT/ not $self->type =~ /(?:^REF|SCALAR|ARRAY|HASH)/
Truth table100%3/3
A and not(B)
A= $self->type =~ /REF|CODE|REGEXP|OBJECT/B= not $self->type =~ /(?:^REF|SCALAR|ARRAY|HASH)/
ABresult
0X0
100
111
596 39 ▶ return unless( $self->__validate_ref_type( $values[0] ) && scalar(@values) == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->__validate_ref_type($values[0]) and scalar @values == 1 9 30 39
Condition66%2/3
$self->__validate_ref_type($values[0]) and scalar @values == 1
!ll&&!rl&&r
9030
MC/DC50%1/2
$self->__validate_ref_type($values[0]) and scalar @values == 1
$self->__validate_ref_type($values[0]) scalar @values == 1
Truth table66%2/3
A and B
A= $self->__validate_ref_type($values[0])B= scalar @values == 1
ABresult
0X0
100
111
597 }
598  
599 248 for( $self->type() ) {
600 248 ▶ /^REF/ && do { return unless( scalar @values == 1 && ref( $values[0] ) ); };
Branch: 2 branches
BranchTrueFalseTotal
/^REF/ and do { return unless scalar @values == 1 and ref $values[0] } 8 240 248
unless scalar @values == 1 and ref $values[0] 2 6 8
Condition66%2/3
scalar @values == 1 and ref $values[0]
!ll&&!rl&&r
206
MC/DC50%1/2
scalar @values == 1 and ref $values[0]
scalar @values == 1 ref $values[0]
Truth table66%2/3
A and B
A= scalar @values == 1B= ref $values[0]
ABresult
0X0
100
111
601 246 ▶ /HASH/ && do { return unless( scalar @values % 2 == 0 || ref( $values[0] ) eq 'HASH' ); };
Branch: 2 branches
BranchTrueFalseTotal
/HASH/ and do { return unless scalar @values % 2 == 0 or ref $values[0] eq "HASH" } 34 212 246
unless scalar @values % 2 == 0 or ref $values[0] eq "HASH" 0 34 34
Condition66%2/3
scalar @values % 2 == 0 or ref $values[0] eq "HASH"
l!l&&r!l&&!r
24100
MC/DC0%0/2
scalar @values % 2 == 0 or ref $values[0] eq "HASH"
scalar @values % 2 == 0 ref $values[0] eq "HASH"
Truth table66%2/3
A or B
A= scalar @values % 2 == 0B= ref $values[0] eq "HASH"
ABresult
1X1
011
000
602 246 ▶ /SCALAR/ && do { return unless( scalar @values == 1 ); };
Branch: 2 branches
BranchTrueFalseTotal
/SCALAR/ and do { return unless scalar @values == 1 } 138 108 246
unless scalar @values == 1 4 134 138
603 242 ▶ /GLOB/ && do { return unless( scalar @values == 1 && ref( $values[0] ) eq 'GLOB' ) };
Branch: 2 branches
BranchTrueFalseTotal
/GLOB/ and do { return unless scalar @values == 1 and ref $values[0] eq "GLOB" } 2 240 242
unless scalar @values == 1 and ref $values[0] eq "GLOB" 0 2 2
Condition33%1/3
scalar @values == 1 and ref $values[0] eq "GLOB"
!ll&&!rl&&r
002
MC/DC0%0/2
scalar @values == 1 and ref $values[0] eq "GLOB"
scalar @values == 1 ref $values[0] eq "GLOB"
Truth table33%1/3
A and B
A= scalar @values == 1B= ref $values[0] eq "GLOB"
ABresult
0X0
100
111
604 }
605  
606 242 return 1;
607 }
608  
609 ############################################################################################
610 ## Test the validity of data using the validator of this accessor
611 ############################################################################################
612 sub __validate
613 274 ▶ {
Subroutine __validate: called CC=4 SCAR=13.9
614 274 my ( $self, @values ) = @_;
615  
616 274 ▶ return unless(@values);
Branch: 1 branch
BranchTrueFalseTotal
unless @values 0 274 274
617 274 ▶ return unless( $self->__validate_type(@values) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->__validate_type(@values) 32 242 274
618  
619 242 ▶ if( defined( $self->validator() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->validator) { } 176 66 242
620 176 return $self->validator()->( $self->self(), $self->__dereference_always(@values) );
621 }
622 else {
623 66 return $self->__dereference_always(@values);
624 }
625 }
626  
627 ############################################################################################
628 ## This will indescriminately dereference a type to its base type; it is used because it simplifies validation
629 ############################################################################################
630 sub __dereference_always
631 262 ▶ {
Subroutine __dereference_always: called CC=4 SCAR=13.9
632 262 my ( $self, @input ) = @_;
633  
634 262 my @values = ();
635  
636 262 ▶ if( scalar @input == 1 && ref( $input[0] ) && ref( $input[0] ) eq $self->base_type() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @input == 1 and ref $input[0] and ref $input[0] eq $self->base_type) { } 45 217 262
Condition100%6/6
scalar @input == 1 and ref $input[0] and ref $input[0] eq $self->base_type
!ll&&!rl&&r
1803745
scalar @input == 1 and ref $input[0]
!ll&&!rl&&r
4413682
MC/DC100%3/3
scalar @input == 1 and ref $input[0] and ref $input[0] eq $self->base_type
scalar @input == 1 ref $input[0] ref $input[0] eq $self->base_type
Truth table100%4/4
A and B and C
A= scalar @input == 1B= ref $input[0]C= ref $input[0] eq $self->base_type
ABCresult
0XX0
10X0
1100
1111
637 45 my $tmp_type = $self->type();
638 45 my $buf_type = $self->base_type();
639  
640 45 $self->{_Type} = $buf_type;
641 45 @values = $self->dereference( $input[0] );
642 45 $self->{_Type} = $tmp_type;
643 }
644 else {
645 217 @values = @input;
646 }
647 262 return @values;
648 }
649  
650 ############################################################################################
651 ## Return a subroutine which will correctly validate via regexp the data of the specified type.
652 ############################################################################################
653 sub __regexp_sub_factory
654 36 ▶ {
Subroutine __regexp_sub_factory: called CC=3 SCAR=11.3
655 36 my ( $self, $regexp ) = @_;
656  
657 36 my $possible_method;
658 36 $possible_method = '__regexp_sub_impl_' . lc( $self->type() );
659  
660 36 ▶ if( $self->can($possible_method) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($possible_method)) 31 5 36
661 31 return $self->$possible_method($regexp);
662 }
663  
664 5 $possible_method = '__regexp_sub_impl_' . lc( $self->base_type() );
665 5 ▶ if( $self->can($possible_method) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($possible_method)) 5 0 5
666 5 return $self->$possible_method($regexp);
667 }
668 0 ▶ return sub {return};
Subroutine __ANON__: not called CC=1 SCAR=6.9
669 }
670  
671 ############################################################################################
672 ## "free" regexp subroutine for hashes
673 ############################################################################################
674 sub __regexp_sub_impl_hash
675 8 ▶ {
Subroutine __regexp_sub_impl_hash: called CC=1 SCAR=0.0
676 8 my ( $self, $regexp ) = @_;
677  
678 14 ▶ return sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
679 14 my ( $this, %args ) = @_;
680  
681 14 my $re = $regexp;
682 14 my %valid_args = ();
683 14 ▶ return unless( keys %args );
Branch: 1 branch
BranchTrueFalseTotal
unless keys %args 0 14 14
684 14 ▶ while( my ( $key, $val ) = each %args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 34 14 48
685 34 ▶ $val =~ /($re)/ && do {
Branch: 1 branch
BranchTrueFalseTotal
$val =~ /($re)/ and do { $valid_args{$key} = $1 } 21 13 34
686 21 $valid_args{$key} = $1;
687 }
688 }
689 14 ▶ return %valid_args if( scalar keys %args == scalar keys %valid_args );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %args == scalar keys %valid_args 9 5 14
690 5 return;
691 8 };
692 }
693  
694 ############################################################################################
695 ## "free" regexp subroutine for arrays
696 ############################################################################################
697 sub __regexp_sub_impl_array
698 6 ▶ {
Subroutine __regexp_sub_impl_array: called CC=1 SCAR=0.0
699 6 my ( $self, $regexp ) = @_;
700  
701 10 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
702 10 my ( $this, @args ) = @_;
703  
704 10 my $re = $regexp;
705 10 my @valid_args = ();
706 10 ▶ return unless(@args);
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 10 10
707 10 for(@args) {
708 30 ▶ return unless( defined($_) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 30 30
709 30 ▶ /($re)/x && do {
Branch: 1 branch
BranchTrueFalseTotal
/($re)/x and do { push @valid_args, $1 } 17 13 30
710 17 push @valid_args, $1;
711 };
712 }
713 10 ▶ return @valid_args if( scalar @args == scalar @valid_args );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @args == scalar @valid_args 5 5 10
714 5 return;
715 6 };
716 }
717  
718 ############################################################################################
719 ## "free" regexp subroutine for scalar
720 ############################################################################################
721 sub __regexp_sub_impl_scalar
722 20 ▶ {
Subroutine __regexp_sub_impl_scalar: called CC=1 SCAR=0.0
723 20 my ( $self, $regexp ) = @_;
724  
725 96 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
726 96 my ( $this, $arg ) = @_;
727 96 my $re = $regexp;
728 96 my $valid_arg = undef;
729  
730 96 ▶ return unless( defined($arg) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 0 96 96
731 96 ▶ $arg =~ m/($re)/ && do {
Branch: 1 branch
BranchTrueFalseTotal
$arg =~ /($re)/ and do { $valid_arg = $1; return unless defined $valid_arg; return $valid_arg } 91 5 96
732 91 $valid_arg = $1;
733 91 ▶ return unless( defined($valid_arg) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $valid_arg 0 91 91
734 91 return $valid_arg;
735 };
736 5 return;
737 20 };
738 }
739  
740 ############################################################################################
741 ## "free" regexp subroutine for objects (uses ref for string representation)
742 ############################################################################################
743 sub __regexp_sub_impl_object
744 2 ▶ {
Subroutine __regexp_sub_impl_object: called CC=1 SCAR=0.0
745 2 my ( $self, $regexp ) = @_;
746  
747 4 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
748 4 my ( $this, $obj ) = @_;
749  
750 4 ▶ return unless( defined $obj );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj 0 4 4
751 4 ▶ return $obj if( ref($obj) =~ m/$regexp/ );
Branch: 1 branch
BranchTrueFalseTotal
if ref($obj) =~ /$regexp/ 2 2 4
752 2 return;
753 2 };
754 }
755 }
756 7 1;
757 __END__
« Class.pm ↑ Summary Class/Multiton.pm »