Compile/Schema/BuiltInFacets.pm

filter: Statementstmt 75.4% 154 / 204 Branchbran 54.8% 57 / 104 Conditioncond 27.7% 10 / 36 MC/DCmcdc 18.1% 4 / 22 Subroutinesub 73.8% 48 / 65 Podpod 100% 1 / 1 totaltotal 63.4% 274 / 432 CC 66 SCAR 24.0
CC
66
Cov
64%
_maybe_big
66.1
_date_expl_tz
20.0
__ANON__
12.0
CRAP 11.0
« Compile/Translate/Writer.pm ↑ Summary Compile/Schema/Specs.pm »
1 # Copyrights 2006-2024 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of distribution XML-Compile. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package XML::Compile::Schema::BuiltInFacets;{
10 50 our $VERSION = '1.64';
11 }
12  
13 50 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 50 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 50 our @EXPORT = qw/builtin_facet/;
20  
21 50 ▶use Log::Report 'xml-compile';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 50 ▶use Math::BigInt;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 50 ▶use Math::BigFloat;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 50 ▶use XML::LibXML; # for ::RegExp
Subroutine BEGIN: called CC=1 SCAR=0.0
26 50 ▶use XML::Compile::Util qw/SCHEMA2001 pack_type duration2secs/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 50 ▶use POSIX qw/DBL_MAX_10_EXP DBL_DIG/;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # depend on Perl's compile flags
31 50 ▶use constant INT_MAX => int((sprintf"%u\n",-1)/2);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 50 ▶use constant INT_MIN => -1 - INT_MAX;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34  
35 50 my %facets_simple =
36 ( enumeration => \&_enumeration
37 , fractionDigits => \&_s_fractionDigits
38 , length => \&_s_length
39 , maxExclusive => \&_s_maxExclusive
40 , maxInclusive => \&_s_maxInclusive
41 , maxLength => \&_s_maxLength
42 , maxScale => undef # ignore
43 , minExclusive => \&_s_minExclusive
44 , minInclusive => \&_s_minInclusive
45 , minLength => \&_s_minLength
46 , minScale => undef # ignore
47 , pattern => \&_pattern
48 , totalDigits => \&_s_totalDigits
49 , whiteSpace => \&_s_whiteSpace
50 , _totalFracDigits=> \&_s_totalFracDigits
51 );
52  
53 50 my %facets_list =
54 ( enumeration => \&_enumeration
55 , length => \&_list_length
56 , maxLength => \&_list_maxLength
57 , minLength => \&_list_minLength
58 , pattern => \&_pattern
59 , whiteSpace => \&_list_whiteSpace
60 );
61  
62 50 my %facets_date = # inclusive or exclusive times is rather useless.
63 ( enumeration => \&_enumeration
64 , explicitTimeZone=> \&_date_expl_tz
65 , maxExclusive => \&_date_max
66 , maxInclusive => \&_date_max
67 , minExclusive => \&_date_min
68 , minInclusive => \&_date_min
69 , pattern => \&_pattern
70 , whiteSpace => \&_date_whiteSpace
71 );
72  
73 50 my %facets_duration =
74 ( enumeration => \&_enumeration
75 , maxExclusive => \&_dur_max_excl
76 , maxInclusive => \&_dur_max_incl
77 , minExclusive => \&_dur_min_excl
78 , minInclusive => \&_dur_min_incl
79 , pattern => \&_pattern
80 , whiteSpace => \&_s_whiteSpace
81 );
82  
83 50 my $date_time_type = pack_type SCHEMA2001, 'dateTime';
84 50 my $date_type = pack_type SCHEMA2001, 'date';
85 50 my $duration_type = pack_type SCHEMA2001, 'duration';
86  
87 sub builtin_facet($$$$$$$$)
88 243 ▶{ my ($path, $args, $facet, $value, $is_list, $type, $nss, $action) = @_;
Subroutine builtin_facet: called CC=6 SCAR=18.1
Pod documented
89  
90 my $def
91 = $is_list ? $facets_list{$facet}
92 : $nss->doesExtend($type, $date_time_type) ? $facets_date{$facet}
93 : $nss->doesExtend($type, $date_type) ? $facets_date{$facet}
94 : $nss->doesExtend($type, $duration_type) ? $facets_duration{$facet}
95 243 ▶ : $facets_simple{$facet};
Branch: 4 branches
BranchTrueFalseTotal
$is_list ? : 23 220 243
$nss->doesExtend($type, $date_time_type) ? : 4 216 220
$nss->doesExtend($type, $date_type) ? : 0 216 216
$nss->doesExtend($type, $duration_type) ? : 5 211 216
96  
97 243 ▶ $def or error __x"facet {facet} not implemented at {where}"
Branch: 1 branch
BranchTrueFalseTotal
$def or &error(&__x("facet {facet} not implemented at {where}", "facet", $facet, "where", $path)) 243 0 243
98 , facet => $facet, where => $path;
99  
100 243 $def->($path, $args, $value, $type, $nss, $action);
101 }
102  
103 sub _list_whiteSpace($$$)
104 0 ▶{ my ($path, undef, $ws) = @_;
Subroutine _list_whiteSpace: not called CC=2 SCAR=17.9
105 0 ▶ $ws eq 'collapse'
Branch: 1 branch
BranchTrueFalseTotal
$ws eq "collapse" or &error(&__x("list whiteSpace facet fixed to 'collapse', not '{ws}' in {path}", "ws", $ws, "path", $path)) 0 0 0
106 or error __x"list whiteSpace facet fixed to 'collapse', not '{ws}' in {path}"
107 , ws => $ws, path => $path;
108 0 ();
109 }
110  
111 sub _s_whiteSpace($$$)
112 6 ▶{ my ($path, undef, $ws) = @_;
Subroutine _s_whiteSpace: called CC=4 SCAR=13.9
113 6 ▶ $ws eq 'replace' ? \&_whitespace_replace
Branch: 3 branches
BranchTrueFalseTotal
$ws eq 'replace' ? : 2 4 6
$ws eq 'collapse' ? : 2 2 4
$ws eq 'preserve' ? : 2 0 2
114 : $ws eq 'collapse' ? \&_whitespace_collapse
115 : $ws eq 'preserve' ? ()
116 : error __x"illegal whiteSpace facet '{ws}' in {path}"
117 , ws => $ws, path => $path;
118 }
119  
120 sub _date_whiteSpace($$$)
121 0 ▶{ my ($path, undef, $ws) = @_;
Subroutine _date_whiteSpace: not called CC=2 SCAR=17.9
122  
123 # whitespace processing already in the dateTime parser
124 0 ▶ $ws eq 'collapse'
Branch: 1 branch
BranchTrueFalseTotal
$ws eq "collapse" or &error(&__x("illegal whiteSpace facet '{ws}' in {path}", "ws", $ws, "path", $path)) 0 0 0
125 or error __x"illegal whiteSpace facet '{ws}' in {path}"
126 , ws => $ws, path => $path;
127 0 ();
128 }
129  
130 sub _whitespace_replace($)
131 2 ▶{ my $value = ref $_[0] ? $_[0]->textContent : $_[0];
Subroutine _whitespace_replace: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 1 2
132 2 $value =~ s/[\t\r\n]/ /gs;
133 2 $value;
134 }
135  
136 sub _whitespace_collapse($)
137 2 ▶{ my $value = ref $_[0] ? $_[0]->textContent : $_[0];
Subroutine _whitespace_collapse: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 1 2
138 2 for($value)
139 2 { s/[\t\r\n ]+/ /gs;
140 2 s/^ +//;
141 2 s/ +$//;
142 }
143 2 $value;
144 }
145  
146 sub _maybe_big($$$)
147 72 ▶{ my ($path, $args, $value) = @_;
Subroutine _maybe_big: called CC=14 SCAR=41.9
148 72 ▶ return $value if $args->{sloppy_integers};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"sloppy_integers"} 2 70 72
149  
150 # modules Math::Big* loaded by Schema::Spec when not sloppy
151  
152 70 $value =~ s/\s//g;
153 70 ▶ if($value =~ m/[.eE]/)
Branch: 2 branches
BranchTrueFalseTotal
if ($value =~ /[.eE]/) { } 0 70 70
elsif (substr($value, 0, 1) eq '-') { } 0 70 70
154 0 { my $c = $value;
155 0 ▶ my $exp = $c =~ s/[eE][+-]?([0-9]+)// ? $1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$c =~ s/[eE][+-]?([0-9]+)// ? : 0 0 0
156 0 ▶ my $pre = $c =~ /^[-+]?([0-9]*)/ ? length($1) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$c =~ /^[-+]?([0-9]*)/ ? : 0 0 0
157 0 ▶ return Math::BigFloat->new($value)
Branch: 1 branch
BranchTrueFalseTotal
if $pre >= 15 or $pre + $exp >= 308 0 0 0
Condition0%0/3
$pre >= 15 or $pre + $exp >= 308
l!l&&r!l&&!r
000
MC/DC0%0/2
$pre >= 15 or $pre + $exp >= 308
$pre >= 15 $pre + $exp >= 308
Truth table0%0/3
A or B
A= $pre >= 15B= $pre + $exp >= 308
ABresult
1X1
011
000
158 if $pre >= DBL_DIG || $pre+$exp >= DBL_MAX_10_EXP;
159 }
160 # compare ints as strings, because they will overflow!!
161 elsif(substr($value, 0, 1) eq '-')
162 0 ▶ { return Math::BigInt->new($value)
Branch: 1 branch
BranchTrueFalseTotal
if length $value > 21 or length $value == 21 and $value gt "-9.22337203685478e+18" 0 0 0
Condition0%0/6
length $value > 21 or length $value == 21 and $value gt "-9.22337203685478e+18"
l!l&&r!l&&!r
000
length $value == 21 and $value gt "-9.22337203685478e+18"
!ll&&!rl&&r
000
MC/DC0%0/3
length $value > 21 or length $value == 21 and $value gt "-9.22337203685478e+18"
length $value > 21 length $value == 21 $value gt "-9.22337203685478e+18"
Truth table0%0/4
A or B and C
A= length $value > 21B= length $value == 21C= $value gt "-9.22337203685478e+18"
ABCresult
1XX1
0111
00X0
0100
163 if length($value) > length(INT_MIN)
164 || (length($value)==length(INT_MIN) && $value gt INT_MIN);
165 }
166 else
167 70 ▶ { return Math::BigInt->new($value)
Branch: 1 branch
BranchTrueFalseTotal
if length $value > 19 or length $value == 19 and $value gt '9223372036854775808' 6 64 70
Condition50%3/6
length $value > 19 or length $value == 19 and $value gt '9223372036854775808'
l!l&&r!l&&!r
6064
length $value == 19 and $value gt '9223372036854775808'
!ll&&!rl&&r
6400
MC/DC33%1/3
length $value > 19 or length $value == 19 and $value gt '9223372036854775808'
length $value > 19 length $value == 19 $value gt '9223372036854775808'
Truth table50%2/4
A or B and C
A= length $value > 19B= length $value == 19C= $value gt '9223372036854775808'
ABCresult
1XX1
0111
00X0
0100
168 if length($value) > length(INT_MAX)
169 || (length($value)==length(INT_MAX) && $value gt INT_MAX);
170 }
171  
172 64 $value;
173 }
174  
175 sub _s_minInclusive($$$)
176 33 ▶{ my ($path, $args, $min) = @_;
Subroutine _s_minInclusive: called CC=1 SCAR=0.0
177 33 $min = _maybe_big $path, $args, $min;
178 26 ▶ sub { return $_[0] if $_[0] >= $min;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] >= $min 19 7 26
179 7 error __x"too small inclusive {value}, min {min} at {where}"
180 , value => $_[0], min => $min, where => $path;
181 33 };
182 }
183  
184 sub _s_minExclusive($$$)
185 6 ▶{ my ($path, $args, $min) = @_;
Subroutine _s_minExclusive: called CC=1 SCAR=0.0
186 6 $min = _maybe_big $path, $args, $min;
187 6 ▶ sub { return $_[0] if $_[0] > $min;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] > $min 4 2 6
188 2 error __x"too small exclusive {value}, larger {min} at {where}"
189 , value => $_[0], min => $min, where => $path;
190 6 };
191 }
192  
193 sub _s_maxInclusive($$$)
194 21 ▶{ my ($path, $args, $max) = @_;
Subroutine _s_maxInclusive: called CC=1 SCAR=0.0
195 21 $max = _maybe_big $path, $args, $max;
196 18 ▶ sub { return $_[0] if $_[0] <= $max;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] <= $max 12 6 18
197 6 error __x"too large inclusive {value}, max {max} at {where}"
198 , value => $_[0], max => $max, where => $path;
199 21 };
200 }
201  
202 sub _s_maxExclusive($$$)
203 12 ▶{ my ($path, $args, $max) = @_;
Subroutine _s_maxExclusive: called CC=1 SCAR=0.0
204 12 $max = _maybe_big $path, $args, $max;
205 5 ▶ sub { return $_[0] if $_[0] < $max;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] < $max 3 2 5
206 2 error __x"too large exclusive {value}, smaller {max} at {where}"
207 , value => $_[0], max => $max, where => $path;
208 12 };
209 }
210  
211 50 my $qname = pack_type SCHEMA2001, 'QName';
212 sub _enumeration($$$$$$)
213 62 ▶{ my ($path, $args, $enums, $type, $nss, $action) = @_;
Subroutine _enumeration: called CC=1 SCAR=0.0
214  
215 62 my %enum = map +($_ => 1), @$enums;
216 48 ▶ sub { my $v = ref $_[0] eq 'ARRAY' ? join(' ', @{$_[0]}) : $_[0];
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 9 39 48
217 48 ▶ return $v if exists $enum{$v};
Branch: 1 branch
BranchTrueFalseTotal
if exists $enum{$v} 30 18 48
218 18 error __x"invalid enumerate `{string}' at {where}"
219 , string => $v, where => $path;
220 62 };
221 }
222  
223 sub _s_totalDigits($$$)
224 26 ▶{ my ($path, undef, $total) = @_;
Subroutine _s_totalDigits: called CC=1 SCAR=0.0
225  
226 # this accidentally also works correctly for NaN +INF -INF
227 sub
228 26 ▶ { my $v = $_[0];
Subroutine __ANON__: called CC=2 SCAR=6.9
229 26 $v =~ s/[eE].*//;
230 26 $v =~ s/^[+-]?0*//;
231 26 ▶ return $_[0] if $total >= ($v =~ tr/0-9//);
Branch: 1 branch
BranchTrueFalseTotal
if $total >= $v =~ tr/0-9// 24 2 26
232  
233 2 error __x"decimal too long, got {length} digits max {max} at {where}"
234 , length => ($v =~ tr/0-9//), max => $total, where => $path;
235 26 };
236 }
237  
238 sub _s_fractionDigits($$$)
239 2 ▶{ my $frac = $_[2];
Subroutine _s_fractionDigits: called CC=1 SCAR=0.0
240 # can be result from Math::BigFloat, so too long to use %f But rounding
241 # is very hard to implement. If you need this accuracy, then format your
242 # value yourself!
243 sub
244 4 ▶ { my $v = $_[0];
Subroutine __ANON__: called CC=1 SCAR=0.0
245 4 $v =~ s/(\.[0-9]{$frac}).*/$1/;
246 4 $v;
247 2 };
248 }
249  
250 sub _s_totalFracDigits($$$)
251 3 ▶{ my ($path, undef, $dig) = @_;
Subroutine _s_totalFracDigits: called CC=1 SCAR=0.1
252 3 my ($total, $frac) = @$dig;
253 sub
254 4 ▶ { my $w = $_[0];
Subroutine __ANON__: called CC=5 SCAR=17.0
255  
256 4 my $v = $w; # total is checking length
257 4 $v =~ s/[eE].*//;
258 4 $v =~ s/^[+-]?0*//;
259  
260 4 ▶ if( $v !~ /^(?:[+-]?)(?:[0-9]*)(?:\.([0-9]*))?$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($v =~ /^(?:[+-]?)(?:[0-9]*)(?:\.([0-9]*))?$/) 0 4 4
261 0 { error __x"Invalid numeric format, got {value} at {where}"
262 , value => $w, where => $path;
263 }
264  
265 4 ▶ if($1 && length($1) > $frac)
Branch: 1 branch
BranchTrueFalseTotal
if ($1 and length $1 > $frac) 1 3 4
Condition66%2/3
$1 and length $1 > $frac
!ll&&!rl&&r
031
MC/DC50%1/2
$1 and length $1 > $frac
$1 length $1 > $frac
Truth table66%2/3
A and B
A= $1B= length $1 > $frac
ABresult
0X0
100
111
266 1 { error __x"fractional part for {value} too long, got {l} digits max {max} at {where}"
267 , value => $w, l => length($1), max => $frac, where => $path;
268 }
269  
270 3 ▶ return $w if $total >= ($v =~ tr/0-9//);
Branch: 1 branch
BranchTrueFalseTotal
if $total >= $v =~ tr/0-9// 3 0 3
271 0 error __x"decimal too long, got {length} digits max {max} at {where}"
272 , length => ($v =~ tr/0-9//), max => $total, where => $path;
273 3 };
274 }
275  
276 sub _s_length($$$$$$)
277 19 ▶{ my ($path, $args, $len, $type, $nss, $action) = @_;
Subroutine _s_length: called CC=1 SCAR=0.0
278  
279 15 ▶ sub { return $_[0] if defined $_[0] && length($_[0])==$len;
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and length $_[0] == $len 6 9 15
Condition66%2/3
defined $_[0] and length $_[0] == $len
!ll&&!rl&&r
096
MC/DC50%1/2
defined $_[0] and length $_[0] == $len
defined $_[0] length $_[0] == $len
Truth table66%2/3
A and B
A= defined $_[0]B= length $_[0] == $len
ABresult
0X0
100
111
280 9 error __x"string `{string}' does not have required length {len} but {size} at {where}"
281 , string => $_[0], len => $len, size => length($_[0]), where => $path;
282 19 };
283 }
284  
285 sub _list_length($$$)
286 6 ▶{ my ($path, $args, $len) = @_;
Subroutine _list_length: called CC=1 SCAR=0.0
287 6 ▶ sub { return $_[0] if defined $_[0] && @{$_[0]}==$len;
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and @{$_[0];} == $len 2 4 6
Condition66%2/3
defined $_[0] and @{$_[0];} == $len
!ll&&!rl&&r
042
MC/DC50%1/2
defined $_[0] and @{$_[0];} == $len
defined $_[0] @{$_[0];} == $len
Truth table66%2/3
A and B
A= defined $_[0]B= @{$_[0];} == $len
ABresult
0X0
100
111
288 4 error __x"list `{list}' does not have required length {len} at {where}"
289 , list => $_[0], len => $len, where => $path;
290 6 };
291 }
292  
293 sub _s_minLength($$$)
294 8 ▶{ my ($path, $args, $len, $type, $nss, $action) = @_;
Subroutine _s_minLength: called CC=1 SCAR=0.8
295  
296 4 ▶ sub { return $_[0] if defined $_[0] && length($_[0]) >=$len;
Subroutine __ANON__: called CC=3 SCAR=15.4
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and length $_[0] >= $len 4 0 4
Condition33%1/3
defined $_[0] and length $_[0] >= $len
!ll&&!rl&&r
004
MC/DC0%0/2
defined $_[0] and length $_[0] >= $len
defined $_[0] length $_[0] >= $len
Truth table33%1/3
A and B
A= defined $_[0]B= length $_[0] >= $len
ABresult
0X0
100
111
297 0 error __x"string `{string}' does not have minimum length {len} at {where}"
298 , string => $_[0], len => $len, where => $path;
299 8 };
300 }
301  
302 sub _list_minLength($$$)
303 0 ▶{ my ($path, $args, $len) = @_;
Subroutine _list_minLength: not called CC=1 SCAR=6.9
304 0 ▶ sub { return $_[0] if defined $_[0] && @{$_[0]} >=$len;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and @{$_[0];} >= $len 0 0 0
Condition0%0/3
defined $_[0] and @{$_[0];} >= $len
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and @{$_[0];} >= $len
defined $_[0] @{$_[0];} >= $len
Truth table0%0/3
A and B
A= defined $_[0]B= @{$_[0];} >= $len
ABresult
0X0
100
111
305 0 error __x"list `{list}' does not have minimum length {len} at {where}"
306 , list => $_[0], len => $len, where => $path;
307 0 };
308 }
309  
310 sub _s_maxLength($$$)
311 0 ▶{ my ($path, $args, $len, $type, $nss, $action) = @_;
Subroutine _s_maxLength: not called CC=1 SCAR=6.9
312  
313 0 ▶ sub { return $_[0] if defined $_[0] && length $_[0] <= $len;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and length $_[0] <= $len 0 0 0
Condition0%0/3
defined $_[0] and length $_[0] <= $len
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and length $_[0] <= $len
defined $_[0] length $_[0] <= $len
Truth table0%0/3
A and B
A= defined $_[0]B= length $_[0] <= $len
ABresult
0X0
100
111
314 0 error __x"string `{string}' longer than maximum length {len} at {where}"
315 , string => $_[0], len => $len, where => $path;
316 0 };
317 }
318  
319 sub _list_maxLength($$$)
320 0 ▶{ my ($path, $args, $len) = @_;
Subroutine _list_maxLength: not called CC=1 SCAR=6.9
321 0 ▶ sub { return $_[0] if defined $_[0] && @{$_[0]} <= $len;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and @{$_[0];} <= $len 0 0 0
Condition0%0/3
defined $_[0] and @{$_[0];} <= $len
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and @{$_[0];} <= $len
defined $_[0] @{$_[0];} <= $len
Truth table0%0/3
A and B
A= defined $_[0]B= @{$_[0];} <= $len
ABresult
0X0
100
111
322 0 error __x"list `{list}' longer than maximum length {len} at {where}"
323 , list => $_[0], len => $len, where => $path;
324 0 };
325 }
326  
327 sub _pattern($$$)
328 30 ▶{ my ($path, $args, $pats) = @_;
Subroutine _pattern: called CC=3 SCAR=11.1
329 30 ▶ @$pats or return ();
Branch: 1 branch
BranchTrueFalseTotal
@$pats or return () 30 0 30
330 30 ▶ my $regex = @$pats==1 ? $pats->[0] : "(".join(')|(', @$pats).")";
Branch: 1 branch
BranchTrueFalseTotal
@$pats == 1 ? : 30 0 30
331 30 my $compiled = XML::LibXML::RegExp->new($regex);
332  
333 26 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
334 50 ▶use Carp 'cluck';
Subroutine BEGIN: called CC=1 SCAR=0.0
335 26 ▶defined $_[0] or cluck "PATTERN";
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] or cluck("PATTERN") 26 0 26
336 26 ▶ my $v = ref $_[0] ? $_[0]->textContent : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 10 16 26
337 26 ▶ return $_[0] if $compiled->matches($v);
Branch: 1 branch
BranchTrueFalseTotal
if $compiled->matches($v) 20 6 26
338 6 error __x"string `{string}' does not match pattern `{pat}' at {where}"
339 , string => $v, pat => $regex, where => $path;
340 30 };
341 }
342  
343 sub _date_min($$$)
344 2 ▶{ my ($path, $args, $min) = @_;
Subroutine _date_min: called CC=1 SCAR=0.4
345 2 ▶ sub { return $_[0] if $_[0] gt $min;
Subroutine __ANON__: called CC=2 SCAR=9.2
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] gt $min 2 0 2
346 0 error __x"too small inclusive {value}, min {min} at {where}"
347 , value => $_[0], min => $min, where => $path;
348 2 };
349 }
350  
351 sub _date_max($$$)
352 2 ▶{ my ($path, $args, $max) = @_;
Subroutine _date_max: called CC=1 SCAR=0.4
353 2 ▶ sub { return $_[0] if $_[0] lt $max;
Subroutine __ANON__: called CC=2 SCAR=9.2
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] lt $max 2 0 2
354 0 error __x"too large inclusive {value}, max {max} at {where}"
355 , value => $_[0], max => $max, where => $path;
356 2 };
357 }
358  
359 sub _date_expl_tz($$$)
360 0 ▶{ my ($path, $args, $enum) = @_;
Subroutine _date_expl_tz: not called CC=4 SCAR=30.0
361 0 my $tz = qr/Z$ | [+-](?:(?:0[0-9]|1[0-3])\:[0-5][0-9] | 14\:00)$/x;
362  
363 $enum eq 'optional' ? ()
364 : $enum eq 'prohibited'
365 0 ▶ ? sub { $_[0] !~ $tz
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
not $_[0] =~ /$tz/ or &error(&__x("timezone forbidden on {date} at {where}", "date", $_[0], "where", $path)) 0 0 0
366 or error __x"timezone forbidden on {date} at {where}"
367 , date => $_[0], where => $path;
368 }
369 : $enum eq 'required'
370 0 ▶ ? sub { $_[0] =~ $tz
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /$tz/ or &error(&__x("timezone required on {date} at {where}", "date", $_[0], "where", $path)) 0 0 0
371 or error __x"timezone required on {date} at {where}"
372 , date => $_[0], where => $path;
373 }
374 0 ▶ : error __x"illegal explicitTimeZone facet '{enum}' in {path}"
Branch: 3 branches
BranchTrueFalseTotal
$enum eq 'optional' ? : 0 0 0
$enum eq 'prohibited' ? : 0 0 0
$enum eq 'required' ? : 0 0 0
375 , enum => $enum, path => $path;
376 }
377  
378 sub _dur_min_incl($$$)
379 5 ▶{ my ($path, $args, $min) = @_;
Subroutine _dur_min_incl: called CC=1 SCAR=0.0
380 5 my $secs = duration2secs $min;
381  
382 5 ▶ sub { return $_[0] if duration2secs $_[0] >= $secs;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &duration2secs($_[0]) >= $secs 4 1 5
383 1 error __x"too small minInclusive duration {value}, min {min} at {where}"
384 , value => $_[0], min => $min, where => $path;
385 5 };
386 }
387  
388  
389 sub _dur_min_excl($$$)
390 0 ▶{ my ($path, $args, $min) = @_;
Subroutine _dur_min_excl: not called CC=1 SCAR=6.9
391 0 my $secs = duration2secs $min;
392  
393 0 ▶ sub { return $_[0] if duration2secs $_[0] > $secs;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if &duration2secs($_[0]) > $secs 0 0 0
394 0 error __x"too small minExclusive duration {value}, min {min} at {where}"
395 , value => $_[0], min => $min, where => $path;
396 0 };
397 }
398  
399  
400 sub _dur_max_incl($$$)
401 0 ▶{ my ($path, $args, $max) = @_;
Subroutine _dur_max_incl: not called CC=1 SCAR=6.9
402 0 my $secs = duration2secs $max;
403  
404 0 ▶ sub { return $_[0] if duration2secs $_[0] <= $secs;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if &duration2secs($_[0]) <= $secs 0 0 0
405 0 error __x"too large maxInclusive duration {value}, max {max} at {where}"
406 , value => $_[0], max => $max, where => $path;
407 0 };
408 }
409  
410  
411 sub _dur_max_excl($$$)
412 0 ▶{ my ($path, $args, $max) = @_;
Subroutine _dur_max_excl: not called CC=1 SCAR=6.9
413 0 my $secs = duration2secs $max;
414  
415 0 ▶ sub { return $_[0] if duration2secs $_[0] < $secs;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if &duration2secs($_[0]) < $secs 0 0 0
416 0 error __x"too large maxExclusive duration {value}, max {max} at {where}"
417 , value => $_[0], max => $max, where => $path;
418 0 };
419 }
420  
421 50 1;
« Compile/Translate/Writer.pm ↑ Summary Compile/Schema/Specs.pm »