Class/DataTypes.pm

filter: Statementstmt 75.1% 109 / 145 Branchbran 70.4% 62 / 88 Conditioncond 81.8% 54 / 66 MC/DCmcdc 68.4% 26 / 38 Subroutinesub 92.5% 25 / 27 Podpod 100% 5 / 5 totaltotal 76.1% 281 / 369 CC 70 SCAR 20.0
CC
70
Cov
75%
__ANON__
30.0
set_ref_checker
12.0
__ANON__
11.9
CRAP 7.4
« Class/Attributes/OOStandard/DefinitionCheck.pm ↑ Summary Class/Rigid.pm »
1 package Fukurama::Class::DataTypes;
2 4 ▶use Fukurama::Class::Version(0.04);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use Fukurama::Class::Rigid;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 Fukurama::Class::DataTypes - Helper class to register and check datatypes
8  
9 =head1 VERSION
10  
11 Version 0.04 (beta)
12  
13 =head1 SYNOPSIS
14  
15 package MyClass;
16  
17 BEGIN {
18 use Fukurama::Class::DataTypes();
19 Fukurama::Class::DataTypes->set_type_checker('MyOwnClass', sub {
20 my $parameter = $_[0];
21 my $data_type_checker_name = $_[1];
22
23 my $error = undef;
24 my $is_ok = 0;
25 if(ref($parameter) && UNIVERSAL::isa($parameter, 'MyOwnClass')) {
26 if($parameter->get('name') eq 'MyOwnName') {
27 $is_ok = 1;
28 } else {
29 $error = 'nameIsNotCorrect';
30 }
31 } else {
32 $error = 'notAnObject';
33 }
34 return ($is_ok, $parameter, $error);
35 });
36 }
37 use Fukurama::Class;
38
39 # Croak, if parameter one is not an instance of 'MyOwnClass'
40 # and doesn't have the name 'MyOwnName'
41 sub set_my_own_class : Method(public|MyOwnClass|boolean) {
42 ...
43 }
44  
45 =head1 DESCRIPTION
46  
47 This helper-class provides functions to register and handle check-methods for several data types.
48  
49 =head1 EXPORT
50  
51 -
52  
53 =head1 METHODS
54  
55 =over 4
56  
57 =item set_type_checker( name:STRING, checker:CODE ) return:BOOLEAN
58  
59 Set a check-method for a new or an existing datatype. B<Name> is the identifier string for the data type,
60 B<checker> is a code reference to check the data type.
61  
62 Examples for B<name>: I<string> , I<boolean>, I<MySpecial::Class>
63 Native data types have to be in lowercase. Object data types have to start with an uppercase letter.
64 You should be careful when you define the identifier because object data types would be handeled different as
65 native data types.
66  
67 An example for a type checker for a simple hash reference:
68  
69 $class->set_type_checker('hashref', sub {
70 my $parameter = $_[0];
71 my $data_type_checker_name = $_[1];
72
73 my $error = undef;
74 my $is_ok = 0;
75 if(ref($parameter) eq 'HASH') {
76 $is_ok = 1;
77 } else {
78 $error = 'notARef';
79 }
80 return ($is_ok, $parameter, $error);
81 });
82  
83 =item set_ref_checker( identifier:STRING, checker:CODE ) return:BOOLEAN
84  
85 Set a check-method for a new or an existing reference type. B<identifier> is the string which identifies this
86 reference, B<checker> is a code referende to check the reference type.
87  
88 Examples for B<identifier>: I<[]> (for array reference), I<{}> (for hash reference)
89  
90 An example for a reference checker for array references:
91  
92 $class->set_ref_checker('[]' => sub {
93 my $data_type_checker = $_[0];
94 my $parameter = $_[1];
95 my $data_type_checker_name = $_[2];
96 my $actual_subroutine_parameter = $_[3]; # \INT
97 my $full_subroutine_parameter_list = $_[4]; # \ARRAY
98
99 return 0 if(ref($parameter) ne 'ARRAY');
100 my $i = 0;
101 my $error = undef;
102 # Check all entries of this array reference
103 foreach my $parameter_entry (@{$parameter}) {
104 my ($is_ok, $returned_parameter, $returned_error) = &{$data_type_checker}($parameter_entry, $data_type_checker_name);
105 if(!$is_ok) {
106 $parameter->[$i] = $returned_parameter;
107 $error = [ $is_ok, $parameter, $returned_error ];
108 }
109 ++$i;
110 }
111 return @$error if($error) {
112 1;
113 });
114  
115 =item is_ref_allowed( identifier:STRING ) return:BOOLEAN
116  
117 Method to check if the given identifier has a defined reference checker.
118  
119 =item get_check_definition ( type_name:STRING, ref_identifier:STRING ) return:HASHREF
120  
121 For internal usage in attribute helper classes. Get the defined checker
122 methods for data type and the reference identifier as a hash reference.
123  
124 {
125 is_class => data_type_is_a_class:BOOLEAN,
126 check => reference_checker:CODE,
127 param_0 => data_type_checker:CODE,
128 }
129  
130 =item check_parameter_definition ( type_name:STRING, parameter_definition:HASHREF ) return:BOOLEAN
131  
132 For internal usage in attribute helper classes. Check the given parameter definition.
133  
134 =back
135  
136 =head1 AUTHOR, BUGS, SUPPORT, ACKNOWLEDGEMENTS, COPYRIGHT & LICENSE
137  
138 see perldoc of L<Fukurama::Class>
139  
140 =cut
141  
142 4 my $OVERFLOW_SIGN;
143 4 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=14.4
144 4 my $i = 0;
145 4 my $float;
146 4 ▶ while(++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i) 16 0 16
147 16 $float = '1.2e+' . ($i * 100);
148 16 my $result = ($float * 1) - $float;
149 16 ▶ if($result ne '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($result ne 0) 4 12 16
150 4 $OVERFLOW_SIGN = $float * 1;
151 4 last;
152 }
153 12 ▶ if($i > 1_000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 1000) 0 12 12
154 0 $OVERFLOW_SIGN = 'inf';
155 0 last;
156 }
157 }
158 }
159 11 ▶my $HAS_OVERFLOW = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
160 11 ($_[0] * 1) eq $OVERFLOW_SIGN;
161 4 };
162 # param: value:SCALAR, type:STRING
163 my $TYPES = {
164 3 ▶ void => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
165 3 ▶ return 1 if(!defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 1 2 3
166 2 (0, $_[0]);
167 },
168 5 ▶ scalar => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
169 5 1
170 },
171 2 ▶ scalarref => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
172 2 ▶ return 1 if(ref($_[0]) eq 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "SCALAR" 1 1 2
173 1 (0, $_[0]);
174 },
175 2 ▶ arrayref => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
176 2 ▶ return 1 if(ref($_[0]) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 1 1 2
177 1 (0, $_[0]);
178 },
179 2 ▶ hashref => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
180 2 ▶ return 1 if(ref($_[0]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 1 1 2
181 1 (0, $_[0]);
182 },
183 2 ▶ typglobref => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
184 2 ▶ return 1 if(ref($_[0]) eq 'GLOB');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "GLOB" 1 1 2
185 1 (0, $_[0]);
186 },
187 12 ▶ string => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
188 12 ▶ return 1 if(defined($_[0]) && !ref($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and not ref $_[0] 10 2 12
Condition100%3/3
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
1110
MC/DC100%2/2
defined $_[0] and not ref $_[0]
defined $_[0] not ref $_[0]
Truth table100%3/3
A and not(B)
A= defined $_[0]B= not ref $_[0]
ABresult
0X0
100
111
189 2 (0, $_[0]);
190 },
191 6 ▶ boolean => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
192 6 ▶ return 1 if(defined($_[0]) && ($_[0] eq '0' || $_[0] eq '1'));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq 0 || $_[0] eq 1 4 2 6
Condition100%6/6
defined $_[0] and $_[0] eq 0 || $_[0] eq 1
!ll&&!rl&&r
114
$_[0] eq 0 or $_[0] eq 1
l!l&&r!l&&!r
131
MC/DC100%3/3
defined $_[0] and $_[0] eq 0 || $_[0] eq 1
defined $_[0] $_[0] eq 0 $_[0] eq 1
Truth table100%4/4
A and B or C
A= defined $_[0]B= $_[0] eq 0C= $_[0] eq 1
ABCresult
0XX0
1000
11X1
1011
193 2 (0, $_[0]);
194 },
195 13 ▶ int => sub {
Subroutine __ANON__: called CC=8 SCAR=21.7
196 13 ▶ return 1 if(defined($_[0]) && $_[0] =~ m/^\-?[0-9]+$/ && ($_[0] * 1) eq $_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] =~ /^\-?[0-9]+$/ and $_[0] * 1 eq $_[0] 8 5 13
Condition83%5/6
defined $_[0] and $_[0] =~ /^\-?[0-9]+$/ and $_[0] * 1 eq $_[0]
!ll&&!rl&&r
328
defined $_[0] and $_[0] =~ /^\-?[0-9]+$/
!ll&&!rl&&r
0310
MC/DC66%2/3
defined $_[0] and $_[0] =~ /^\-?[0-9]+$/ and $_[0] * 1 eq $_[0]
defined $_[0] $_[0] =~ /^\-?[0-9]+$/ $_[0] * 1 eq $_[0]
Truth table75%3/4
A and B and C
A= defined $_[0]B= $_[0] =~ /^\-?[0-9]+$/C= $_[0] * 1 eq $_[0]
ABCresult
0XX0
10X0
1100
1111
197 5 ▶ return (0, $_[0]) if(!defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 5 5
198 5 ▶ return (0, $_[0], 'noInt') if($_[0] !~ m/^\-?[0-9]+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^\-?[0-9]+$/ 3 2 5
199 2 ▶ return (0, $_[0] * 1, 'overflow') if(&$HAS_OVERFLOW($_[0]) || ($_[0] * 1) ne $_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if &$HAS_OVERFLOW($_[0]) or $_[0] * 1 ne $_[0] 2 0 2
Condition66%2/3
&$HAS_OVERFLOW($_[0]) or $_[0] * 1 ne $_[0]
l!l&&r!l&&!r
110
MC/DC0%0/2
&$HAS_OVERFLOW($_[0]) or $_[0] * 1 ne $_[0]
&$HAS_OVERFLOW($_[0]) $_[0] * 1 ne $_[0]
Truth table66%2/3
A or B
A= &$HAS_OVERFLOW($_[0])B= $_[0] * 1 ne $_[0]
ABresult
1X1
011
000
200 0 (0, $_[0] * 1);
201 },
202 7 ▶ float => sub {
Subroutine __ANON__: called CC=11 SCAR=24.7
203 7 ▶ return 1 if(
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] =~ /^[0-9]+\.?[0-9]*$/ || $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+/ and $_[0] * 1 == $_[0] and not &$HAS_OVERFLOW($_[0]) 4 3 7
Condition91%11/12
defined $_[0] and $_[0] =~ /^[0-9]+\.?[0-9]*$/ || $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+/ and $_[0] * 1 == $_[0] and not &$HAS_OVERFLOW($_[0])
!ll&&!rl&&r
214
defined $_[0] and $_[0] =~ /^[0-9]+\.?[0-9]*$/ || $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+/ and $_[0] * 1 == $_[0]
!ll&&!rl&&r
205
defined $_[0] and $_[0] =~ /^[0-9]+\.?[0-9]*$/ || $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+/
!ll&&!rl&&r
115
$_[0] =~ /^[0-9]+\.?[0-9]*$/ or $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+/
l!l&&r!l&&!r
231
MC/DC80%4/5
defined $_[0] and $_[0] =~ /^[0-9]+\.?[0-9]*$/ || $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+/ and $_[0] * 1 == $_[0] and not &$HAS_OVERFLOW($_[0])
defined $_[0] $_[0] =~ /^[0-9]+\.?[0-9]*$/ $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+/ $_[0] * 1 == $_[0] not &$HAS_OVERFLOW($_[0])
Truth table62%5/8
A and B or C and D and not(E)
A= defined $_[0]B= $_[0] =~ /^[0-9]+\.?[0-9]*$/C= $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+/D= $_[0] * 1 == $_[0]E= not &$HAS_OVERFLOW($_[0])
ABCDEresult
0XXXX0
100XX0
11X0X0
1010X0
11X100
101100
11X111
101111
204 defined($_[0])
205 && ( $_[0] =~ m/^[0-9]+\.?[0-9]*$/ || $_[0] =~ m/^[0-9]+\.?[0-9]*e\+?[0-9]+/)
206 && ($_[0] * 1) == $_[0]
207 && !&$HAS_OVERFLOW($_[0])
208 );
209 3 ▶ return (0, $_[0]) if(!defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 1 2 3
210 2 ▶ return (0, $_[0], 'NaN') if($_[0] !~ m/^[0-9]+\.?[0-9]*$/ && $_[0] !~ m/^[0-9]+\.?[0-9]*e\+?[0-9]+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[0-9]+\.?[0-9]*$/ or $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+$/ 1 1 2
Condition66%2/3
$_[0] =~ /^[0-9]+\.?[0-9]*$/ or $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+$/
l!l&&r!l&&!r
011
MC/DC50%1/2
$_[0] =~ /^[0-9]+\.?[0-9]*$/ or $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+$/
$_[0] =~ /^[0-9]+\.?[0-9]*$/ $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+$/
Truth table66%2/3
A or B
A= $_[0] =~ /^[0-9]+\.?[0-9]*$/B= $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+$/
ABresult
1X1
011
000
211 1 ▶ return (0, $_[0] * 1, 'overflow') if(&$HAS_OVERFLOW($_[0]) || ($_[0] * 1) != $_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if &$HAS_OVERFLOW($_[0]) or $_[0] * 1 != $_[0] 1 0 1
Condition33%1/3
&$HAS_OVERFLOW($_[0]) or $_[0] * 1 != $_[0]
l!l&&r!l&&!r
100
MC/DC0%0/2
&$HAS_OVERFLOW($_[0]) or $_[0] * 1 != $_[0]
&$HAS_OVERFLOW($_[0]) $_[0] * 1 != $_[0]
Truth table33%1/3
A or B
A= &$HAS_OVERFLOW($_[0])B= $_[0] * 1 != $_[0]
ABresult
1X1
011
000
212 0 (0, $_[0]);
213 },
214 9 ▶ decimal => sub {
Subroutine __ANON__: called CC=10 SCAR=23.1
215 9 ▶ return 1 if(defined($_[0]) && $_[0] =~ m/^\-?[0-9]+\.?[0-9]*$/ && ($_[0] * 1) eq $_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] =~ /^\-?[0-9]+\.?[0-9]*$/ and $_[0] * 1 eq $_[0] 3 6 9
Condition100%6/6
defined $_[0] and $_[0] =~ /^\-?[0-9]+\.?[0-9]*$/ and $_[0] * 1 eq $_[0]
!ll&&!rl&&r
513
defined $_[0] and $_[0] =~ /^\-?[0-9]+\.?[0-9]*$/
!ll&&!rl&&r
144
MC/DC100%3/3
defined $_[0] and $_[0] =~ /^\-?[0-9]+\.?[0-9]*$/ and $_[0] * 1 eq $_[0]
defined $_[0] $_[0] =~ /^\-?[0-9]+\.?[0-9]*$/ $_[0] * 1 eq $_[0]
Truth table100%4/4
A and B and C
A= defined $_[0]B= $_[0] =~ /^\-?[0-9]+\.?[0-9]*$/C= $_[0] * 1 eq $_[0]
ABCresult
0XX0
10X0
1100
1111
216 6 ▶ return (0, $_[0]) if(!defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 1 5 6
217 5 ▶ return (0, $_[0], 'NaN') if($_[0] !~ m/^[0-9]+\.?[0-9]*$/ && $_[0] !~ m/^[0-9]+\.?[0-9]*e\+?[0-9]+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[0-9]+\.?[0-9]*$/ or $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+$/ 2 3 5
Condition100%3/3
$_[0] =~ /^[0-9]+\.?[0-9]*$/ or $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+$/
l!l&&r!l&&!r
122
MC/DC100%2/2
$_[0] =~ /^[0-9]+\.?[0-9]*$/ or $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+$/
$_[0] =~ /^[0-9]+\.?[0-9]*$/ $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+$/
Truth table100%3/3
A or B
A= $_[0] =~ /^[0-9]+\.?[0-9]*$/B= $_[0] =~ /^[0-9]+\.?[0-9]*e\+?[0-9]+$/
ABresult
1X1
011
000
218 3 ▶ return (0, $_[0] * 1, 'overflow') if(&$HAS_OVERFLOW($_[0]) || ($_[0] * 1) ne $_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if &$HAS_OVERFLOW($_[0]) or $_[0] * 1 ne $_[0] 2 1 3
Condition100%3/3
&$HAS_OVERFLOW($_[0]) or $_[0] * 1 ne $_[0]
l!l&&r!l&&!r
111
MC/DC100%2/2
&$HAS_OVERFLOW($_[0]) or $_[0] * 1 ne $_[0]
&$HAS_OVERFLOW($_[0]) $_[0] * 1 ne $_[0]
Truth table100%3/3
A or B
A= &$HAS_OVERFLOW($_[0])B= $_[0] * 1 ne $_[0]
ABresult
1X1
011
000
219 1 ▶ return (0, $_[0], 'noDec') if($_[0] !~ m/^\-?[0-9]+\.?[0-9]*$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^\-?[0-9]+\.?[0-9]*$/ 1 0 1
220 0 (0, $_[0] * 1);
221 },
222 4 ▶ class => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
223 4 ▶ return 1 if(!ref($_[0]) && UNIVERSAL::isa($_[0], $_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] and UNIVERSAL::isa($_[0], $_[0]) 1 3 4
Condition100%3/3
not ref $_[0] and UNIVERSAL::isa($_[0], $_[0])
!ll&&!rl&&r
121
MC/DC100%2/2
not ref $_[0] and UNIVERSAL::isa($_[0], $_[0])
not ref $_[0] UNIVERSAL::isa($_[0], $_[0])
Truth table100%3/3
not(A) and B
A= not ref $_[0]B= UNIVERSAL::isa($_[0], $_[0])
ABresult
0X0
100
111
224 3 (0, $_[0]);
225 },
226 4 ▶ object => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
227 4 ▶ return 1 if(ref($_[0]) && UNIVERSAL::isa($_[0], ref($_[0])));
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] and UNIVERSAL::isa($_[0], ref $_[0]) 1 3 4
Condition66%2/3
ref $_[0] and UNIVERSAL::isa($_[0], ref $_[0])
!ll&&!rl&&r
301
MC/DC50%1/2
ref $_[0] and UNIVERSAL::isa($_[0], ref $_[0])
ref $_[0] UNIVERSAL::isa($_[0], ref $_[0])
Truth table66%2/3
A and B
A= ref $_[0]B= UNIVERSAL::isa($_[0], ref $_[0])
ABresult
0X0
100
111
228 3 (0, $_[0]);
229 },
230 6 ▶ '*class*' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
231 6 ▶ return 1 if(ref($_[0]) && UNIVERSAL::isa($_[0], $_[1]));
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] and UNIVERSAL::isa($_[0], $_[1]) 2 4 6
Condition100%3/3
ref $_[0] and UNIVERSAL::isa($_[0], $_[1])
!ll&&!rl&&r
312
MC/DC100%2/2
ref $_[0] and UNIVERSAL::isa($_[0], $_[1])
ref $_[0] UNIVERSAL::isa($_[0], $_[1])
Truth table100%3/3
A and B
A= ref $_[0]B= UNIVERSAL::isa($_[0], $_[1])
ABresult
0X0
100
111
232 4 (0, $_[0]);
233 },
234 4 };
235 4 my $CLASS_TYPES = {
236 class => 1,
237 object => 1,
238 };
239 # param: check_sub:CODE, value:SCALAR, type:STRING, pos:\INT, all_io:\ARRAY
240 my $REFS = {
241 75 ▶ '' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
242 75 &{$_[0]}($_[1], $_[2]);
243 },
244 2 ▶ '[]' => sub {
Subroutine __ANON__: called CC=5 SCAR=22.7
245 2 ▶ return 0 if(ref($_[1]) ne 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[1] ne "ARRAY" 0 2 2
246 2 my $i = 0;
247 2 my $error = undef;
248 2 foreach my $entry (@{$_[1]}) {
249 0 my @result = &{$_[0]}($entry, $_[2]);
250 0 ▶ if(!$result[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result[0]) 0 0 0
251 0 $_[1]->[$i] = $result[1];
252 0 $error = \@result;
253 }
254 0 ++$i;
255 }
256 2 ▶ if($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 2 2
257 0 $error->[1] = $_[1];
258 0 return @$error;
259 }
260 2 1;
261 },
262 2 ▶ '()' => sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
263 2 my $error = undef;
264 2 my @io = @{$_[4]}[${$_[3]}..$#{$_[4]}];
265 2 foreach my $entry (@io) {
266 6 my @result = &{$_[0]}($entry, $_[2]);
267 6 ▶ if(!$result[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result[0]) 0 6 6
268 0 $error = \@result;
269 0 last;
270 }
271 }
272 2 ${$_[3]} = $#{$_[4]};
273 2 ▶ return @$error if($error);
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 2 2
274 2 1;
275 },
276 0 ▶ '{}' => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
277 0 ▶ return 0 if(ref($_[1]) ne 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[1] ne "HASH" 0 0 0
278 0 my $error = undef;
279 0 foreach my $key (keys(%{$_[1]})) {
280 0 my $entry = $_[1]->{$key};
281 0 my @result = &{$_[0]}($entry, $_[2]);
282 0 ▶ if(!$result[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result[0]) 0 0 0
283 0 $_[1]->{$key} = $result[1];
284 0 $error = \@result;
285 }
286 }
287 0 ▶ if($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
288 0 $error->[1] = $_[1];
289 0 return @$error;
290 }
291 0 1;
292 }
293 4 };
294 # boolean
295 0 ▶sub set_ref_checker {
Subroutine set_ref_checker: not called CC=3 SCAR=24.8
Pod documented
296 0 my $class = $_[0];
297 0 my $identifier = $_[1];
298 0 my $code = $_[2];
299
300 0 ▶ return 0 if(!length($identifier) || ref($code) ne 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
if not length $identifier or ref $code ne "CODE" 0 0 0
Condition0%0/3
not length $identifier or ref $code ne "CODE"
l!l&&r!l&&!r
000
MC/DC0%0/2
not length $identifier or ref $code ne "CODE"
not length $identifier ref $code ne "CODE"
Truth table0%0/3
not(A) or B
A= not length $identifierB= ref $code ne "CODE"
ABresult
1X1
011
000
301 0 $REFS->{$identifier} = $code;
302 0 return 1;
303 }
304 # boolean
305 1 ▶sub set_type_checker {
Subroutine set_type_checker: called CC=3 SCAR=11.6
Pod documented
306 1 my $class = $_[0];
307 1 my $identifier = $_[1];
308
309 1 my $code = $_[2];
310
311 1 ▶ return 0 if(!length($identifier) || ref($code) ne 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
if not length $identifier or ref $code ne "CODE" 0 1 1
Condition33%1/3
not length $identifier or ref $code ne "CODE"
l!l&&r!l&&!r
001
MC/DC0%0/2
not length $identifier or ref $code ne "CODE"
not length $identifier ref $code ne "CODE"
Truth table33%1/3
not(A) or B
A= not length $identifierB= ref $code ne "CODE"
ABresult
1X1
011
000
312 1 $TYPES->{$identifier} = $code;
313 1 return 1;
314 }
315 # boolean
316 38 ▶sub is_ref_allowed {
Subroutine is_ref_allowed: called CC=2 SCAR=7.6
Pod documented
317 38 my $class = $_[0];
318 38 my $identifier = $_[1];
319
320 38 ▶ return 1 if(exists($REFS->{$identifier}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $REFS->{$identifier} 38 0 38
321 0 return 0;
322 }
323 # hashref
324 102 ▶sub get_check_definition {
Subroutine get_check_definition: called CC=6 SCAR=18.0
Pod documented
325 102 my $class = $_[0];
326 102 my $type = $_[1];
327 102 my $ref = $_[2];
328
329 102 my $ref_sub = $REFS->{$ref};
330 102 ▶ return {} if(!$ref_sub);
Branch: 1 branch
BranchTrueFalseTotal
unless $ref_sub 0 102 102
331
332 102 my $is_class = 0;
333 102 my $type_sub = $TYPES->{$type};
334 102 ▶ if(!$type_sub) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type_sub) 12 90 102
335 12 ▶ return {} if($type !~ /^[A-Z]/);
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /^[A-Z]/ 0 12 12
336 12 $type_sub = $TYPES->{'*class*'};
337 12 $is_class = 1;
338 }
339 102 ▶ $is_class = 1 if($CLASS_TYPES->{$type} || $type =~ m/^[A-Z]/);
Branch: 1 branch
BranchTrueFalseTotal
if $CLASS_TYPES->{$type} or $type =~ /^[A-Z]/ 24 78 102
Condition100%3/3
$CLASS_TYPES->{$type} or $type =~ /^[A-Z]/
l!l&&r!l&&!r
81678
MC/DC100%2/2
$CLASS_TYPES->{$type} or $type =~ /^[A-Z]/
$CLASS_TYPES->{$type} $type =~ /^[A-Z]/
Truth table100%3/3
A or B
A= $CLASS_TYPES->{$type}B= $type =~ /^[A-Z]/
ABresult
1X1
011
000
340 return {
341 102 is_class => $is_class,
342 check => $ref_sub,
343 param_0 => $type_sub,
344 };
345 }
346 # boolean
347 38 ▶sub check_parameter_definition {
Subroutine check_parameter_definition: called CC=4 SCAR=14.0
Pod documented
348 38 my $class = $_[0];
349 38 my $param_type = $_[1];
350 38 my $check_def = $_[2];
351
352 38 ▶ return 0 if(!$check_def->{'check'});
Branch: 1 branch
BranchTrueFalseTotal
unless $check_def->{"check"} 0 38 38
353
354 38 ▶ return 1 if($CLASS_TYPES->{$param_type});
Branch: 1 branch
BranchTrueFalseTotal
if $CLASS_TYPES->{$param_type} 0 38 38
355 38 ▶ if($check_def->{'is_class'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check_def->{"is_class"}) 6 32 38
356 6 return UNIVERSAL::isa($param_type, $param_type);
357 }
358 32 1;
359 }
360 4 1;
« Class/Attributes/OOStandard/DefinitionCheck.pm ↑ Summary Class/Rigid.pm »