Corvus/Formats.pm

filter: Statementstmt 57.2% 205 / 358 Branchbran 30.5% 85 / 278 Conditioncond 14.2% 34 / 238 MC/DCmcdc 3.7% 5 / 134 Subroutinesub 56.1% 32 / 57 Podpod 0.0% 0 / 22 totaltotal 33.2% 361 / 1087 CC 226 SCAR 47.1
CC
226
Cov
37%
_idn_label_ok
453.4
_bidi_label_ok
230.9
time_format
210.0
CRAP 111.6
« Corvus/Compiler.pm ↑ Summary Corvus/Runtime.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 5 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Math::BigInt ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use JSON::Schema::Corvus::Json ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use JSON::Schema::Corvus::Uts46 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶sub _ascii { $_[0] !~ /[^\x00-\x7f]/ }
Subroutine _ascii: called CC=1 SCAR=0.0
15  
16 5 my @DAYS = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
17  
18 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
19  
20 0 ▶sub date {
Subroutine date: not called CC=8 SCAR=42.8
Pod undocumented
21 0 my ($s) = @_;
22 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
23 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
24 }
25  
26 0 ▶sub time_format {
Subroutine time_format: not called CC=14 SCAR=53.5
Pod undocumented
27 0 my ($s) = @_;
28 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
29 = $s =~ /\A([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]+)?([zZ]|([+-])([0-9]{2}):([0-9]{2}))\z/ or return 0;
30 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
31 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
32 0 ▶ if (defined $sign) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sign) 0 0 0
33 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
34 }
35 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
36 0 ▶ if ($sec == 60) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sec == 60) 0 0 0
37 # A leap second is valid only at 23:59:60 UTC.
38 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
39 0 my $utc_minutes = ($h * 60 + $mi + $direction * ($oh * 60 + $om)) % 1440;
40 0 ▶ return $utc_minutes == 23 * 60 + 59 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$utc_minutes == 1439 ? : 0 0 0
41 }
42 0 return 1;
43 }
44  
45 0 ▶sub date_time {
Subroutine date_time: not called CC=5 SCAR=34.0
Pod undocumented
46 0 my ($s) = @_;
47 0 ▶ my $t = $s =~ /[tT]/g ? pos($s) - 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /[tT]/gu ? : 0 0 0
48 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
49 }
50  
51 # RFC 3339 appendix A: dur-year = 1*DIGIT "Y" [dur-month], dur-month = 1*DIGIT "M" [dur-day], and so on.
52 5 my $DUR_TIME = qr/(?:[0-9]+H(?:[0-9]+M(?:[0-9]+S)?)?|[0-9]+M(?:[0-9]+S)?|[0-9]+S)/;
53 5 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/;
54  
55 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
56  
57 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
58  
59 5 my $DEC_OCTET = qr/(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])/;
60  
61 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
62  
63 0 ▶sub ipv6 {
Subroutine ipv6: not called CC=12 SCAR=50.5
Pod undocumented
64 0 my ($s) = @_;
65 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
66 0 my $groups = 8;
67 0 my $tail = $s;
68 0 my $last_colon = rindex($s, ':');
69 0 ▶ if (index($s, '.') >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($s, ".") != -1) 0 0 0
70 0 ▶ return 0 unless ipv4(substr($s, $last_colon + 1));
Branch: 1 branch
BranchTrueFalseTotal
unless ipv4(substr($s, $last_colon + 1)) 0 0 0
71 0 $tail = substr($s, 0, $last_colon + 1) . '0:0';
72 }
73 0 my $dbl = index($tail, '::');
74 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
75 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
76 0 ▶ my $hex_ok = sub { $_[0] =~ /\A[0-9a-fA-F]{1,4}\z/ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 0 ▶ if ($dbl >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbl >= 0) 0 0 0
78 0 my @left = $parts->(substr($tail, 0, $dbl));
79 0 my @right = $parts->(substr($tail, $dbl + 2));
80 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
81 }
82 0 my @every = split /:/, $tail, -1;
83 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
84 }
85  
86 5 my $LABEL_RE = qr/\A[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\z/;
87  
88 17 ▶sub _is_a_label { lc(substr($_[0], 0, 4)) eq 'xn--' }
Subroutine _is_a_label: called CC=1 SCAR=0.0
89  
90 9 ▶sub _hostname_label_ok {
Subroutine _hostname_label_ok: called CC=7 SCAR=22.5
91 9 my ($label) = @_;
92 9 ▶ 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 9 9
Condition33%2/6
length $label == 0 or length $label > 63 or not $label =~ /$LABEL_RE/u
l!l&&r!l&&!r
009
length $label == 0 or length $label > 63
l!l&&r!l&&!r
009
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 table25%1/4
A or B or not(C)
A= length $label == 0B= length $label > 63C= not $label =~ /$LABEL_RE/u
ABCresult
1XX1
01X1
0011
0000
93 # "--" in the third and fourth positions is reserved for A-labels (xn--).
94 9 ▶ 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)) ? : 9 0 9
Condition83%5/6
length $label >= 4 && substr($label, 2, 2) eq '--' && !_is_a_label($label)
!ll&&!rl&&r
810
length $label >= 4 and substr($label, 2, 2) eq "--"
!ll&&!rl&&r
441
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 table75%3/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
95 }
96  
97 # RFC 1123 host names (draft 4 and 6): no IDNA rules for "--" or A-labels.
98 0 ▶sub legacy_hostname {
Subroutine legacy_hostname: not called CC=7 SCAR=40.3
Pod undocumented
99 0 my ($s) = @_;
100 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
101 0 for my $label (split /\./, $s, -1) {
102 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
103 }
104 0 return 1;
105 }
106  
107 1 ▶sub hostname {
Subroutine hostname: called CC=7 SCAR=22.9
Pod undocumented
108 1 my ($s) = @_;
109 1 ▶ return 0 if length $s == 0 || length $s > 253;
Branch: 1 branch
BranchTrueFalseTotal
if length $s == 0 or length $s > 253 0 1 1
Condition33%1/3
length $s == 0 or length $s > 253
l!l&&r!l&&!r
001
MC/DC0%0/2
length $s == 0 or length $s > 253
length $s == 0 length $s > 253
Truth table33%1/3
A or B
A= length $s == 0B= length $s > 253
ABresult
1X1
011
000
110 1 for my $label (split /\./, $s, -1) {
111 2 ▶ return 0 unless _hostname_label_ok($label);
Branch: 1 branch
BranchTrueFalseTotal
unless _hostname_label_ok($label) 0 2 2
112 2 ▶ 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 2 2
Condition33%1/3
_is_a_label($label) and not _punycode_label_ok(substr($label, 4))
!ll&&!rl&&r
200
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 table33%1/3
A and not(B)
A= _is_a_label($label)B= not _punycode_label_ok(substr($label, 4))
ABresult
0X0
100
111
113 }
114 1 return 1;
115 }
116  
117 1 ▶sub _punycode_label_ok {
Subroutine _punycode_label_ok: called CC=8 SCAR=27.1
118 1 my ($encoded) = @_;
119 1 my $decoded = _punycode_decode($encoded);
120 1 ▶ 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 1 1
Condition33%2/6
not defined $decoded or length $decoded == 0 or _ascii($decoded)
l!l&&r!l&&!r
001
not defined $decoded or length $decoded == 0
l!l&&r!l&&!r
001
MC/DC0%0/3
not defined $decoded or length $decoded == 0 or _ascii($decoded)
not defined $decoded length $decoded == 0 _ascii($decoded)
Truth table25%1/4
not(A) or B or C
A= not defined $decodedB= length $decoded == 0C= _ascii($decoded)
ABCresult
1XX1
01X1
0011
0000
121 # The encoding must be canonical: encoding the U-label again gives the same A-label.
122 1 ▶ return 0 if _punycode_encode($decoded) ne lc $encoded;
Branch: 1 branch
BranchTrueFalseTotal
if _punycode_encode($decoded) ne lc $encoded 0 1 1
123 1 ▶ 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)) ? : 1 0 1
Condition33%2/6
_idn_label_ok($decoded) and not _disallowed(_strip_exceptions($decoded)) and _bidi_label_ok($decoded, _bidi_domain($decoded))
!ll&&!rl&&r
001
_idn_label_ok($decoded) and not _disallowed(_strip_exceptions($decoded))
!ll&&!rl&&r
001
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 table25%1/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
124 && _bidi_label_ok($decoded, _bidi_domain($decoded)) ? 1 : 0;
125 }
126  
127 # Code points IDNA2008 disallows that the tests exercise: controls, format characters, spaces, unassigned, uppercase
128 # and titlecase letters (mapped away, never PVALID), and symbols.
129 1 ▶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: called CC=1 SCAR=0.0
130 1 ▶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: called CC=1 SCAR=0.0
131  
132 5 ▶use constant { BASE => 36, T_MIN => 1, T_MAX => 26, SKEW => 38, DAMP => 700 };
Subroutine BEGIN: called CC=1 SCAR=0.0
133  
134 15 ▶sub _adapt {
Subroutine _adapt: called CC=3 SCAR=11.4
135 15 my ($delta, $num_points, $first_time) = @_;
136 15 ▶ $delta = $first_time ? int($delta / DAMP) : $delta >> 1;
Branch: 1 branch
BranchTrueFalseTotal
$first_time ? : 3 12 15
137 15 $delta += int($delta / $num_points);
138 15 my $k = 0;
139 15 ▶ while ($delta > ((BASE - T_MIN) * T_MAX) >> 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delta > 455) 0 15 15
140 0 $delta = int($delta / (BASE - T_MIN));
141 0 $k += BASE;
142 }
143 15 return $k + int(((BASE - T_MIN + 1) * $delta) / ($delta + SKEW));
144 }
145  
146 # RFC 3492 encoding, for the canonical round trip and the A-label length checks.
147 1 ▶sub _punycode_encode {
Subroutine _punycode_encode: called CC=13 SCAR=25.7
148 1 my ($text) = @_;
149 1 my @cps = map { ord } split //, $text;
150 0 my $out = join '', map { chr } grep { $_ < 0x80 } @cps;
151 1 my $basic_length = length $out;
152 1 my $h = $basic_length;
153 1 ▶ $out .= '-' if $basic_length > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $basic_length > 0 0 1 1
154 1 my ($n, $delta, $bias) = (128, 0, 72);
155 1 ▶ my $digit = sub { chr($_[0] < 26 ? $_[0] + 97 : $_[0] + 22) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] < 26 ? : 7 1 8
156 1 ▶ while ($h < @cps) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h < @cps) 5 1 6
157 5 my $m;
158 5 ▶ for (@cps) { $m = $_ if $_ >= $n && (!defined $m || $_ < $m) }
Branch: 1 branch
BranchTrueFalseTotal
if $_ >= $n and !defined($m) || $_ < $m 8 17 25
Condition100%6/6
$_ >= $n and !defined($m) || $_ < $m
!ll&&!rl&&r
1078
not defined $m or $_ < $m
l!l&&r!l&&!r
537
MC/DC100%3/3
$_ >= $n and !defined($m) || $_ < $m
$_ >= $n not defined $m $_ < $m
Truth table100%4/4
A and not(B) or C
A= $_ >= $nB= not defined $mC= $_ < $m
ABCresult
0XX0
1000
11X1
1011
159 5 $delta += ($m - $n) * ($h + 1);
160 5 $n = $m;
161 5 for my $c (@cps) {
162 25 ▶ $delta++ if $c < $n;
Branch: 1 branch
BranchTrueFalseTotal
if $c < $n 10 15 25
163 25 ▶ if ($c == $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c == $n) 5 20 25
164 5 my $q = $delta;
165 5 my $k = BASE;
166 5 while (1) {
167 8 ▶ my $t = $k <= $bias ? T_MIN : $k >= $bias + T_MAX ? T_MAX : $k - $bias;
Branch: 2 branches
BranchTrueFalseTotal
$k <= $bias ? : 2 6 8
$k >= $bias + 26 ? : 6 0 6
168 8 ▶ last if $q < $t;
Branch: 1 branch
BranchTrueFalseTotal
if $q < $t 5 3 8
169 3 $out .= $digit->($t + ($q - $t) % (BASE - $t));
170 3 $q = int(($q - $t) / (BASE - $t));
171 3 $k += BASE;
172 }
173 5 $out .= $digit->($q);
174 5 $bias = _adapt($delta, $h + 1, $h == $basic_length);
175 5 $delta = 0;
176 5 $h++;
177 }
178 }
179 5 $delta++;
180 5 $n++;
181 }
182 1 return $out;
183 }
184  
185 # The RFC 5893 Bidi rule, with Bidi classes approximated by script and general category, as the TypeScript evaluator
186 # does.
187 0 ▶sub _bidi_class {
Subroutine _bidi_class: not called CC=13 SCAR=52.0
188 0 my ($c) = @_;
189 0 my $cp = ord $c;
190 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
191 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
192 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
193 0 ▶ return 'R' if $c =~ /\A\p{Script=Hebrew}/;
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /\A\p{Script=Hebrew}/u 0 0 0
194 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
195 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
196 0 return 'ON';
197 }
198  
199 8 ▶sub _bidi_domain {
Subroutine _bidi_domain: called CC=6 SCAR=32.3
200 8 my ($label) = @_;
201 8 ▶ 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 8 0 8
202 0 for my $c (split //, $label) {
203 0 my $class = _bidi_class($c);
204 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
205 }
206 0 return 0;
207 }
208  
209 8 ▶sub _bidi_label_ok {
Subroutine _bidi_label_ok: called CC=16 SCAR=54.4
210 8 my ($label, $is_bidi_domain) = @_;
211 8 ▶ return 1 unless $is_bidi_domain;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_bidi_domain 8 0 8
212 0 my @classes = map { _bidi_class($_) } split //, $label;
213 0 my $first = $classes[0];
214 0 my $last = $#classes;
215 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
216 0 my %has = map { $_ => 1 } @classes;
217 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
218 0 ▶ return 0 if $has{L};
Branch: 1 branch
BranchTrueFalseTotal
if $has{"L"} 0 0 0
219 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
220 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
221 }
222 0 ▶ if ($first eq 'L') {
Branch: 1 branch
BranchTrueFalseTotal
if ($first eq "L") 0 0 0
223 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
224 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
225 }
226 0 return 0;
227 }
228  
229 # RFC 3492 decoding, enough to validate A-labels.
230 2 ▶sub _punycode_decode {
Subroutine _punycode_decode: called CC=16 SCAR=29.6
231 2 my ($text) = @_;
232 2 my ($n, $i, $bias) = (128, 0, 72);
233 2 my @output;
234 2 my $basic = rindex($text, '-');
235 2 ▶ $basic = 0 if $basic < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $basic < 0 2 0 2
236 2 for my $j (0 .. $basic - 1) {
237 0 my $c = ord substr($text, $j, 1);
238 0 ▶ return undef if $c >= 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $c >= 128 0 0 0
239 0 push @output, $c;
240 }
241 2 ▶ my $index = $basic > 0 ? $basic + 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$basic > 0 ? : 0 2 2
242 2 ▶ while ($index < length $text) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < length $text) 10 2 12
243 10 my $oldi = $i;
244 10 my $w = 1;
245 10 my $k = BASE;
246 10 while (1) {
247 16 ▶ return undef if $index >= length $text;
Branch: 1 branch
BranchTrueFalseTotal
if $index >= length $text 0 16 16
248 16 my $c = ord substr($text, $index++, 1);
249 16 ▶ 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 ? : 2 14 16
$c - 65 < 26 ? : 0 14 14
$c - 97 < 26 ? : 14 0 14
250 16 ▶ return undef if $digit < 0 || $digit >= BASE;
Branch: 1 branch
BranchTrueFalseTotal
if $digit < 0 or $digit >= 36 0 16 16
Condition33%1/3
$digit < 0 or $digit >= 36
l!l&&r!l&&!r
0016
MC/DC0%0/2
$digit < 0 or $digit >= 36
$digit < 0 $digit >= 36
Truth table33%1/3
A or B
A= $digit < 0B= $digit >= 36
ABresult
1X1
011
000
251 16 $i += $digit * $w;
252 16 ▶ my $t = $k <= $bias ? T_MIN : $k >= $bias + T_MAX ? T_MAX : $k - $bias;
Branch: 2 branches
BranchTrueFalseTotal
$k <= $bias ? : 4 12 16
$k >= $bias + 26 ? : 12 0 12
253 16 ▶ last if $digit < $t;
Branch: 1 branch
BranchTrueFalseTotal
if $digit < $t 10 6 16
254 6 $w *= BASE - $t;
255 6 $k += BASE;
256 }
257 10 $bias = _adapt($i - $oldi, @output + 1, $oldi == 0);
258 10 $n += int($i / (@output + 1));
259 10 $i %= @output + 1;
260 10 ▶ return undef if $n > 0x10FFFF;
Branch: 1 branch
BranchTrueFalseTotal
if $n > 1114111 0 10 10
261 10 splice @output, $i, 0, $n;
262 10 $i++;
263 }
264 5 ▶ no warnings 'surrogate';
Subroutine BEGIN: called CC=1 SCAR=0.0
265 2 return join '', map { chr } @output;
266 }
267  
268 5 my %VIRAMAS = map { $_ => 1 } (
269 0x094D, 0x09CD, 0x0A4D, 0x0ACD, 0x0B4D, 0x0BCD, 0x0C4D, 0x0CCD, 0x0D3B, 0x0D3C, 0x0D4D, 0x0DCA, 0x0E3A, 0x0EBA,
270 0x0F84, 0x1039, 0x103A, 0x1714, 0x1734, 0x17D2, 0x1A60, 0x1B44, 0x1BAA, 0x1BAB, 0x1BF2, 0x1BF3, 0x2D7F, 0xA806,
271 0xA8C4, 0xA953, 0xA9C0, 0xAAF6, 0xABED,
272 );
273  
274 5 my %FORBIDDEN = map { $_ => 1 } (0x302E, 0x302F, 0x0640, 0x07FA, 0x3031, 0x3032, 0x3033, 0x3034, 0x3035, 0x303B);
275  
276 # The contextual and disallowed code points of RFC 5892 that the test suite exercises.
277 1 ▶sub _idn_label_ok {
Subroutine _idn_label_ok: called CC=35 SCAR=61.2
278 1 my ($label) = @_;
279 1 ▶ return 0 if length $label == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $label == 0 0 1 1
280 1 ▶ 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 1 1
Condition33%1/3
substr($label, 0, 1) eq "-" or substr($label, -1) eq "-"
l!l&&r!l&&!r
001
MC/DC0%0/2
substr($label, 0, 1) eq "-" or substr($label, -1) eq "-"
substr($label, 0, 1) eq "-" substr($label, -1) eq "-"
Truth table33%1/3
A or B
A= substr($label, 0, 1) eq "-"B= substr($label, -1) eq "-"
ABresult
1X1
011
000
281 1 ▶ 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 1 1
Condition33%1/3
length $label >= 4 and substr($label, 2, 2) eq "--"
!ll&&!rl&&r
010
MC/DC0%0/2
length $label >= 4 and substr($label, 2, 2) eq "--"
length $label >= 4 substr($label, 2, 2) eq "--"
Truth table33%1/3
A and B
A= length $label >= 4B= substr($label, 2, 2) eq "--"
ABresult
0X0
100
111
282 1 my @cps = map { ord } split //, $label;
283 1 ▶ return 0 if $label =~ /\A\p{M}/;
Branch: 1 branch
BranchTrueFalseTotal
if $label =~ /\A\p{M}/u 0 1 1
284 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 1 1
Condition22%2/9
grep {$_ >= 1632 and $_ <= 1641;} @cps and grep {$_ >= 1776 and $_ <= 1785;} @cps
!ll&&!rl&&r
100
$_ >= 1632 && $_ <= 1641
!ll&&!rl&&r
500
$_ >= 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 table33%1/3
A and B
A= grep {$_ >= 1632 and $_ <= 1641;} @cpsB= grep {$_ >= 1776 and $_ <= 1785;} @cps
ABresult
0X0
100
111
Truth table33%1/3
A && B
A= $_ >= 1632B= $_ <= 1641
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= $_ >= 1776B= $_ <= 1785
ABresult
0X0
100
111
285 1 for my $i (0 .. $#cps) {
286 5 my $c = $cps[$i];
287 5 ▶ return 0 if $FORBIDDEN{$c};
Branch: 1 branch
BranchTrueFalseTotal
if $FORBIDDEN{$c} 0 5 5
288 5 ▶ if ($c == 0x00B7) {
Branch: 6 branches
BranchTrueFalseTotal
if ($c == 183) { } 0 5 5
elsif ($c == 885) { } 0 5 5
elsif ($c == 1523 or $c == 1524) { } 0 5 5
elsif ($c == 12539) { } 0 5 5
elsif ($c == 8205) { } 0 5 5
elsif ($c == 8204) { } 0 5 5
289 # MIDDLE DOT: between two 'l'.
290 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
291 }
292 elsif ($c == 0x0375) {
293 # GREEK KERAIA: followed by Greek.
294 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
295 }
296 ▶ elsif ($c == 0x05F3 || $c == 0x05F4) {
Condition33%1/3
$c == 1523 or $c == 1524
l!l&&r!l&&!r
005
MC/DC0%0/2
$c == 1523 or $c == 1524
$c == 1523 $c == 1524
Truth table33%1/3
A or B
A= $c == 1523B= $c == 1524
ABresult
1X1
011
000
297 # HEBREW GERESH or GERSHAYIM: preceded by Hebrew.
298 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
299 }
300 elsif ($c == 0x30FB) {
301 # KATAKANA MIDDLE DOT: the label has Hiragana, Katakana or Han.
302 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
303 }
304 elsif ($c == 0x200D) {
305 # ZERO WIDTH JOINER: preceded by a virama.
306 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
307 }
308 elsif ($c == 0x200C) {
309 # ZERO WIDTH NON-JOINER: preceded by a virama (the joining-type rule is approximated).
310 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
311 }
312 }
313 1 return 1;
314 }
315  
316 # (Joining_Type:{L,D})(Joining_Type:T)*‌(Joining_Type:T)*(Joining_Type:{R,D}), approximated with Arabic letters.
317 0 ▶sub _zwnj_joining_context {
Subroutine _zwnj_joining_context: not called CC=9 SCAR=45.0
318 0 my ($cps, $i) = @_;
319 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
320 0 my $left = $i - 1;
321 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
322 0 my $right = $i + 1;
323 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
324 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
325 }
326  
327 # The most UTF-8 bytes an idn-hostname may have before it is read: four for each character of the 253 of a host name.
328 # The check decodes and encodes Punycode and walks around every joiner and katakana middle dot, which take time that
329 # grows with the square of a label, so it must not be given a label of any length.
330 5 my $MAX_IDN_HOSTNAME_BYTES = 4 * 253;
331  
332 11 ▶sub _utf8_length {
Subroutine _utf8_length: called CC=1 SCAR=0.0
333 11 my ($s) = @_;
334 11 utf8::encode($s);
335 11 return length $s;
336 }
337  
338 6 ▶sub idn_hostname {
Subroutine idn_hostname: called CC=19 SCAR=39.6
Pod undocumented
339 6 my ($s) = @_;
340 6 ▶ return 0 if _utf8_length($s) > $MAX_IDN_HOSTNAME_BYTES;
Branch: 1 branch
BranchTrueFalseTotal
if _utf8_length($s) > $MAX_IDN_HOSTNAME_BYTES 1 5 6
341 # UTS #46 maps the name before it is checked: it removes the ignored code points and replaces the mapped ones, such
342 # as the fullwidth forms, which can produce an "xn--" A-label to decode.
343 5 $s = JSON::Schema::Corvus::Uts46::map_name($s);
344 5 ▶ return 0 if _utf8_length($s) > $MAX_IDN_HOSTNAME_BYTES;
Branch: 1 branch
BranchTrueFalseTotal
if _utf8_length($s) > $MAX_IDN_HOSTNAME_BYTES 0 5 5
345 5 ▶ return 0 if length $s == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $s == 0 0 5 5
346 # Label separators: full stop, ideographic full stop, fullwidth full stop, halfwidth ideographic full stop.
347 5 my @labels = split /[.\x{3002}\x{ff0e}\x{ff61}]/, $s, -1;
348 5 ▶ my @unicode_labels = map { _is_a_label($_) ? (_punycode_decode(substr($_, 4)) || $_) : $_ } @labels;
Branch: 1 branch
BranchTrueFalseTotal
_is_a_label($_) ? : 1 6 7
Condition33%1/3
_punycode_decode(substr($_, 4)) or $_
l!l&&r!l&&!r
100
MC/DC0%0/2
_punycode_decode(substr($_, 4)) or $_
_punycode_decode(substr($_, 4)) $_
Truth table33%1/3
A or B
A= _punycode_decode(substr($_, 4))B= $_
ABresult
1X1
011
000
349 5 my $is_bidi_domain = grep { _bidi_domain($_) } @unicode_labels;
350 5 my $ascii_length = 0;
351 5 for my $i (0 .. $#labels) {
352 7 my $label = $labels[$i];
353 7 ▶ return 0 if length $label == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $label == 0 0 7 7
354 7 ▶ if (_ascii($label)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_ascii($label)) { } 7 0 7
355 7 ▶ return 0 unless _hostname_label_ok($label);
Branch: 1 branch
BranchTrueFalseTotal
unless _hostname_label_ok($label) 0 7 7
356 7 ▶ 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 7 7
Condition66%2/3
_is_a_label($label) and not _punycode_label_ok(substr($label, 4))
!ll&&!rl&&r
610
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 table66%2/3
A and not(B)
A= _is_a_label($label)B= not _punycode_label_ok(substr($label, 4))
ABresult
0X0
100
111
357 7 ▶ 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 7 7
358 7 $ascii_length += length($label) + 1;
359 }
360 else {
361 0 ▶ return 0 unless _idn_label_ok($label);
Branch: 1 branch
BranchTrueFalseTotal
unless _idn_label_ok($label) 0 0 0
362 0 (my $without_joiners = $label) =~ s/[\x{200c}\x{200d}]//g;
363 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
364 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
365 0 my $a_label = 'xn--' . _punycode_encode($label);
366 0 ▶ return 0 if length $a_label > 63;
Branch: 1 branch
BranchTrueFalseTotal
if length $a_label > 63 0 0 0
367 0 $ascii_length += length($a_label) + 1;
368 }
369 }
370 5 ▶ return $ascii_length - 1 <= 253 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ascii_length - 1 <= 253 ? : 5 0 5
371 }
372  
373 # RFC 5321 Local-part: a dot-string of atext, or a quoted string of qtextSMTP (%d32-33 / %d35-91 / %d93-126) and quoted
374 # pairs (a backslash and one of %d32-126). There are no comments. RFC 6531 extends atext and qtextSMTP with
375 # UTF8-non-ascii (every character outside ASCII, whatever its category), but not the quoted pair.
376 5 my $EMAIL_LOCAL_RE = qr/\A(?:[A-Za-z0-9!#\$%&'*+\/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#\$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x20\x21\x23-\x5B\x5D-\x7E]|\\[\x20-\x7E])*")\z/;
377 5 my $IDN_EMAIL_LOCAL_RE = qr/\A(?:[A-Za-z0-9!#\$%&'*+\/=?^_`{|}~\x{80}-\x{10FFFF}-]+(?:\.[A-Za-z0-9!#\$%&'*+\/=?^_`{|}~\x{80}-\x{10FFFF}-]+)*|"(?:[\x20\x21\x23-\x5B\x5D-\x7E\x{80}-\x{10FFFF}]|\\[\x20-\x7E])*")\z/;
378  
379 3 ▶sub _email_domain {
Subroutine _email_domain: called CC=5 SCAR=21.7
380 3 my ($domain, $idn) = @_;
381 3 ▶ 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 3 3
Condition33%1/3
substr($domain, 0, 1) eq "[" and substr($domain, -1) eq "]"
!ll&&!rl&&r
300
MC/DC0%0/2
substr($domain, 0, 1) eq "[" and substr($domain, -1) eq "]"
substr($domain, 0, 1) eq "[" substr($domain, -1) eq "]"
Truth table33%1/3
A and B
A= substr($domain, 0, 1) eq "["B= substr($domain, -1) eq "]"
ABresult
0X0
100
111
382 0 my $inner = substr($domain, 1, -1);
383 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
384 0 return ipv4($inner);
385 }
386 3 ▶ return $idn ? idn_hostname($domain) : hostname($domain);
Branch: 1 branch
BranchTrueFalseTotal
$idn ? : 2 1 3
387 }
388  
389 4 ▶sub email {
Subroutine email: called CC=4 SCAR=13.9
Pod undocumented
390 4 my ($s) = @_;
391 4 my $at = rindex($s, '@');
392 4 ▶ return 0 if $at <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $at <= 0 2 2 4
393 2 ▶ 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) ? : 1 1 2
Condition66%2/3
substr($s, 0, $at) =~ /$EMAIL_LOCAL_RE/u and _email_domain(substr($s, $at + 1), 0)
!ll&&!rl&&r
101
MC/DC50%1/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 table66%2/3
A and B
A= substr($s, 0, $at) =~ /$EMAIL_LOCAL_RE/uB= _email_domain(substr($s, $at + 1), 0)
ABresult
0X0
100
111
394 }
395  
396 2 ▶sub idn_email {
Subroutine idn_email: called CC=4 SCAR=15.6
Pod undocumented
397 2 my ($s) = @_;
398 2 my $at = rindex($s, '@');
399 2 ▶ return 0 if $at <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $at <= 0 0 2 2
400 2 ▶ 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) ? : 2 0 2
Condition33%1/3
substr($s, 0, $at) =~ /$IDN_EMAIL_LOCAL_RE/u and _email_domain(substr($s, $at + 1), 1)
!ll&&!rl&&r
002
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 table33%1/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
401 }
402  
403 # The RFC 3986 (URI) and RFC 3987 (IRI) grammars.
404 5 my $HEX = '[0-9A-Fa-f]';
405 5 my $PCT = "%$HEX\{2}";
406 5 my $SUB = q{[!$&'()*+,;=]};
407 5 my $UNRESERVED = '[A-Za-z0-9\-._~]';
408 5 my $UCSCHAR = '[\x{a0}-\x{d7ff}\x{f900}-\x{fdcf}\x{fdf0}-\x{ffef}\x{10000}-\x{efffd}]';
409  
410 0 ▶sub _uri_regex {
Subroutine _uri_regex: not called CC=4 SCAR=30.0
411 0 my ($iri, $reference) = @_;
412 0 ▶ my $unreserved = $iri ? "(?:$UNRESERVED|$UCSCHAR)" : $UNRESERVED;
Branch: 1 branch
BranchTrueFalseTotal
$iri ? : 0 0 0
413 0 my $pchar = "(?:$unreserved|$PCT|$SUB|[:\@])";
414 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
415 : "(?:$pchar|[/?])*";
416 0 my $fragment = "(?:$pchar|[/?])*";
417 0 my $dec_octet = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])';
418 0 my $ip4 = "$dec_octet(?:\\.$dec_octet){3}";
419 0 my $h16 = "$HEX\{1,4}";
420 0 my $ls32 = "(?:$h16:$h16|$ip4)";
421 0 my $ip6 = "(?:(?:$h16:){6}$ls32|::(?:$h16:){5}$ls32|(?:$h16)?::(?:$h16:){4}$ls32"
422 . "|(?:(?:$h16:){0,1}$h16)?::(?:$h16:){3}$ls32"
423 . "|(?:(?:$h16:){0,2}$h16)?::(?:$h16:){2}$ls32|(?:(?:$h16:){0,3}$h16)?::$h16:$ls32"
424 . "|(?:(?:$h16:){0,4}$h16)?::$ls32"
425 . "|(?:(?:$h16:){0,5}$h16)?::$h16|(?:(?:$h16:){0,6}$h16)?::)";
426 0 my $ip_literal = "\\[(?:$ip6|v$HEX+\\.(?:$UNRESERVED|$SUB|:)+)\\]";
427 0 my $reg_name = "(?:$unreserved|$PCT|$SUB)*";
428 0 my $authority = "(?:(?:$unreserved|$PCT|$SUB|:)*\@)?(?:$ip_literal|$ip4|$reg_name)(?::[0-9]*)?";
429 0 my $segment = "$pchar*";
430 0 my $segment_nz = "$pchar+";
431 0 my $segment_nz_nc = "(?:$unreserved|$PCT|$SUB|\@)+";
432 0 my $hier_part = "(?://$authority(?:/$segment)*|/(?:$segment_nz(?:/$segment)*)?|$segment_nz(?:/$segment)*|)";
433 0 my $relative_part = "(?://$authority(?:/$segment)*|/(?:$segment_nz(?:/$segment)*)?|$segment_nz_nc(?:/$segment)*|)";
434 0 my $scheme = '[A-Za-z][A-Za-z0-9+\-.]*';
435 0 my $absolute = "$scheme:$hier_part(?:\\?$query)?(?:#$fragment)?";
436 0 my $relative = "$relative_part(?:\\?$query)?(?:#$fragment)?";
437 0 ▶ my $source = '\A(?:' . ($reference ? "$absolute|$relative" : $absolute) . ')\z';
Branch: 1 branch
BranchTrueFalseTotal
$reference ? : 0 0 0
438 0 return qr/$source/;
439 }
440  
441 # The URI and IRI grammars, compiled on first use (they are long).
442 5 my %URI_RES;
443  
444 0 ▶sub _uri_re {
Subroutine _uri_re: not called CC=2 SCAR=17.9
445 0 my ($iri, $reference) = @_;
446 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
447 }
448  
449 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
450 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
451 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
452 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
453  
454 5 my $VARCHAR = '(?:[A-Za-z0-9_]|%[0-9A-Fa-f]{2})';
455 5 my $VARSPEC = "$VARCHAR(?:\\.?$VARCHAR)*(?::[1-9][0-9]{0,3}|\\*)?";
456 # RFC 6570: literals = %x21 / %x23-24 / %x26-3B / %x3D / %x3F-5B / %x5D / %x5F / %x61-7A / %x7E / ucschar / iprivate /
457 # pct-encoded. RFC 6570 printed %x26 / %x28-3B, leaving out the apostrophe; erratum 6937 corrects it.
458 5 my $LITERAL = '(?:[\x21\x23\x24\x26-\x3B\x3D\x3F-\x5B\x5D\x5F\x61-\x7A\x7E\x{A0}-\x{D7FF}\x{E000}-\x{FDCF}\x{FDF0}-\x{FFEF}'
459 . '\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}'
460 . '\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}'
461 . '\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}\x{F0000}-\x{FFFFD}\x{100000}-\x{10FFFD}]|%[0-9A-Fa-f]{2})';
462 5 my $URI_TEMPLATE_SOURCE = "\\A(?:$LITERAL|\\{[+#./;?&=,!\@|]?$VARSPEC(?:,$VARSPEC)*\\})*\\z";
463 5 my $URI_TEMPLATE_RE = qr/$URI_TEMPLATE_SOURCE/;
464  
465 5 ▶sub uri_template { $_[0] =~ $URI_TEMPLATE_RE ? 1 : 0 }
Subroutine uri_template: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /$URI_TEMPLATE_RE/u ? : 1 4 5
466  
467 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
468 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
469  
470 0 ▶sub regex_format {
Subroutine regex_format: not called CC=2 SCAR=17.9
Pod undocumented
471 0 require JSON::Schema::Corvus::Pattern;
472 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
473 }
474  
475 # The built-in format assertions, by format name.
476 5 our %FORMAT_VALIDATORS = (
477 'date' => \&date,
478 'time' => \&time_format,
479 'date-time' => \&date_time,
480 'duration' => \&duration,
481 'uuid' => \&uuid,
482 'ipv4' => \&ipv4,
483 'ipv6' => \&ipv6,
484 'hostname' => \&hostname,
485 'idn-hostname' => \&idn_hostname,
486 'email' => \&email,
487 'idn-email' => \&idn_email,
488 'uri' => \&uri,
489 'uri-reference' => \&uri_reference,
490 'iri' => \&iri,
491 'iri-reference' => \&iri_reference,
492 'uri-template' => \&uri_template,
493 'json-pointer' => \&json_pointer,
494 'relative-json-pointer' => \&relative_json_pointer,
495 'regex' => \&regex_format,
496 );
497  
498 # Numeric formats (a Corvus extension): integers of a given width, and floating-point and decimal magnitudes.
499 50 ▶sub _integer_range {
Subroutine _integer_range: called CC=1 SCAR=5.1
500 50 my ($lo, $hi) = map { Math::BigInt->new($_) } @_;
501 0 ▶ return sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
502 0 my ($x) = @_;
503 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
504 # Exactly: an integer's digits (a copy's text, which for an integer is its digits), or a whole double's.
505 0 ▶ my $text = ref $x ? undef : do { my $copy = $x; "$copy" };
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
506 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
507 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
508 50 };
509 }
510  
511 20 ▶sub _magnitude {
Subroutine _magnitude: called CC=1 SCAR=3.9
512 20 my ($limit) = @_;
513 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
514 0 my ($x) = @_;
515 0 ▶ my $v = ref $x ? $x->numify : $x;
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
516 0 ▶ return abs($v) <= $limit ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
abs $v <= $limit ? : 0 0 0
517 20 };
518 }
519  
520 5 our %NUMERIC_FORMAT_VALIDATORS = (
521 'byte' => _integer_range(0, 255),
522 'uint16' => _integer_range(0, 65535),
523 'uint32' => _integer_range(0, 4294967295),
524 'uint64' => _integer_range(0, '18446744073709551615'),
525 'uint128' => _integer_range(0, '340282366920938463463374607431768211455'),
526 'sbyte' => _integer_range(-128, 127),
527 'int16' => _integer_range(-32768, 32767),
528 'int32' => _integer_range(-2147483648, 2147483647),
529 'int64' => _integer_range('-9223372036854775808', '9223372036854775807'),
530 'int128' => _integer_range('-170141183460469231731687303715884105728', '170141183460469231731687303715884105727'),
531 'half' => _magnitude(65504),
532 'single' => _magnitude(3.40282346638528859e38),
533 'double' => _magnitude(1.7976931348623157e308),
534 'decimal' => _magnitude(79228162514264337593543950335),
535 );
536  
537 5 my %SINCE = ('uri-reference' => 1, 'uri-template' => 1, 'json-pointer' => 1, 'date' => 2, 'time' => 2, 'regex' => 2,
538 'relative-json-pointer' => 2, 'idn-email' => 2, 'idn-hostname' => 2, 'iri' => 2, 'iri-reference' => 2,
539 'duration' => 3, 'uuid' => 3);
540 5 my %ALWAYS = map { $_ => 1 } qw(byte uint16 uint32 uint64 uint128 sbyte int16 int32 int64 int128 half single double
541 decimal date-time email hostname ipv4 ipv6 uri);
542  
543 # The format a dialect recognises for a format value (SchemaCompiler.GetFormatKind): its canonical name, or 'unknown'
544 # for names the dialect does not define (which always match).
545 13 ▶sub format_kind {
Subroutine format_kind: called CC=5 SCAR=16.2
Pod undocumented
546 13 my ($format, $dialect) = @_;
547 13 ▶ return 'single' if $format eq 'float';
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "float" 0 13 13
548 13 ▶ return $format if $ALWAYS{$format};
Branch: 1 branch
BranchTrueFalseTotal
if $ALWAYS{$format} 6 7 13
549 7 my $since = $SINCE{$format};
550 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
551 }
552  
553 14 ▶sub is_numeric_format { exists $NUMERIC_FORMAT_VALIDATORS{ $_[0] } }
Subroutine is_numeric_format: called CC=1 SCAR=0.0
Pod undocumented
554  
555 5 1;
« Corvus/Compiler.pm ↑ Summary Corvus/Runtime.pm »