Corvus/Formats.pm

filter: Statementstmt 17.5% 61 / 347 Branchbran 2.1% 6 / 274 Conditioncond 0.8% 2 / 238 MC/DCmcdc 0.7% 1 / 134 Subroutinesub 21.8% 12 / 55 Podpod 0.0% 0 / 22 totaltotal 7.6% 82 / 1070 CC 224 SCAR 55.5
CC
224
Cov
8%
_idn_label_ok
1260.0
idn_hostname
306.0
_bidi_label_ok
272.0
CRAP 257.8
« Corvus/Collecting.pm ↑ Summary Corvus/Regex/Linear.pm »
1 package JSON::Schema::Corvus::Formats;
2  
3 # Format assertions, applied only when format is asserted (the format-assertion vocabulary, or assert_format). A port
4 # of the Python package's formats.py; Perl's regular expressions have the Unicode properties and scripts that the
5 # Python package takes from the regex package.
6  
7 4 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Math::BigInt ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use JSON::Schema::Corvus::Json ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub _ascii { $_[0] !~ /[^\x00-\x7f]/ }
Subroutine _ascii: not called CC=1 SCAR=6.9
14  
15 4 my @DAYS = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
16  
17 0 ▶sub _is_leap_year { my ($y) = @_; $y % 4 == 0 && ($y % 100 != 0 || $y % 400 == 0) }
Subroutine _is_leap_year: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
$y % 4 == 0 and $y % 100 != 0 || $y % 400 == 0 0 0 0
Condition0%0/6
$y % 4 == 0 && ($y % 100 != 0 || $y % 400 == 0)
!ll&&!rl&&r
000
$y % 100 != 0 or $y % 400 == 0
l!l&&r!l&&!r
000
MC/DC0%0/3
$y % 4 == 0 && ($y % 100 != 0 || $y % 400 == 0)
$y % 4 == 0 $y % 100 != 0 $y % 400 == 0
Truth table0%0/4
A && B or C
A= $y % 4 == 0B= $y % 100 != 0C= $y % 400 == 0
ABCresult
0XX0
1000
11X1
1011
18  
19 0 ▶sub date {
Subroutine date: not called CC=8 SCAR=42.8
Pod undocumented
20 0 my ($s) = @_;
21 0 ▶ my ($y, $mo, $d) = $s =~ /\A([0-9]{4})-([0-9]{2})-([0-9]{2})\z/ or return 0;
Branch: 1 branch
BranchTrueFalseTotal
() = $s =~ /\A([0-9]{4})-([0-9]{2})-([0-9]{2})\z/u or return 0 0 0 0
22 0 ▶ return $mo >= 1 && $mo <= 12 && $d >= 1 && $d <= ($mo == 2 && _is_leap_year($y) ? 29 : $DAYS[$mo]) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$mo >= 1 && $mo <= 12 && $d >= 1 && $d <= ($mo == 2 && _is_leap_year($y) ? 29 : $DAYS[$mo]) ? : 0 0 0
$mo == 2 && _is_leap_year($y) ? : 0 0 0
Condition0%0/12
$mo >= 1 and $mo <= 12 and $d >= 1 and $d <= ($mo == 2 && _is_leap_year($y) ? 29 : $DAYS[$mo])
!ll&&!rl&&r
000
$mo >= 1 and $mo <= 12 and $d >= 1
!ll&&!rl&&r
000
$mo >= 1 and $mo <= 12
!ll&&!rl&&r
000
$mo == 2 and _is_leap_year($y)
!ll&&!rl&&r
000
MC/DC0%0/4
$mo >= 1 and $mo <= 12 and $d >= 1 and $d <= ($mo == 2 && _is_leap_year($y) ? 29 : $DAYS[$mo])
$mo >= 1 $mo <= 12 $d >= 1 $d <= ($mo == 2 && _is_leap_year($y) ? 29 : $DAYS[$mo])
MC/DC0%0/2
$mo == 2 and _is_leap_year($y)
$mo == 2 _is_leap_year($y)
Truth table0%0/5
A and B and C and D
A= $mo >= 1B= $mo <= 12C= $d >= 1D= $d <= ($mo == 2 && _is_leap_year($y) ? 29 : $DAYS[$mo])
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/3
A and B
A= $mo == 2B= _is_leap_year($y)
ABresult
0X0
100
111
23 }
24  
25 0 ▶sub time_format {
Subroutine time_format: not called CC=14 SCAR=53.5
Pod undocumented
26 0 my ($s) = @_;
27 0 ▶ my ($h, $mi, $sec, undef, undef, $sign, $oh, $om)
Branch: 1 branch
BranchTrueFalseTotal
() = $s =~ /\A([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]+)?([zZ]|([+-])([0-9]{2}):([0-9]{2}))\z/u or return 0 0 0 0
28 = $s =~ /\A([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]+)?([zZ]|([+-])([0-9]{2}):([0-9]{2}))\z/ or return 0;
29 0 ▶ $oh //= 0;
Condition0%0/2
$oh //= 0
l!l
00
MC/DC0%0/1
$oh //= 0
$oh
Truth table0%0/2
A
A= $oh
Aresult
11
00
30 0 ▶ $om //= 0;
Condition0%0/2
$om //= 0
l!l
00
MC/DC0%0/1
$om //= 0
$om
Truth table0%0/2
A
A= $om
Aresult
11
00
31 0 ▶ if (defined $sign) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sign) 0 0 0
32 0 ▶ return 0 if $oh > 23 || $om > 59;
Branch: 1 branch
BranchTrueFalseTotal
if $oh > 23 or $om > 59 0 0 0
Condition0%0/3
$oh > 23 or $om > 59
l!l&&r!l&&!r
000
MC/DC0%0/2
$oh > 23 or $om > 59
$oh > 23 $om > 59
Truth table0%0/3
A or B
A= $oh > 23B= $om > 59
ABresult
1X1
011
000
33 }
34 0 ▶ return 0 if $h > 23 || $mi > 59 || $sec > 60;
Branch: 1 branch
BranchTrueFalseTotal
if $h > 23 or $mi > 59 or $sec > 60 0 0 0
Condition0%0/6
$h > 23 or $mi > 59 or $sec > 60
l!l&&r!l&&!r
000
$h > 23 or $mi > 59
l!l&&r!l&&!r
000
MC/DC0%0/3
$h > 23 or $mi > 59 or $sec > 60
$h > 23 $mi > 59 $sec > 60
Truth table0%0/4
A or B or C
A= $h > 23B= $mi > 59C= $sec > 60
ABCresult
1XX1
01X1
0011
0000
35 0 ▶ if ($sec == 60) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sec == 60) 0 0 0
36 # A leap second is valid only at 23:59:60 UTC.
37 0 ▶ my $direction = defined $sign && $sign eq '-' ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $sign && $sign eq '-' ? : 0 0 0
Condition0%0/3
defined $sign and $sign eq "-"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $sign and $sign eq "-"
defined $sign $sign eq "-"
Truth table0%0/3
A and B
A= defined $signB= $sign eq "-"
ABresult
0X0
100
111
38 0 my $utc_minutes = ($h * 60 + $mi + $direction * ($oh * 60 + $om)) % 1440;
39 0 ▶ return $utc_minutes == 23 * 60 + 59 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$utc_minutes == 1439 ? : 0 0 0
40 }
41 0 return 1;
42 }
43  
44 0 ▶sub date_time {
Subroutine date_time: not called CC=5 SCAR=34.0
Pod undocumented
45 0 my ($s) = @_;
46 0 ▶ my $t = $s =~ /[tT]/g ? pos($s) - 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /[tT]/gu ? : 0 0 0
47 0 ▶ return $t == 10 && date(substr($s, 0, 10)) && time_format(substr($s, 11)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$t == 10 && date(substr($s, 0, 10)) && time_format(substr($s, 11)) ? : 0 0 0
Condition0%0/6
$t == 10 and date(substr($s, 0, 10)) and time_format(substr($s, 11))
!ll&&!rl&&r
000
$t == 10 and date(substr($s, 0, 10))
!ll&&!rl&&r
000
MC/DC0%0/3
$t == 10 and date(substr($s, 0, 10)) and time_format(substr($s, 11))
$t == 10 date(substr($s, 0, 10)) time_format(substr($s, 11))
Truth table0%0/4
A and B and C
A= $t == 10B= date(substr($s, 0, 10))C= time_format(substr($s, 11))
ABCresult
0XX0
10X0
1100
1111
48 }
49  
50 # RFC 3339 appendix A: dur-year = 1*DIGIT "Y" [dur-month], dur-month = 1*DIGIT "M" [dur-day], and so on.
51 4 my $DUR_TIME = qr/(?:[0-9]+H(?:[0-9]+M(?:[0-9]+S)?)?|[0-9]+M(?:[0-9]+S)?|[0-9]+S)/;
52 4 my $DURATION_RE = qr/\AP(?:[0-9]+W|(?:[0-9]+Y(?:[0-9]+M(?:[0-9]+D)?)?|[0-9]+M(?:[0-9]+D)?|[0-9]+D)(?:T$DUR_TIME)?|T$DUR_TIME)\z/;
53  
54 0 ▶sub duration { $_[0] =~ $DURATION_RE ? 1 : 0 }
Subroutine duration: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /$DURATION_RE/u ? : 0 0 0
55  
56 0 ▶sub uuid { $_[0] =~ /\A[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\z/ ? 1 : 0 }
Subroutine uuid: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /\A[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\z/u ? : 0 0 0
57  
58 4 my $DEC_OCTET = qr/(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])/;
59  
60 0 ▶sub ipv4 { $_[0] =~ /\A(?:$DEC_OCTET\.){3}$DEC_OCTET\z/ ? 1 : 0 }
Subroutine ipv4: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /\A(?:$DEC_OCTET\.){3}$DEC_OCTET\z/u ? : 0 0 0
61  
62 0 ▶sub ipv6 {
Subroutine ipv6: not called CC=12 SCAR=50.5
Pod undocumented
63 0 my ($s) = @_;
64 0 ▶ return 0 if length $s < 2 || $s !~ /\A[0-9a-fA-F:.]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if length $s < 2 or not $s =~ /\A[0-9a-fA-F:.]+\z/u 0 0 0
Condition0%0/3
length $s < 2 or not $s =~ /\A[0-9a-fA-F:.]+\z/u
l!l&&r!l&&!r
000
MC/DC0%0/2
length $s < 2 or not $s =~ /\A[0-9a-fA-F:.]+\z/u
length $s < 2 not $s =~ /\A[0-9a-fA-F:.]+\z/u
Truth table0%0/3
A or not(B)
A= length $s < 2B= not $s =~ /\A[0-9a-fA-F:.]+\z/u
ABresult
1X1
011
000
65 0 my $groups = 8;
66 0 my $tail = $s;
67 0 my $last_colon = rindex($s, ':');
68 0 ▶ if (index($s, '.') >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($s, ".") != -1) 0 0 0
69 0 ▶ return 0 unless ipv4(substr($s, $last_colon + 1));
Branch: 1 branch
BranchTrueFalseTotal
unless ipv4(substr($s, $last_colon + 1)) 0 0 0
70 0 $tail = substr($s, 0, $last_colon + 1) . '0:0';
71 }
72 0 my $dbl = index($tail, '::');
73 0 ▶ return 0 if $dbl >= 0 && index($tail, '::', $dbl + 1) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $dbl >= 0 and index($tail, "::", $dbl + 1) != -1 0 0 0
Condition0%0/3
$dbl >= 0 and index($tail, "::", $dbl + 1) != -1
!ll&&!rl&&r
000
MC/DC0%0/2
$dbl >= 0 and index($tail, "::", $dbl + 1) != -1
$dbl >= 0 index($tail, "::", $dbl + 1) != -1
Truth table0%0/3
A and B
A= $dbl >= 0B= index($tail, "::", $dbl + 1) != -1
ABresult
0X0
100
111
74 0 ▶ my $parts = sub { $_[0] eq '' ? () : split /:/, $_[0], -1 };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq '' ? : 0 0 0
75 0 ▶ my $hex_ok = sub { $_[0] =~ /\A[0-9a-fA-F]{1,4}\z/ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 0 ▶ if ($dbl >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbl >= 0) 0 0 0
77 0 my @left = $parts->(substr($tail, 0, $dbl));
78 0 my @right = $parts->(substr($tail, $dbl + 2));
79 0 ▶ return (!grep { !$hex_ok->($_) } @left, @right) && @left + @right < $groups ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!grep({not &$hex_ok($_);} @left, @right) && @left + @right < $groups ? : 0 0 0
Condition0%0/3
not grep({not &$hex_ok($_);} @left, @right) and @left + @right < $groups
!ll&&!rl&&r
000
MC/DC0%0/2
not grep({not &$hex_ok($_);} @left, @right) and @left + @right < $groups
not grep({not &$hex_ok($_);} @left, @right) @left + @right < $groups
Truth table0%0/3
not(A) and B
A= not grep({not &$hex_ok($_);} @left, @right)B= @left + @right < $groups
ABresult
0X0
100
111
80 }
81 0 my @every = split /:/, $tail, -1;
82 0 ▶ return @every == $groups && !(grep { !$hex_ok->($_) } @every) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@every == $groups && !grep({not &$hex_ok($_);} @every) ? : 0 0 0
Condition0%0/3
@every == $groups and not grep({not &$hex_ok($_);} @every)
!ll&&!rl&&r
000
MC/DC0%0/2
@every == $groups and not grep({not &$hex_ok($_);} @every)
@every == $groups not grep({not &$hex_ok($_);} @every)
Truth table0%0/3
A and not(B)
A= @every == $groupsB= not grep({not &$hex_ok($_);} @every)
ABresult
0X0
100
111
83 }
84  
85 4 my $LABEL_RE = qr/\A[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\z/;
86  
87 0 ▶sub _is_a_label { lc(substr($_[0], 0, 4)) eq 'xn--' }
Subroutine _is_a_label: not called CC=1 SCAR=6.9
88  
89 0 ▶sub _hostname_label_ok {
Subroutine _hostname_label_ok: not called CC=7 SCAR=40.3
90 0 my ($label) = @_;
91 0 ▶ return 0 if length $label == 0 || length $label > 63 || $label !~ $LABEL_RE;
Branch: 1 branch
BranchTrueFalseTotal
if length $label == 0 or length $label > 63 or not $label =~ /$LABEL_RE/u 0 0 0
Condition0%0/6
length $label == 0 or length $label > 63 or not $label =~ /$LABEL_RE/u
l!l&&r!l&&!r
000
length $label == 0 or length $label > 63
l!l&&r!l&&!r
000
MC/DC0%0/3
length $label == 0 or length $label > 63 or not $label =~ /$LABEL_RE/u
length $label == 0 length $label > 63 not $label =~ /$LABEL_RE/u
Truth table0%0/4
A or B or not(C)
A= length $label == 0B= length $label > 63C= not $label =~ /$LABEL_RE/u
ABCresult
1XX1
01X1
0011
0000
92 # "--" in the third and fourth positions is reserved for A-labels (xn--).
93 0 ▶ return !(length $label >= 4 && substr($label, 2, 2) eq '--' && !_is_a_label($label)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!(length $label >= 4 && substr($label, 2, 2) eq '--' && !_is_a_label($label)) ? : 0 0 0
Condition0%0/6
length $label >= 4 && substr($label, 2, 2) eq '--' && !_is_a_label($label)
!ll&&!rl&&r
000
length $label >= 4 and substr($label, 2, 2) eq "--"
!ll&&!rl&&r
000
MC/DC0%0/3
length $label >= 4 && substr($label, 2, 2) eq '--' && !_is_a_label($label)
length $label >= 4 substr($label, 2, 2) eq "--" !_is_a_label($label)
Truth table0%0/4
A and B && not(C)
A= length $label >= 4B= substr($label, 2, 2) eq "--"C= !_is_a_label($label)
ABCresult
0XX0
10X0
1100
1111
94 }
95  
96 # RFC 1123 host names (draft 4 and 6): no IDNA rules for "--" or A-labels.
97 0 ▶sub legacy_hostname {
Subroutine legacy_hostname: not called CC=7 SCAR=40.3
Pod undocumented
98 0 my ($s) = @_;
99 0 ▶ return 0 if length $s == 0 || length $s > 253;
Branch: 1 branch
BranchTrueFalseTotal
if length $s == 0 or length $s > 253 0 0 0
Condition0%0/3
length $s == 0 or length $s > 253
l!l&&r!l&&!r
000
MC/DC0%0/2
length $s == 0 or length $s > 253
length $s == 0 length $s > 253
Truth table0%0/3
A or B
A= length $s == 0B= length $s > 253
ABresult
1X1
011
000
100 0 for my $label (split /\./, $s, -1) {
101 0 ▶ return 0 unless length $label > 0 && length $label <= 63 && $label =~ $LABEL_RE;
Branch: 1 branch
BranchTrueFalseTotal
unless length $label > 0 and length $label <= 63 and $label =~ /$LABEL_RE/u 0 0 0
Condition0%0/6
length $label > 0 and length $label <= 63 and $label =~ /$LABEL_RE/u
!ll&&!rl&&r
000
length $label > 0 and length $label <= 63
!ll&&!rl&&r
000
MC/DC0%0/3
length $label > 0 and length $label <= 63 and $label =~ /$LABEL_RE/u
length $label > 0 length $label <= 63 $label =~ /$LABEL_RE/u
Truth table0%0/4
A and B and C
A= length $label > 0B= length $label <= 63C= $label =~ /$LABEL_RE/u
ABCresult
0XX0
10X0
1100
1111
102 }
103 0 return 1;
104 }
105  
106 0 ▶sub hostname {
Subroutine hostname: not called CC=7 SCAR=40.3
Pod undocumented
107 0 my ($s) = @_;
108 0 ▶ return 0 if length $s == 0 || length $s > 253;
Branch: 1 branch
BranchTrueFalseTotal
if length $s == 0 or length $s > 253 0 0 0
Condition0%0/3
length $s == 0 or length $s > 253
l!l&&r!l&&!r
000
MC/DC0%0/2
length $s == 0 or length $s > 253
length $s == 0 length $s > 253
Truth table0%0/3
A or B
A= length $s == 0B= length $s > 253
ABresult
1X1
011
000
109 0 for my $label (split /\./, $s, -1) {
110 0 ▶ return 0 unless _hostname_label_ok($label);
Branch: 1 branch
BranchTrueFalseTotal
unless _hostname_label_ok($label) 0 0 0
111 0 ▶ return 0 if _is_a_label($label) && !_punycode_label_ok(substr($label, 4));
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_label($label) and not _punycode_label_ok(substr($label, 4)) 0 0 0
Condition0%0/3
_is_a_label($label) and not _punycode_label_ok(substr($label, 4))
!ll&&!rl&&r
000
MC/DC0%0/2
_is_a_label($label) and not _punycode_label_ok(substr($label, 4))
_is_a_label($label) not _punycode_label_ok(substr($label, 4))
Truth table0%0/3
A and not(B)
A= _is_a_label($label)B= not _punycode_label_ok(substr($label, 4))
ABresult
0X0
100
111
112 }
113 0 return 1;
114 }
115  
116 0 ▶sub _punycode_label_ok {
Subroutine _punycode_label_ok: not called CC=8 SCAR=42.8
117 0 my ($encoded) = @_;
118 0 my $decoded = _punycode_decode($encoded);
119 0 ▶ return 0 if !defined $decoded || length $decoded == 0 || _ascii($decoded);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $decoded or length $decoded == 0 or _ascii($decoded) 0 0 0
Condition0%0/6
not defined $decoded or length $decoded == 0 or _ascii($decoded)
l!l&&r!l&&!r
000
not defined $decoded or length $decoded == 0
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $decoded or length $decoded == 0 or _ascii($decoded)
not defined $decoded length $decoded == 0 _ascii($decoded)
Truth table0%0/4
not(A) or B or C
A= not defined $decodedB= length $decoded == 0C= _ascii($decoded)
ABCresult
1XX1
01X1
0011
0000
120 # The encoding must be canonical: encoding the U-label again gives the same A-label.
121 0 ▶ return 0 if _punycode_encode($decoded) ne lc $encoded;
Branch: 1 branch
BranchTrueFalseTotal
if _punycode_encode($decoded) ne lc $encoded 0 0 0
122 0 ▶ return _idn_label_ok($decoded) && !_disallowed(_strip_exceptions($decoded))
Branch: 1 branch
BranchTrueFalseTotal
_idn_label_ok($decoded) && !_disallowed(_strip_exceptions($decoded)) && _bidi_label_ok($decoded, _bidi_domain($decoded)) ? : 0 0 0
Condition0%0/6
_idn_label_ok($decoded) and not _disallowed(_strip_exceptions($decoded)) and _bidi_label_ok($decoded, _bidi_domain($decoded))
!ll&&!rl&&r
000
_idn_label_ok($decoded) and not _disallowed(_strip_exceptions($decoded))
!ll&&!rl&&r
000
MC/DC0%0/3
_idn_label_ok($decoded) and not _disallowed(_strip_exceptions($decoded)) and _bidi_label_ok($decoded, _bidi_domain($decoded))
_idn_label_ok($decoded) not _disallowed(_strip_exceptions($decoded)) _bidi_label_ok($decoded, _bidi_domain($decoded))
Truth table0%0/4
A and not(B) and C
A= _idn_label_ok($decoded)B= not _disallowed(_strip_exceptions($decoded))C= _bidi_label_ok($decoded, _bidi_domain($decoded))
ABCresult
0XX0
10X0
1100
1111
123 && _bidi_label_ok($decoded, _bidi_domain($decoded)) ? 1 : 0;
124 }
125  
126 # Code points IDNA2008 disallows that the tests exercise: controls, format characters, spaces, unassigned, uppercase
127 # and titlecase letters (mapped away, never PVALID), and symbols.
128 0 ▶sub _strip_exceptions { (my $s = $_[0]) =~ s/[\x{06fd}\x{06fe}\x{0f0b}\x{00b7}\x{05f3}\x{05f4}\x{30fb}\-]//g; $s }
Subroutine _strip_exceptions: not called CC=1 SCAR=6.9
129 0 ▶sub _disallowed { $_[0] =~ /[\p{Cc}\p{Cs}\p{Co}\p{Cn}\p{Zs}\p{Zl}\p{Zp}\p{Lu}\p{Lt}\p{Sm}\p{So}\p{P}]/ }
Subroutine _disallowed: not called CC=1 SCAR=6.9
130  
131 4 ▶use constant { BASE => 36, T_MIN => 1, T_MAX => 26, SKEW => 38, DAMP => 700 };
Subroutine BEGIN: called CC=1 SCAR=0.0
132  
133 0 ▶sub _adapt {
Subroutine _adapt: not called CC=3 SCAR=24.8
134 0 my ($delta, $num_points, $first_time) = @_;
135 0 ▶ $delta = $first_time ? int($delta / DAMP) : $delta >> 1;
Branch: 1 branch
BranchTrueFalseTotal
$first_time ? : 0 0 0
136 0 $delta += int($delta / $num_points);
137 0 my $k = 0;
138 0 ▶ while ($delta > ((BASE - T_MIN) * T_MAX) >> 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delta > 455) 0 0 0
139 0 $delta = int($delta / (BASE - T_MIN));
140 0 $k += BASE;
141 }
142 0 return $k + int(((BASE - T_MIN + 1) * $delta) / ($delta + SKEW));
143 }
144  
145 # RFC 3492 encoding, for the canonical round trip and the A-label length checks.
146 0 ▶sub _punycode_encode {
Subroutine _punycode_encode: not called CC=13 SCAR=52.0
147 0 my ($text) = @_;
148 0 my @cps = map { ord } split //, $text;
149 0 my $out = join '', map { chr } grep { $_ < 0x80 } @cps;
150 0 my $basic_length = length $out;
151 0 my $h = $basic_length;
152 0 ▶ $out .= '-' if $basic_length > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $basic_length > 0 0 0 0
153 0 my ($n, $delta, $bias) = (128, 0, 72);
154 0 ▶ my $digit = sub { chr($_[0] < 26 ? $_[0] + 97 : $_[0] + 22) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] < 26 ? : 0 0 0
155 0 ▶ while ($h < @cps) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h < @cps) 0 0 0
156 0 my $m;
157 0 ▶ for (@cps) { $m = $_ if $_ >= $n && (!defined $m || $_ < $m) }
Branch: 1 branch
BranchTrueFalseTotal
if $_ >= $n and !defined($m) || $_ < $m 0 0 0
Condition0%0/6
$_ >= $n and !defined($m) || $_ < $m
!ll&&!rl&&r
000
not defined $m or $_ < $m
l!l&&r!l&&!r
000
MC/DC0%0/3
$_ >= $n and !defined($m) || $_ < $m
$_ >= $n not defined $m $_ < $m
Truth table0%0/4
A and not(B) or C
A= $_ >= $nB= not defined $mC= $_ < $m
ABCresult
0XX0
1000
11X1
1011
158 0 $delta += ($m - $n) * ($h + 1);
159 0 $n = $m;
160 0 for my $c (@cps) {
161 0 ▶ $delta++ if $c < $n;
Branch: 1 branch
BranchTrueFalseTotal
if $c < $n 0 0 0
162 0 ▶ if ($c == $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c == $n) 0 0 0
163 0 my $q = $delta;
164 0 my $k = BASE;
165 0 while (1) {
166 0 ▶ my $t = $k <= $bias ? T_MIN : $k >= $bias + T_MAX ? T_MAX : $k - $bias;
Branch: 2 branches
BranchTrueFalseTotal
$k <= $bias ? : 0 0 0
$k >= $bias + 26 ? : 0 0 0
167 0 ▶ last if $q < $t;
Branch: 1 branch
BranchTrueFalseTotal
if $q < $t 0 0 0
168 0 $out .= $digit->($t + ($q - $t) % (BASE - $t));
169 0 $q = int(($q - $t) / (BASE - $t));
170 0 $k += BASE;
171 }
172 0 $out .= $digit->($q);
173 0 $bias = _adapt($delta, $h + 1, $h == $basic_length);
174 0 $delta = 0;
175 0 $h++;
176 }
177 }
178 0 $delta++;
179 0 $n++;
180 }
181 0 return $out;
182 }
183  
184 # The RFC 5893 Bidi rule, with Bidi classes approximated by script and general category, as the TypeScript evaluator
185 # does.
186 0 ▶sub _bidi_class {
Subroutine _bidi_class: not called CC=13 SCAR=52.0
187 0 my ($c) = @_;
188 0 my $cp = ord $c;
189 0 ▶ return 'NSM' if $c =~ /\A[\p{Mn}\p{Me}]/;
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /\A[\p{Mn}\p{Me}]/u 0 0 0
190 0 ▶ return 'AN' if ($cp >= 0x660 && $cp <= 0x669) || $cp == 0x66B || $cp == 0x66C;
Branch: 1 branch
BranchTrueFalseTotal
if $cp >= 1632 and $cp <= 1641 or $cp == 1643 or $cp == 1644 0 0 0
Condition0%0/9
$cp >= 1632 and $cp <= 1641 or $cp == 1643 or $cp == 1644
l!l&&r!l&&!r
000
$cp >= 1632 and $cp <= 1641 or $cp == 1643
l!l&&r!l&&!r
000
$cp >= 1632 and $cp <= 1641
!ll&&!rl&&r
000
MC/DC0%0/4
$cp >= 1632 and $cp <= 1641 or $cp == 1643 or $cp == 1644
$cp >= 1632 $cp <= 1641 $cp == 1643 $cp == 1644
Truth table0%0/7
A and B or C or D
A= $cp >= 1632B= $cp <= 1641C= $cp == 1643D= $cp == 1644
ABCDresult
11XX1
0X1X1
101X1
0X011
10011
0X000
10000
191 0 ▶ return 'EN' if ($cp >= 0x30 && $cp <= 0x39) || ($cp >= 0x6F0 && $cp <= 0x6F9);
Branch: 1 branch
BranchTrueFalseTotal
if $cp >= 48 and $cp <= 57 or $cp >= 1776 and $cp <= 1785 0 0 0
Condition0%0/9
$cp >= 48 and $cp <= 57 or $cp >= 1776 and $cp <= 1785
l!l&&r!l&&!r
000
$cp >= 48 and $cp <= 57
!ll&&!rl&&r
000
$cp >= 1776 and $cp <= 1785
!ll&&!rl&&r
000
MC/DC0%0/4
$cp >= 48 and $cp <= 57 or $cp >= 1776 and $cp <= 1785
$cp >= 48 $cp <= 57 $cp >= 1776 $cp <= 1785
Truth table0%0/7
A and B or C and D
A= $cp >= 48B= $cp <= 57C= $cp >= 1776D= $cp <= 1785
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
192 0 ▶ return 'R' if $c =~ /\A\p{Script=Hebrew}/;
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /\A\p{Script=Hebrew}/u 0 0 0
193 0 ▶ return 'AL' if $c =~ /\A[\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}]/;
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /\A[\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}]/u 0 0 0
194 0 ▶ return 'L' if $c =~ /\A[\p{L}\p{Mc}]/;
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /\A[\p{L}\p{Mc}]/u 0 0 0
195 0 return 'ON';
196 }
197  
198 0 ▶sub _bidi_domain {
Subroutine _bidi_domain: not called CC=6 SCAR=37.4
199 0 my ($label) = @_;
200 0 ▶ return 0 unless $label =~ /[\p{Script=Hebrew}\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\x{0660}-\x{0669}\x{066b}\x{066c}]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $label =~ /[\p{Script=Hebrew}\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\x{0660}-\x{0669}\x{066b}\x{066c}]/u 0 0 0
201 0 for my $c (split //, $label) {
202 0 my $class = _bidi_class($c);
203 0 ▶ return 1 if $class eq 'R' || $class eq 'AL' || $class eq 'AN';
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "R" or $class eq "AL" or $class eq "AN" 0 0 0
Condition0%0/6
$class eq "R" or $class eq "AL" or $class eq "AN"
l!l&&r!l&&!r
000
$class eq "R" or $class eq "AL"
l!l&&r!l&&!r
000
MC/DC0%0/3
$class eq "R" or $class eq "AL" or $class eq "AN"
$class eq "R" $class eq "AL" $class eq "AN"
Truth table0%0/4
A or B or C
A= $class eq "R"B= $class eq "AL"C= $class eq "AN"
ABCresult
1XX1
01X1
0011
0000
204 }
205 0 return 0;
206 }
207  
208 0 ▶sub _bidi_label_ok {
Subroutine _bidi_label_ok: not called CC=16 SCAR=56.1
209 0 my ($label, $is_bidi_domain) = @_;
210 0 ▶ return 1 unless $is_bidi_domain;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_bidi_domain 0 0 0
211 0 my @classes = map { _bidi_class($_) } split //, $label;
212 0 my $first = $classes[0];
213 0 my $last = $#classes;
214 0 ▶ $last-- while $last > 0 && $classes[$last] eq 'NSM';
Branch: 1 branch
BranchTrueFalseTotal
$last > 0 and $classes[$last] eq "NSM" and do { --$last } 0 0 0
Condition0%0/3
$last > 0 and $classes[$last] eq "NSM"
!ll&&!rl&&r
000
MC/DC0%0/2
$last > 0 and $classes[$last] eq "NSM"
$last > 0 $classes[$last] eq "NSM"
Truth table0%0/3
A and B
A= $last > 0B= $classes[$last] eq "NSM"
ABresult
0X0
100
111
215 0 my %has = map { $_ => 1 } @classes;
216 0 ▶ if ($first eq 'R' || $first eq 'AL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($first eq "R" or $first eq "AL") 0 0 0
Condition0%0/3
$first eq "R" or $first eq "AL"
l!l&&r!l&&!r
000
MC/DC0%0/2
$first eq "R" or $first eq "AL"
$first eq "R" $first eq "AL"
Truth table0%0/3
A or B
A= $first eq "R"B= $first eq "AL"
ABresult
1X1
011
000
217 0 ▶ return 0 if $has{L};
Branch: 1 branch
BranchTrueFalseTotal
if $has{"L"} 0 0 0
218 0 ▶ return 0 unless $classes[$last] =~ /\A(?:R|AL|EN|AN)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $classes[$last] =~ /\A(?:R|AL|EN|AN)\z/u 0 0 0
219 0 ▶ return !($has{EN} && $has{AN}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!($has{'EN'} && $has{'AN'}) ? : 0 0 0
Condition0%0/3
$has{'EN'} && $has{'AN'}
!ll&&!rl&&r
000
MC/DC0%0/2
$has{'EN'} && $has{'AN'}
$has{'EN'} $has{'AN'}
Truth table0%0/3
A && B
A= $has{'EN'}B= $has{'AN'}
ABresult
0X0
100
111
220 }
221 0 ▶ if ($first eq 'L') {
Branch: 1 branch
BranchTrueFalseTotal
if ($first eq "L") 0 0 0
222 0 ▶ return 0 if $has{R} || $has{AL} || $has{AN};
Branch: 1 branch
BranchTrueFalseTotal
if $has{"R"} or $has{"AL"} or $has{"AN"} 0 0 0
Condition0%0/6
$has{"R"} or $has{"AL"} or $has{"AN"}
l!l&&r!l&&!r
000
$has{"R"} or $has{"AL"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$has{"R"} or $has{"AL"} or $has{"AN"}
$has{"R"} $has{"AL"} $has{"AN"}
Truth table0%0/4
A or B or C
A= $has{"R"}B= $has{"AL"}C= $has{"AN"}
ABCresult
1XX1
01X1
0011
0000
223 0 ▶ return $classes[$last] eq 'L' || $classes[$last] eq 'EN' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$classes[$last] eq 'L' || $classes[$last] eq 'EN' ? : 0 0 0
Condition0%0/3
$classes[$last] eq "L" or $classes[$last] eq "EN"
l!l&&r!l&&!r
000
MC/DC0%0/2
$classes[$last] eq "L" or $classes[$last] eq "EN"
$classes[$last] eq "L" $classes[$last] eq "EN"
Truth table0%0/3
A or B
A= $classes[$last] eq "L"B= $classes[$last] eq "EN"
ABresult
1X1
011
000
224 }
225 0 return 0;
226 }
227  
228 # RFC 3492 decoding, enough to validate A-labels.
229 0 ▶sub _punycode_decode {
Subroutine _punycode_decode: not called CC=16 SCAR=54.7
230 0 my ($text) = @_;
231 0 my ($n, $i, $bias) = (128, 0, 72);
232 0 my @output;
233 0 my $basic = rindex($text, '-');
234 0 ▶ $basic = 0 if $basic < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $basic < 0 0 0 0
235 0 for my $j (0 .. $basic - 1) {
236 0 my $c = ord substr($text, $j, 1);
237 0 ▶ return undef if $c >= 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $c >= 128 0 0 0
238 0 push @output, $c;
239 }
240 0 ▶ my $index = $basic > 0 ? $basic + 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$basic > 0 ? : 0 0 0
241 0 ▶ while ($index < length $text) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < length $text) 0 0 0
242 0 my $oldi = $i;
243 0 my $w = 1;
244 0 my $k = BASE;
245 0 while (1) {
246 0 ▶ return undef if $index >= length $text;
Branch: 1 branch
BranchTrueFalseTotal
if $index >= length $text 0 0 0
247 0 my $c = ord substr($text, $index++, 1);
248 0 ▶ my $digit = $c - 48 < 10 ? $c - 22 : $c - 65 < 26 ? $c - 65 : $c - 97 < 26 ? $c - 97 : BASE;
Branch: 3 branches
BranchTrueFalseTotal
$c - 48 < 10 ? : 0 0 0
$c - 65 < 26 ? : 0 0 0
$c - 97 < 26 ? : 0 0 0
249 0 ▶ return undef if $digit < 0 || $digit >= BASE;
Branch: 1 branch
BranchTrueFalseTotal
if $digit < 0 or $digit >= 36 0 0 0
Condition0%0/3
$digit < 0 or $digit >= 36
l!l&&r!l&&!r
000
MC/DC0%0/2
$digit < 0 or $digit >= 36
$digit < 0 $digit >= 36
Truth table0%0/3
A or B
A= $digit < 0B= $digit >= 36
ABresult
1X1
011
000
250 0 $i += $digit * $w;
251 0 ▶ my $t = $k <= $bias ? T_MIN : $k >= $bias + T_MAX ? T_MAX : $k - $bias;
Branch: 2 branches
BranchTrueFalseTotal
$k <= $bias ? : 0 0 0
$k >= $bias + 26 ? : 0 0 0
252 0 ▶ last if $digit < $t;
Branch: 1 branch
BranchTrueFalseTotal
if $digit < $t 0 0 0
253 0 $w *= BASE - $t;
254 0 $k += BASE;
255 }
256 0 $bias = _adapt($i - $oldi, @output + 1, $oldi == 0);
257 0 $n += int($i / (@output + 1));
258 0 $i %= @output + 1;
259 0 ▶ return undef if $n > 0x10FFFF;
Branch: 1 branch
BranchTrueFalseTotal
if $n > 1114111 0 0 0
260 0 splice @output, $i, 0, $n;
261 0 $i++;
262 }
263 4 ▶ no warnings 'surrogate';
Subroutine BEGIN: called CC=1 SCAR=0.0
264 0 return join '', map { chr } @output;
265 }
266  
267 4 my %VIRAMAS = map { $_ => 1 } (
268 0x094D, 0x09CD, 0x0A4D, 0x0ACD, 0x0B4D, 0x0BCD, 0x0C4D, 0x0CCD, 0x0D3B, 0x0D3C, 0x0D4D, 0x0DCA, 0x0E3A, 0x0EBA,
269 0x0F84, 0x1039, 0x103A, 0x1714, 0x1734, 0x17D2, 0x1A60, 0x1B44, 0x1BAA, 0x1BAB, 0x1BF2, 0x1BF3, 0x2D7F, 0xA806,
270 0xA8C4, 0xA953, 0xA9C0, 0xAAF6, 0xABED,
271 );
272  
273 4 my %FORBIDDEN = map { $_ => 1 } (0x302E, 0x302F, 0x0640, 0x07FA, 0x3031, 0x3032, 0x3033, 0x3034, 0x3035, 0x303B);
274  
275 # The contextual and disallowed code points of RFC 5892 that the test suite exercises.
276 0 ▶sub _idn_label_ok {
Subroutine _idn_label_ok: not called CC=35 SCAR=71.4
277 0 my ($label) = @_;
278 0 ▶ return 0 if length $label == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $label == 0 0 0 0
279 0 ▶ return 0 if substr($label, 0, 1) eq '-' || substr($label, -1) eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if substr($label, 0, 1) eq "-" or substr($label, -1) eq "-" 0 0 0
Condition0%0/3
substr($label, 0, 1) eq "-" or substr($label, -1) eq "-"
l!l&&r!l&&!r
000
MC/DC0%0/2
substr($label, 0, 1) eq "-" or substr($label, -1) eq "-"
substr($label, 0, 1) eq "-" substr($label, -1) eq "-"
Truth table0%0/3
A or B
A= substr($label, 0, 1) eq "-"B= substr($label, -1) eq "-"
ABresult
1X1
011
000
280 0 ▶ return 0 if length $label >= 4 && substr($label, 2, 2) eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if length $label >= 4 and substr($label, 2, 2) eq "--" 0 0 0
Condition0%0/3
length $label >= 4 and substr($label, 2, 2) eq "--"
!ll&&!rl&&r
000
MC/DC0%0/2
length $label >= 4 and substr($label, 2, 2) eq "--"
length $label >= 4 substr($label, 2, 2) eq "--"
Truth table0%0/3
A and B
A= length $label >= 4B= substr($label, 2, 2) eq "--"
ABresult
0X0
100
111
281 0 my @cps = map { ord } split //, $label;
282 0 ▶ return 0 if $label =~ /\A\p{M}/;
Branch: 1 branch
BranchTrueFalseTotal
if $label =~ /\A\p{M}/u 0 0 0
283 0 ▶ return 0 if (grep { $_ >= 0x660 && $_ <= 0x669 } @cps) && (grep { $_ >= 0x6F0 && $_ <= 0x6F9 } @cps);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ >= 1632 and $_ <= 1641;} @cps and grep {$_ >= 1776 and $_ <= 1785;} @cps 0 0 0
Condition0%0/9
grep {$_ >= 1632 and $_ <= 1641;} @cps and grep {$_ >= 1776 and $_ <= 1785;} @cps
!ll&&!rl&&r
000
$_ >= 1632 && $_ <= 1641
!ll&&!rl&&r
000
$_ >= 1776 && $_ <= 1785
!ll&&!rl&&r
000
MC/DC0%0/2
grep {$_ >= 1632 and $_ <= 1641;} @cps and grep {$_ >= 1776 and $_ <= 1785;} @cps
grep {$_ >= 1632 and $_ <= 1641;} @cps grep {$_ >= 1776 and $_ <= 1785;} @cps
MC/DC0%0/2
$_ >= 1632 && $_ <= 1641
$_ >= 1632 $_ <= 1641
MC/DC0%0/2
$_ >= 1776 && $_ <= 1785
$_ >= 1776 $_ <= 1785
Truth table0%0/3
A and B
A= grep {$_ >= 1632 and $_ <= 1641;} @cpsB= grep {$_ >= 1776 and $_ <= 1785;} @cps
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= $_ >= 1632B= $_ <= 1641
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= $_ >= 1776B= $_ <= 1785
ABresult
0X0
100
111
284 0 for my $i (0 .. $#cps) {
285 0 my $c = $cps[$i];
286 0 ▶ return 0 if $FORBIDDEN{$c};
Branch: 1 branch
BranchTrueFalseTotal
if $FORBIDDEN{$c} 0 0 0
287 0 ▶ if ($c == 0x00B7) {
Branch: 6 branches
BranchTrueFalseTotal
if ($c == 183) { } 0 0 0
elsif ($c == 885) { } 0 0 0
elsif ($c == 1523 or $c == 1524) { } 0 0 0
elsif ($c == 12539) { } 0 0 0
elsif ($c == 8205) { } 0 0 0
elsif ($c == 8204) { } 0 0 0
288 # MIDDLE DOT: between two 'l'.
289 0 ▶ return 0 unless $i > 0 && $i < $#cps && $cps[$i - 1] == 0x6C && $cps[$i + 1] == 0x6C;
Branch: 1 branch
BranchTrueFalseTotal
unless $i > 0 and $i < $#cps and $cps[$i - 1] == 108 and $cps[$i + 1] == 108 0 0 0
Condition0%0/9
$i > 0 and $i < $#cps and $cps[$i - 1] == 108 and $cps[$i + 1] == 108
!ll&&!rl&&r
000
$i > 0 and $i < $#cps and $cps[$i - 1] == 108
!ll&&!rl&&r
000
$i > 0 and $i < $#cps
!ll&&!rl&&r
000
MC/DC0%0/4
$i > 0 and $i < $#cps and $cps[$i - 1] == 108 and $cps[$i + 1] == 108
$i > 0 $i < $#cps $cps[$i - 1] == 108 $cps[$i + 1] == 108
Truth table0%0/5
A and B and C and D
A= $i > 0B= $i < $#cpsC= $cps[$i - 1] == 108D= $cps[$i + 1] == 108
ABCDresult
0XXX0
10XX0
110X0
11100
11111
290 }
291 elsif ($c == 0x0375) {
292 # GREEK KERAIA: followed by Greek.
293 0 ▶ return 0 unless $i < $#cps && chr($cps[$i + 1]) =~ /\p{Script=Greek}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $i < $#cps and chr($cps[$i + 1]) =~ /\p{Script=Greek}/u 0 0 0
Condition0%0/3
$i < $#cps and chr($cps[$i + 1]) =~ /\p{Script=Greek}/u
!ll&&!rl&&r
000
MC/DC0%0/2
$i < $#cps and chr($cps[$i + 1]) =~ /\p{Script=Greek}/u
$i < $#cps chr($cps[$i + 1]) =~ /\p{Script=Greek}/u
Truth table0%0/3
A and B
A= $i < $#cpsB= chr($cps[$i + 1]) =~ /\p{Script=Greek}/u
ABresult
0X0
100
111
294 }
295 ▶ elsif ($c == 0x05F3 || $c == 0x05F4) {
Condition0%0/3
$c == 1523 or $c == 1524
l!l&&r!l&&!r
000
MC/DC0%0/2
$c == 1523 or $c == 1524
$c == 1523 $c == 1524
Truth table0%0/3
A or B
A= $c == 1523B= $c == 1524
ABresult
1X1
011
000
296 # HEBREW GERESH or GERSHAYIM: preceded by Hebrew.
297 0 ▶ return 0 unless $i > 0 && chr($cps[$i - 1]) =~ /\p{Script=Hebrew}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $i > 0 and chr($cps[$i - 1]) =~ /\p{Script=Hebrew}/u 0 0 0
Condition0%0/3
$i > 0 and chr($cps[$i - 1]) =~ /\p{Script=Hebrew}/u
!ll&&!rl&&r
000
MC/DC0%0/2
$i > 0 and chr($cps[$i - 1]) =~ /\p{Script=Hebrew}/u
$i > 0 chr($cps[$i - 1]) =~ /\p{Script=Hebrew}/u
Truth table0%0/3
A and B
A= $i > 0B= chr($cps[$i - 1]) =~ /\p{Script=Hebrew}/u
ABresult
0X0
100
111
298 }
299 elsif ($c == 0x30FB) {
300 # KATAKANA MIDDLE DOT: the label has Hiragana, Katakana or Han.
301 0 ▶ return 0 unless grep { $_ != 0x30FB && chr($_) =~ /[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/ } @cps;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ != 12539 and chr($_) =~ /[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u;} @cps 0 0 0
Condition0%0/3
$_ != 12539 && chr($_) =~ /[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u
!ll&&!rl&&r
000
MC/DC0%0/2
$_ != 12539 && chr($_) =~ /[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u
$_ != 12539 chr($_) =~ /[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u
Truth table0%0/3
A && B
A= $_ != 12539B= chr($_) =~ /[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u
ABresult
0X0
100
111
302 }
303 elsif ($c == 0x200D) {
304 # ZERO WIDTH JOINER: preceded by a virama.
305 0 ▶ return 0 unless $i > 0 && $VIRAMAS{ $cps[$i - 1] };
Branch: 1 branch
BranchTrueFalseTotal
unless $i > 0 and $VIRAMAS{$cps[$i - 1]} 0 0 0
Condition0%0/3
$i > 0 and $VIRAMAS{$cps[$i - 1]}
!ll&&!rl&&r
000
MC/DC0%0/2
$i > 0 and $VIRAMAS{$cps[$i - 1]}
$i > 0 $VIRAMAS{$cps[$i - 1]}
Truth table0%0/3
A and B
A= $i > 0B= $VIRAMAS{$cps[$i - 1]}
ABresult
0X0
100
111
306 }
307 elsif ($c == 0x200C) {
308 # ZERO WIDTH NON-JOINER: preceded by a virama (the joining-type rule is approximated).
309 0 ▶ return 0 unless ($i > 0 && $VIRAMAS{ $cps[$i - 1] }) || _zwnj_joining_context(\@cps, $i);
Branch: 1 branch
BranchTrueFalseTotal
unless $i > 0 and $VIRAMAS{$cps[$i - 1]} or _zwnj_joining_context(\@cps, $i) 0 0 0
Condition0%0/6
$i > 0 and $VIRAMAS{$cps[$i - 1]} or _zwnj_joining_context(\@cps, $i)
l!l&&r!l&&!r
000
$i > 0 and $VIRAMAS{$cps[$i - 1]}
!ll&&!rl&&r
000
MC/DC0%0/3
$i > 0 and $VIRAMAS{$cps[$i - 1]} or _zwnj_joining_context(\@cps, $i)
$i > 0 $VIRAMAS{$cps[$i - 1]} _zwnj_joining_context(\@cps, $i)
Truth table0%0/5
A and B or C
A= $i > 0B= $VIRAMAS{$cps[$i - 1]}C= _zwnj_joining_context(\@cps, $i)
ABCresult
11X1
0X11
1011
0X00
1000
310 }
311 }
312 0 return 1;
313 }
314  
315 # (Joining_Type:{L,D})(Joining_Type:T)*‌(Joining_Type:T)*(Joining_Type:{R,D}), approximated with Arabic letters.
316 0 ▶sub _zwnj_joining_context {
Subroutine _zwnj_joining_context: not called CC=9 SCAR=45.0
317 0 my ($cps, $i) = @_;
318 0 ▶ my $is_joiner = sub { ($_[0] >= 0x0620 && $_[0] <= 0x064A) || ($_[0] >= 0x066E && $_[0] <= 0x06D3) };
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 1568 and $_[0] <= 1610 or $_[0] >= 1646 and $_[0] <= 1747 0 0 0
Condition0%0/9
$_[0] >= 1568 && $_[0] <= 1610 || $_[0] >= 1646 && $_[0] <= 1747
l!l&&r!l&&!r
000
$_[0] >= 1568 and $_[0] <= 1610
!ll&&!rl&&r
000
$_[0] >= 1646 and $_[0] <= 1747
!ll&&!rl&&r
000
MC/DC0%0/4
$_[0] >= 1568 && $_[0] <= 1610 || $_[0] >= 1646 && $_[0] <= 1747
$_[0] >= 1568 $_[0] <= 1610 $_[0] >= 1646 $_[0] <= 1747
Truth table0%0/7
A and B || C and D
A= $_[0] >= 1568B= $_[0] <= 1610C= $_[0] >= 1646D= $_[0] <= 1747
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
319 0 my $left = $i - 1;
320 0 ▶ $left-- while $left >= 0 && chr($cps->[$left]) =~ /\p{Mn}/;
Branch: 1 branch
BranchTrueFalseTotal
$left >= 0 and chr($cps->[$left]) =~ /\p{Mn}/u and do { --$left } 0 0 0
Condition0%0/3
$left >= 0 and chr($cps->[$left]) =~ /\p{Mn}/u
!ll&&!rl&&r
000
MC/DC0%0/2
$left >= 0 and chr($cps->[$left]) =~ /\p{Mn}/u
$left >= 0 chr($cps->[$left]) =~ /\p{Mn}/u
Truth table0%0/3
A and B
A= $left >= 0B= chr($cps->[$left]) =~ /\p{Mn}/u
ABresult
0X0
100
111
321 0 my $right = $i + 1;
322 0 ▶ $right++ while $right < @$cps && chr($cps->[$right]) =~ /\p{Mn}/;
Branch: 1 branch
BranchTrueFalseTotal
$right < @$cps and chr($cps->[$right]) =~ /\p{Mn}/u and do { ++$right } 0 0 0
Condition0%0/3
$right < @$cps and chr($cps->[$right]) =~ /\p{Mn}/u
!ll&&!rl&&r
000
MC/DC0%0/2
$right < @$cps and chr($cps->[$right]) =~ /\p{Mn}/u
$right < @$cps chr($cps->[$right]) =~ /\p{Mn}/u
Truth table0%0/3
A and B
A= $right < @$cpsB= chr($cps->[$right]) =~ /\p{Mn}/u
ABresult
0X0
100
111
323 0 ▶ return $left >= 0 && $right < @$cps && $is_joiner->($cps->[$left]) && $is_joiner->($cps->[$right]) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$left >= 0 && $right < @$cps && &$is_joiner($cps->[$left]) && &$is_joiner($cps->[$right]) ? : 0 0 0
Condition0%0/9
$left >= 0 and $right < @$cps and &$is_joiner($cps->[$left]) and &$is_joiner($cps->[$right])
!ll&&!rl&&r
000
$left >= 0 and $right < @$cps and &$is_joiner($cps->[$left])
!ll&&!rl&&r
000
$left >= 0 and $right < @$cps
!ll&&!rl&&r
000
MC/DC0%0/4
$left >= 0 and $right < @$cps and &$is_joiner($cps->[$left]) and &$is_joiner($cps->[$right])
$left >= 0 $right < @$cps &$is_joiner($cps->[$left]) &$is_joiner($cps->[$right])
Truth table0%0/5
A and B and C and D
A= $left >= 0B= $right < @$cpsC= &$is_joiner($cps->[$left])D= &$is_joiner($cps->[$right])
ABCDresult
0XXX0
10XX0
110X0
11100
11111
324 }
325  
326 0 ▶sub idn_hostname {
Subroutine idn_hostname: not called CC=17 SCAR=57.2
Pod undocumented
327 0 my ($s) = @_;
328 0 ▶ return 0 if length $s == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $s == 0 0 0 0
329 # Label separators: full stop, ideographic full stop, fullwidth full stop, halfwidth ideographic full stop.
330 0 my @labels = split /[.\x{3002}\x{ff0e}\x{ff61}]/, $s, -1;
331 0 ▶ my @unicode_labels = map { _is_a_label($_) ? (_punycode_decode(substr($_, 4)) || $_) : $_ } @labels;
Branch: 1 branch
BranchTrueFalseTotal
_is_a_label($_) ? : 0 0 0
Condition0%0/3
_punycode_decode(substr($_, 4)) or $_
l!l&&r!l&&!r
000
MC/DC0%0/2
_punycode_decode(substr($_, 4)) or $_
_punycode_decode(substr($_, 4)) $_
Truth table0%0/3
A or B
A= _punycode_decode(substr($_, 4))B= $_
ABresult
1X1
011
000
332 0 my $is_bidi_domain = grep { _bidi_domain($_) } @unicode_labels;
333 0 my $ascii_length = 0;
334 0 for my $i (0 .. $#labels) {
335 0 my $label = $labels[$i];
336 0 ▶ return 0 if length $label == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $label == 0 0 0 0
337 0 ▶ if (_ascii($label)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_ascii($label)) { } 0 0 0
338 0 ▶ return 0 unless _hostname_label_ok($label);
Branch: 1 branch
BranchTrueFalseTotal
unless _hostname_label_ok($label) 0 0 0
339 0 ▶ return 0 if _is_a_label($label) && !_punycode_label_ok(substr($label, 4));
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_label($label) and not _punycode_label_ok(substr($label, 4)) 0 0 0
Condition0%0/3
_is_a_label($label) and not _punycode_label_ok(substr($label, 4))
!ll&&!rl&&r
000
MC/DC0%0/2
_is_a_label($label) and not _punycode_label_ok(substr($label, 4))
_is_a_label($label) not _punycode_label_ok(substr($label, 4))
Truth table0%0/3
A and not(B)
A= _is_a_label($label)B= not _punycode_label_ok(substr($label, 4))
ABresult
0X0
100
111
340 0 ▶ return 0 unless _bidi_label_ok($unicode_labels[$i], $is_bidi_domain);
Branch: 1 branch
BranchTrueFalseTotal
unless _bidi_label_ok($unicode_labels[$i], $is_bidi_domain) 0 0 0
341 0 $ascii_length += length($label) + 1;
342 }
343 else {
344 0 ▶ return 0 unless _idn_label_ok($label);
Branch: 1 branch
BranchTrueFalseTotal
unless _idn_label_ok($label) 0 0 0
345 0 (my $without_joiners = $label) =~ s/[\x{200c}\x{200d}]//g;
346 0 ▶ return 0 if $without_joiners =~ /[\p{Cc}\p{Cf}\p{Zs}\p{Cn}]/ || _disallowed(_strip_exceptions($without_joiners));
Branch: 1 branch
BranchTrueFalseTotal
if $without_joiners =~ /[\p{Cc}\p{Cf}\p{Zs}\p{Cn}]/u or _disallowed(_strip_exceptions($without_joiners)) 0 0 0
Condition0%0/3
$without_joiners =~ /[\p{Cc}\p{Cf}\p{Zs}\p{Cn}]/u or _disallowed(_strip_exceptions($without_joiners))
l!l&&r!l&&!r
000
MC/DC0%0/2
$without_joiners =~ /[\p{Cc}\p{Cf}\p{Zs}\p{Cn}]/u or _disallowed(_strip_exceptions($without_joiners))
$without_joiners =~ /[\p{Cc}\p{Cf}\p{Zs}\p{Cn}]/u _disallowed(_strip_exceptions($without_joiners))
Truth table0%0/3
A or B
A= $without_joiners =~ /[\p{Cc}\p{Cf}\p{Zs}\p{Cn}]/uB= _disallowed(_strip_exceptions($without_joiners))
ABresult
1X1
011
000
347 0 ▶ return 0 unless _bidi_label_ok($label, $is_bidi_domain);
Branch: 1 branch
BranchTrueFalseTotal
unless _bidi_label_ok($label, $is_bidi_domain) 0 0 0
348 0 my $a_label = 'xn--' . _punycode_encode($label);
349 0 ▶ return 0 if length $a_label > 63;
Branch: 1 branch
BranchTrueFalseTotal
if length $a_label > 63 0 0 0
350 0 $ascii_length += length($a_label) + 1;
351 }
352 }
353 0 ▶ return $ascii_length - 1 <= 253 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ascii_length - 1 <= 253 ? : 0 0 0
354 }
355  
356 4 my $EMAIL_LOCAL_RE = qr/\A(?:[A-Za-z0-9!#\$%&'*+\/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#\$%&'*+\/=?^_`{|}~-]+)*|"(?:[^"\\\r\n]|\\.)*")\z/s;
357 4 my $IDN_EMAIL_LOCAL_RE = qr/\A(?:[\p{L}\p{M}\p{N}!#\$%&'*+\/=?^_`{|}~-]+(?:\.[\p{L}\p{M}\p{N}!#\$%&'*+\/=?^_`{|}~-]+)*|"(?:[^"\\\r\n]|\\.)*")\z/s;
358  
359 0 ▶sub _email_domain {
Subroutine _email_domain: not called CC=5 SCAR=34.0
360 0 my ($domain, $idn) = @_;
361 0 ▶ if (substr($domain, 0, 1) eq '[' && substr($domain, -1) eq ']') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($domain, 0, 1) eq "[" and substr($domain, -1) eq "]") 0 0 0
Condition0%0/3
substr($domain, 0, 1) eq "[" and substr($domain, -1) eq "]"
!ll&&!rl&&r
000
MC/DC0%0/2
substr($domain, 0, 1) eq "[" and substr($domain, -1) eq "]"
substr($domain, 0, 1) eq "[" substr($domain, -1) eq "]"
Truth table0%0/3
A and B
A= substr($domain, 0, 1) eq "["B= substr($domain, -1) eq "]"
ABresult
0X0
100
111
362 0 my $inner = substr($domain, 1, -1);
363 0 ▶ return ipv6(substr($inner, 5)) if lc(substr($inner, 0, 5)) eq 'ipv6:';
Branch: 1 branch
BranchTrueFalseTotal
if lc substr($inner, 0, 5) eq "ipv6:" 0 0 0
364 0 return ipv4($inner);
365 }
366 0 ▶ return $idn ? idn_hostname($domain) : hostname($domain);
Branch: 1 branch
BranchTrueFalseTotal
$idn ? : 0 0 0
367 }
368  
369 2 ▶sub email {
Subroutine email: called CC=4 SCAR=20.9
Pod undocumented
370 2 my ($s) = @_;
371 2 my $at = rindex($s, '@');
372 2 ▶ return 0 if $at <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $at <= 0 2 0 2
373 0 ▶ return substr($s, 0, $at) =~ $EMAIL_LOCAL_RE && _email_domain(substr($s, $at + 1), 0) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
substr($s, 0, $at) =~ /$EMAIL_LOCAL_RE/u && _email_domain(substr($s, $at + 1), 0) ? : 0 0 0
Condition0%0/3
substr($s, 0, $at) =~ /$EMAIL_LOCAL_RE/u and _email_domain(substr($s, $at + 1), 0)
!ll&&!rl&&r
000
MC/DC0%0/2
substr($s, 0, $at) =~ /$EMAIL_LOCAL_RE/u and _email_domain(substr($s, $at + 1), 0)
substr($s, 0, $at) =~ /$EMAIL_LOCAL_RE/u _email_domain(substr($s, $at + 1), 0)
Truth table0%0/3
A and B
A= substr($s, 0, $at) =~ /$EMAIL_LOCAL_RE/uB= _email_domain(substr($s, $at + 1), 0)
ABresult
0X0
100
111
374 }
375  
376 0 ▶sub idn_email {
Subroutine idn_email: not called CC=4 SCAR=30.0
Pod undocumented
377 0 my ($s) = @_;
378 0 my $at = rindex($s, '@');
379 0 ▶ return 0 if $at <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $at <= 0 0 0 0
380 0 ▶ return substr($s, 0, $at) =~ $IDN_EMAIL_LOCAL_RE && _email_domain(substr($s, $at + 1), 1) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
substr($s, 0, $at) =~ /$IDN_EMAIL_LOCAL_RE/u && _email_domain(substr($s, $at + 1), 1) ? : 0 0 0
Condition0%0/3
substr($s, 0, $at) =~ /$IDN_EMAIL_LOCAL_RE/u and _email_domain(substr($s, $at + 1), 1)
!ll&&!rl&&r
000
MC/DC0%0/2
substr($s, 0, $at) =~ /$IDN_EMAIL_LOCAL_RE/u and _email_domain(substr($s, $at + 1), 1)
substr($s, 0, $at) =~ /$IDN_EMAIL_LOCAL_RE/u _email_domain(substr($s, $at + 1), 1)
Truth table0%0/3
A and B
A= substr($s, 0, $at) =~ /$IDN_EMAIL_LOCAL_RE/uB= _email_domain(substr($s, $at + 1), 1)
ABresult
0X0
100
111
381 }
382  
383 # The RFC 3986 (URI) and RFC 3987 (IRI) grammars.
384 4 my $HEX = '[0-9A-Fa-f]';
385 4 my $PCT = "%$HEX\{2}";
386 4 my $SUB = q{[!$&'()*+,;=]};
387 4 my $UNRESERVED = '[A-Za-z0-9\-._~]';
388 4 my $UCSCHAR = '[\x{a0}-\x{d7ff}\x{f900}-\x{fdcf}\x{fdf0}-\x{ffef}\x{10000}-\x{efffd}]';
389  
390 0 ▶sub _uri_regex {
Subroutine _uri_regex: not called CC=4 SCAR=30.0
391 0 my ($iri, $reference) = @_;
392 0 ▶ my $unreserved = $iri ? "(?:$UNRESERVED|$UCSCHAR)" : $UNRESERVED;
Branch: 1 branch
BranchTrueFalseTotal
$iri ? : 0 0 0
393 0 my $pchar = "(?:$unreserved|$PCT|$SUB|[:\@])";
394 0 ▶ my $query = $iri ? "(?:$pchar|[/?]|[\\x{e000}-\\x{f8ff}\\x{f0000}-\\x{ffffd}\\x{100000}-\\x{10fffd}])*"
Branch: 1 branch
BranchTrueFalseTotal
$iri ? : 0 0 0
395 : "(?:$pchar|[/?])*";
396 0 my $fragment = "(?:$pchar|[/?])*";
397 0 my $dec_octet = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])';
398 0 my $ip4 = "$dec_octet(?:\\.$dec_octet){3}";
399 0 my $h16 = "$HEX\{1,4}";
400 0 my $ls32 = "(?:$h16:$h16|$ip4)";
401 0 my $ip6 = "(?:(?:$h16:){6}$ls32|::(?:$h16:){5}$ls32|(?:$h16)?::(?:$h16:){4}$ls32"
402 . "|(?:(?:$h16:){0,1}$h16)?::(?:$h16:){3}$ls32"
403 . "|(?:(?:$h16:){0,2}$h16)?::(?:$h16:){2}$ls32|(?:(?:$h16:){0,3}$h16)?::$h16:$ls32"
404 . "|(?:(?:$h16:){0,4}$h16)?::$ls32"
405 . "|(?:(?:$h16:){0,5}$h16)?::$h16|(?:(?:$h16:){0,6}$h16)?::)";
406 0 my $ip_literal = "\\[(?:$ip6|v$HEX+\\.(?:$UNRESERVED|$SUB|:)+)\\]";
407 0 my $reg_name = "(?:$unreserved|$PCT|$SUB)*";
408 0 my $authority = "(?:(?:$unreserved|$PCT|$SUB|:)*\@)?(?:$ip_literal|$ip4|$reg_name)(?::[0-9]*)?";
409 0 my $segment = "$pchar*";
410 0 my $segment_nz = "$pchar+";
411 0 my $segment_nz_nc = "(?:$unreserved|$PCT|$SUB|\@)+";
412 0 my $hier_part = "(?://$authority(?:/$segment)*|/(?:$segment_nz(?:/$segment)*)?|$segment_nz(?:/$segment)*|)";
413 0 my $relative_part = "(?://$authority(?:/$segment)*|/(?:$segment_nz(?:/$segment)*)?|$segment_nz_nc(?:/$segment)*|)";
414 0 my $scheme = '[A-Za-z][A-Za-z0-9+\-.]*';
415 0 my $absolute = "$scheme:$hier_part(?:\\?$query)?(?:#$fragment)?";
416 0 my $relative = "$relative_part(?:\\?$query)?(?:#$fragment)?";
417 0 ▶ my $source = '\A(?:' . ($reference ? "$absolute|$relative" : $absolute) . ')\z';
Branch: 1 branch
BranchTrueFalseTotal
$reference ? : 0 0 0
418 0 return qr/$source/;
419 }
420  
421 # The URI and IRI grammars, compiled on first use (they are long).
422 4 my %URI_RES;
423  
424 0 ▶sub _uri_re {
Subroutine _uri_re: not called CC=2 SCAR=17.9
425 0 my ($iri, $reference) = @_;
426 0 ▶ return $URI_RES{"$iri$reference"} //= _uri_regex($iri, $reference);
Condition0%0/3
$URI_RES{"$iri$reference"} //= _uri_regex($iri, $reference)
l!l&&r!l&&!r
000
MC/DC0%0/2
$URI_RES{"$iri$reference"} //= _uri_regex($iri, $reference)
$URI_RES{"$iri$reference"} _uri_regex($iri, $reference)
Truth table0%0/3
A //= B
A= $URI_RES{"$iri$reference"}B= _uri_regex($iri, $reference)
ABresult
1X1
011
000
427 }
428  
429 0 ▶sub uri { $_[0] =~ _uri_re(0, 0) ? 1 : 0 }
Subroutine uri: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ _uri_re(0, 0) ? : 0 0 0
430 0 ▶sub uri_reference { $_[0] =~ _uri_re(0, 1) ? 1 : 0 }
Subroutine uri_reference: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ _uri_re(0, 1) ? : 0 0 0
431 0 ▶sub iri { $_[0] =~ _uri_re(1, 0) ? 1 : 0 }
Subroutine iri: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ _uri_re(1, 0) ? : 0 0 0
432 0 ▶sub iri_reference { $_[0] =~ _uri_re(1, 1) ? 1 : 0 }
Subroutine iri_reference: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ _uri_re(1, 1) ? : 0 0 0
433  
434 4 my $VARCHAR = '(?:[A-Za-z0-9_]|%[0-9A-Fa-f]{2})';
435 4 my $VARSPEC = "$VARCHAR(?:\\.?$VARCHAR)*(?::[1-9][0-9]{0,3}|\\*)?";
436 4 my $URI_TEMPLATE_SOURCE = "\\A(?:[^\\x00-\\x20\"'<>\\\\^`{|}]|\\{[+#./;?&=,!\@|]?$VARSPEC(?:,$VARSPEC)*\\})*\\z";
437 4 my $URI_TEMPLATE_RE = qr/$URI_TEMPLATE_SOURCE/;
438  
439 0 ▶sub uri_template { $_[0] =~ $URI_TEMPLATE_RE ? 1 : 0 }
Subroutine uri_template: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /$URI_TEMPLATE_RE/u ? : 0 0 0
440  
441 0 ▶sub json_pointer { $_[0] =~ /\A(?:\/(?:[^~\/]|~[01])*)*\z/s ? 1 : 0 }
Subroutine json_pointer: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ m[\A(?:/(?:[^~/]|~[01])*)*\z]su ? : 0 0 0
442 0 ▶sub relative_json_pointer { $_[0] =~ /\A(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~\/]|~[01])*)*)\z/s ? 1 : 0 }
Subroutine relative_json_pointer: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ m[\A(?:0|[1-9][0-9]*)(?:#|(?:/(?:[^~/]|~[01])*)*)\z]su ? : 0 0 0
443  
444 0 ▶sub regex_format {
Subroutine regex_format: not called CC=2 SCAR=17.9
Pod undocumented
445 0 require JSON::Schema::Corvus::Pattern;
446 0 ▶ return JSON::Schema::Corvus::Pattern::is_valid_ecma_regex($_[0]) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
JSON::Schema::Corvus::Pattern::is_valid_ecma_regex($_[0]) ? : 0 0 0
447 }
448  
449 # The built-in format assertions, by format name.
450 4 our %FORMAT_VALIDATORS = (
451 'date' => \&date,
452 'time' => \&time_format,
453 'date-time' => \&date_time,
454 'duration' => \&duration,
455 'uuid' => \&uuid,
456 'ipv4' => \&ipv4,
457 'ipv6' => \&ipv6,
458 'hostname' => \&hostname,
459 'idn-hostname' => \&idn_hostname,
460 'email' => \&email,
461 'idn-email' => \&idn_email,
462 'uri' => \&uri,
463 'uri-reference' => \&uri_reference,
464 'iri' => \&iri,
465 'iri-reference' => \&iri_reference,
466 'uri-template' => \&uri_template,
467 'json-pointer' => \&json_pointer,
468 'relative-json-pointer' => \&relative_json_pointer,
469 'regex' => \&regex_format,
470 );
471  
472 # Numeric formats (a Corvus extension): integers of a given width, and floating-point and decimal magnitudes.
473 40 ▶sub _integer_range {
Subroutine _integer_range: called CC=1 SCAR=5.1
474 40 my ($lo, $hi) = map { Math::BigInt->new($_) } @_;
475 0 ▶ return sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
476 0 my ($x) = @_;
477 0 ▶ return 0 unless JSON::Schema::Corvus::Json::is_integer($x, 0);
Branch: 1 branch
BranchTrueFalseTotal
unless JSON::Schema::Corvus::Json::is_integer($x, 0) 0 0 0
478 # Exactly: an integer's digits (a copy's text, which for an integer is its digits), or a whole double's.
479 0 ▶ my $text = ref $x ? undef : do { my $copy = $x; "$copy" };
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
480 0 ▶ my $big = ref $x ? $x : Math::BigInt->new($text =~ /\A-?[0-9]+\z/ ? $text : sprintf('%.0f', $x));
Branch: 2 branches
BranchTrueFalseTotal
ref $x ? : 0 0 0
$text =~ /\A-?[0-9]+\z/u ? : 0 0 0
481 0 ▶ return $big >= $lo && $big <= $hi ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$big >= $lo && $big <= $hi ? : 0 0 0
Condition0%0/3
$big >= $lo and $big <= $hi
!ll&&!rl&&r
000
MC/DC0%0/2
$big >= $lo and $big <= $hi
$big >= $lo $big <= $hi
Truth table0%0/3
A and B
A= $big >= $loB= $big <= $hi
ABresult
0X0
100
111
482 40 };
483 }
484  
485 16 ▶sub _magnitude {
Subroutine _magnitude: called CC=1 SCAR=3.9
486 16 my ($limit) = @_;
487 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
488 0 my ($x) = @_;
489 0 ▶ my $v = ref $x ? $x->numify : $x;
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
490 0 ▶ return abs($v) <= $limit ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
abs $v <= $limit ? : 0 0 0
491 16 };
492 }
493  
494 4 our %NUMERIC_FORMAT_VALIDATORS = (
495 'byte' => _integer_range(0, 255),
496 'uint16' => _integer_range(0, 65535),
497 'uint32' => _integer_range(0, 4294967295),
498 'uint64' => _integer_range(0, '18446744073709551615'),
499 'uint128' => _integer_range(0, '340282366920938463463374607431768211455'),
500 'sbyte' => _integer_range(-128, 127),
501 'int16' => _integer_range(-32768, 32767),
502 'int32' => _integer_range(-2147483648, 2147483647),
503 'int64' => _integer_range('-9223372036854775808', '9223372036854775807'),
504 'int128' => _integer_range('-170141183460469231731687303715884105728', '170141183460469231731687303715884105727'),
505 'half' => _magnitude(65504),
506 'single' => _magnitude(3.40282346638528859e38),
507 'double' => _magnitude(1.7976931348623157e308),
508 'decimal' => _magnitude(79228162514264337593543950335),
509 );
510  
511 4 my %SINCE = ('uri-reference' => 1, 'uri-template' => 1, 'json-pointer' => 1, 'date' => 2, 'time' => 2, 'regex' => 2,
512 'relative-json-pointer' => 2, 'idn-email' => 2, 'idn-hostname' => 2, 'iri' => 2, 'iri-reference' => 2,
513 'duration' => 3, 'uuid' => 3);
514 4 my %ALWAYS = map { $_ => 1 } qw(byte uint16 uint32 uint64 uint128 sbyte int16 int32 int64 int128 half single double
515 decimal date-time email hostname ipv4 ipv6 uri);
516  
517 # The format a dialect recognises for a format value (SchemaCompiler.GetFormatKind): its canonical name, or 'unknown'
518 # for names the dialect does not define (which always match).
519 13 ▶sub format_kind {
Subroutine format_kind: called CC=5 SCAR=16.2
Pod undocumented
520 13 my ($format, $dialect) = @_;
521 13 ▶ return 'single' if $format eq 'float';
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "float" 0 13 13
522 13 ▶ return $format if $ALWAYS{$format};
Branch: 1 branch
BranchTrueFalseTotal
if $ALWAYS{$format} 6 7 13
523 7 my $since = $SINCE{$format};
524 7 ▶ return defined $since && $dialect >= $since ? $format : 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
defined $since && $dialect >= $since ? : 3 4 7
Condition66%2/3
defined $since and $dialect >= $since
!ll&&!rl&&r
403
MC/DC50%1/2
defined $since and $dialect >= $since
defined $since $dialect >= $since
Truth table66%2/3
A and B
A= defined $sinceB= $dialect >= $since
ABresult
0X0
100
111
525 }
526  
527 14 ▶sub is_numeric_format { exists $NUMERIC_FORMAT_VALIDATORS{ $_[0] } }
Subroutine is_numeric_format: called CC=1 SCAR=0.0
Pod undocumented
528  
529 4 1;
« Corvus/Collecting.pm ↑ Summary Corvus/Regex/Linear.pm »