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