Modern/Vocabulary/FormatAssertion.pm

filter: Statementstmt 82.2% 157 / 191 Branchbran 73.9% 71 / 96 Conditioncond 50.8% 125 / 246 MC/DCmcdc 15.5% 16 / 103 Subroutinesub 78.8% 41 / 52 Podpod 0.0% 0 / 3 totaltotal 59.3% 410 / 691 CC 126 SCAR 34.3
CC
126
Cov
66%
__ANON__
87.7
__ANON__
70.2
__ANON__
24.4
CRAP 30.7
↑ Summary Modern/Result.pm »
1 38 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 38 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package JSON::Schema::Modern::Vocabulary::FormatAssertion;
4 # vim: set ts=8 sts=2 sw=2 tw=100 et :
5 # ABSTRACT: Implementation of the JSON Schema Format-Assertion vocabulary
6  
7 38 our $VERSION = '0.654';
8  
9 38 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 38 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 38 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 38 ▶use stable 0.031 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 38 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 38 ▶no autovivification warn => qw(fetch store exists delete);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 38 ▶use if "$]" >= 5.022, experimental => 're_strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 38 ▶use if "$]" < 5.026, experimental => 'lexical_subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 38 ▶no if "$]" >= 5.031009, feature => 'indirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 38 ▶no if "$]" >= 5.033001, feature => 'multidimensional';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 38 ▶no if "$]" >= 5.033006, feature => 'bareword_filehandles';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 38 ▶no if "$]" >= 5.041009, feature => 'smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 38 ▶no feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 38 ▶use JSON::Schema::Modern::Utilities qw(get_type E A assert_keyword_type abort);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 38 ▶use Feature::Compat::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 38 ▶use if "$]" < 5.041010, 'List::Util' => 'any';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 38 ▶use if "$]" >= 5.041010, experimental => 'keyword_any';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 38 ▶use Scalar::Util 'looks_like_number';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 38 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 38 with 'JSON::Schema::Modern::Vocabulary';
30  
31 22 ▶sub vocabulary ($class) {
Subroutine vocabulary: called CC=1 SCAR=0.0
Pod undocumented
32 22 'https://json-schema.org/draft/2020-12/vocab/format-assertion' => 'draft2020-12';
33 }
34  
35 19 ▶sub evaluation_order ($class) { 2 }
Subroutine evaluation_order: called CC=1 SCAR=0.0
Pod undocumented
36  
37 28 ▶sub keywords ($class, $spec_version) {
Subroutine keywords: called CC=2 SCAR=6.9
Pod undocumented
38 return (
39 28 ▶ $spec_version !~ /^draft(?:[467]|2019-09)\z/ ? qw(format) : (),
Branch: 1 branch
BranchTrueFalseTotal
!($spec_version =~ /^draft(?:[467]|2019-09)\z/u) ? : 24 4 28
40 );
41 }
42  
43 # these definitions are shared with the FormatAnnotation vocabulary
44 {
45 # for now, all built-in formats are constrained to the 'string' type
46  
47 0 ▶ my $is_email = sub { # email, idn-email
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 require Email::Address::XS; Email::Address::XS->VERSION(1.04);
49 0 Email::Address::XS->parse_bare_address($_[0])->is_valid;
50 38 };
51 9 ▶ my $is_hostname = sub { # hostname, idn-hostname
Subroutine __ANON__: called CC=2 SCAR=7.6
52 # A dotted quad (such as 127.0.0.1) is not considered a domain, but the use of
53 # domain_disable_tld_validation results in a valid result anyway.
54 # see https://github.com/houseabsolute/Data-Validate-Domain/pull/15
55 9 ▶ return 0 if $_[0] =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\z/u 2 7 9
56  
57 # FIXME: draft7 hostname uses RFC1034, draft2019-09+ hostname uses RFC1123
58 0 require Data::Validate::Domain; Data::Validate::Domain->VERSION(0.13);
59  
60 0 Data::Validate::Domain::is_domain($_[0],
61 { domain_disable_tld_validation => 1, domain_allow_single_label => 1 });
62 38 };
63 0 ▶ my $idn_decode = sub { # idn-hostname
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 require Net::IDN::Encode; Net::IDN::Encode->VERSION('2.600');
65 0 try { return Net::IDN::Encode::domain_to_ascii($_[0]) } catch ($e) { return $_[0]; }
66 38 };
67 61 ▶ my $is_ipv4 = sub { # ipv4, ipv6
Subroutine __ANON__: called CC=3 SCAR=11.0
68 61 my @o = split(/\./, $_[0], 5);
69 61 ▶ @o == 4 && (grep /^(?:0|[1-9][0-9]{0,2})\z/, @o) == 4 && (grep $_ < 256, @o) == 4;
Branch: 1 branch
BranchTrueFalseTotal
@o == 4 and grep(/^(?:0|[1-9][0-9]{0,2})\z/u, @o) == 4 and grep(($_ < 256), @o) == 4 18 43 61
Condition100%3/3
@o == 4 and grep(/^(?:0|[1-9][0-9]{0,2})\z/u, @o) == 4
!ll&&!rl&&r
192418
MC/DC100%2/2
@o == 4 and grep(/^(?:0|[1-9][0-9]{0,2})\z/u, @o) == 4
@o == 4 grep(/^(?:0|[1-9][0-9]{0,2})\z/u, @o) == 4
Truth table100%3/3
A and B
A= @o == 4B= grep(/^(?:0|[1-9][0-9]{0,2})\z/u, @o) == 4
ABresult
0X0
100
111
70 38 };
71 # https://datatracker.ietf.org/doc/html/rfc3339#appendix-A
72 # Changes in the 2000 version as defined in https://en.wikipedia.org/wiki/ISO_8601#Durations
73 # (that allow fractional numbers) are NOT included
74 38 my $duration_re = do { # duration
75 38 my $num = '[0-9]+';
76 38 my $second = "${num}S";
77 38 my $minute = "${num}M(?:$second)?";
78 38 my $hour = "${num}H(?:$minute)?";
79 38 my $time = "T(?:$hour|$minute|$second)";
80 38 my $day = "${num}D";
81 38 my $month = "${num}M(?:$day)?";
82 38 my $year = "${num}Y(?:$month)?";
83 38 my $week = "${num}W";
84 38 my $date = "(?:$year|$month|$day)(?:$time)?";
85 38 qr{^P(?:$week|$date|$time)\z};
86 };
87  
88 75 ▶ state sub days_in_month ($month) {
Subroutine days_in_month: called CC=6 SCAR=23.5
89 75 ▶ $month == 2 ? 28
Branch: 2 branches
BranchTrueFalseTotal
$month == 2 ? : 12 63 75
$month == 4 || $month == 6 || $month == 9 || $month == 11 ? : 0 63 63
Condition33%3/9
$month == 4 or $month == 6 or $month == 9 or $month == 11
l!l&&r!l&&!r
0063
$month == 4 or $month == 6 or $month == 9
l!l&&r!l&&!r
0063
$month == 4 or $month == 6
l!l&&r!l&&!r
0063
MC/DC0%0/4
$month == 4 or $month == 6 or $month == 9 or $month == 11
$month == 4 $month == 6 $month == 9 $month == 11
Truth table20%1/5
A or B or C or D
A= $month == 4B= $month == 6C= $month == 9D= $month == 11
ABCDresult
1XXX1
01XX1
001X1
00011
00000
90 : $month == 4 || $month == 6 || $month == 9 || $month == 11 ? 30
91 : 31;
92 }
93  
94 my $formats = +{
95 53 ▶ 'date-time' => sub {
Subroutine __ANON__: called CC=37 SCAR=44.7
96 # https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6
97 $_[0] =~ m/^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ia
98 && $2 >= 1 && $2 <= 12 # date-month
99 && $3 >= 1 && $3 <= 31 # date-mday
100 && $4 <= 23 # time-hour
101 && $5 <= 59 # time-minute
102 && $6 <= 60 # time-second
103 && (!defined $7 || abs($7) <= 23) # time-hour in time-numoffset
104 && (!defined $8 || $8 <= 59) # time-minute in time-numoffset
105 && ($3 <= days_in_month($2)
106 || ($2 == 2 && $3 == 29 && $1 % 4 == 0 && ($1 % 100 != 0 || $1 % 400 == 0)))
107 53 ▶ && ($6 < 60 || do {
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $2 >= 1 and $2 <= 12 and $3 >= 1 and $3 <= 31 and $4 <= 23 and $5 <= 59 and $6 <= 60 and !defined($7) || abs $7 <= 23 and !defined($8) || $8 <= 59 and $3 <= days_in_month($2) || $2 == 2 && $3 == 29 && $1 % 4 == 0 && ($1 % 100 != 0 || $1 % 400 == 0) and $6 < 60 || do { () = ($1, $2, $3, $4, $5); if (defined $7 and $7 != 0 || $8 != 0) { my $mult = $7 < 0 ? 1 : -1; $hour += $mult * abs($7); $minute += $mult * $8; $minute += 60, $hour -= 1 if $minute < 0; $minute -= 60, $hour += 1 if $minute >= 60; $hour += 24, $day -= 1 if $hour < 0; $hour -= 24, $day += 1 if $hour >= 24; $day += days_in_month(($month + 11) % 12), $month -= 1 if $day < 1; $day -= days_in_month($month), $month += 1 if $day > days_in_month($month); $month += 12, $year -= 1 if $month < 1; $month -= 12, $year += 1 if $month > 12; } ; $hour == 23 and $minute == 59 and $month == 6 && $day == 30 || $month == 12 && $day == 31 } 47 6 53
Condition57%33/57
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai && $2 >= 1 && $2 <= 12 && $3 >= 1 && $3 <= 31 && $4 <= 23 && $5 <= 59 && $6 <= 60 && (!defined($7) || abs $7 <= 23) && (!defined($8) || $8 <= 59) && ($3 <= days_in_month($2) || $2 == 2 && $3 == 29 && $1 % 4 == 0 && ($1 % 100 != 0 || $1 % 400 == 0)) && ($6 < 60 || do { () = ($1, $2, $3, $4, $5); if (defined $7 and $7 != 0 || $8 != 0) { my $mult = $7 < 0 ? 1 : -1; $hour += $mult * abs($7); $minute += $mult * $8; $minute += 60, $hour -= 1 if $minute < 0; $minute -= 60, $hour += 1 if $minute >= 60; $hour += 24, $day -= 1 if $hour < 0; $hour -= 24, $day += 1 if $hour >= 24; $day += days_in_month(($month + 11) % 12), $month -= 1 if $day < 1; $day -= days_in_month($month), $month += 1 if $day > days_in_month($month); $month += 12, $year -= 1 if $month < 1; $month -= 12, $year += 1 if $month > 12; } ; $hour == 23 and $minute == 59 and $month == 6 && $day == 30 || $month == 12 && $day == 31 })
!ll&&!rl&&r
61631
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $2 >= 1 and $2 <= 12 and $3 >= 1 and $3 <= 31 and $4 <= 23 and $5 <= 59 and $6 <= 60 and !defined($7) || abs $7 <= 23 and !defined($8) || $8 <= 59 and $3 <= days_in_month($2) || $2 == 2 && $3 == 29 && $1 % 4 == 0 && ($1 % 100 != 0 || $1 % 400 == 0)
!ll&&!rl&&r
0647
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $2 >= 1 and $2 <= 12 and $3 >= 1 and $3 <= 31 and $4 <= 23 and $5 <= 59 and $6 <= 60 and !defined($7) || abs $7 <= 23 and !defined($8) || $8 <= 59
!ll&&!rl&&r
0053
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $2 >= 1 and $2 <= 12 and $3 >= 1 and $3 <= 31 and $4 <= 23 and $5 <= 59 and $6 <= 60 and !defined($7) || abs $7 <= 23
!ll&&!rl&&r
0053
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $2 >= 1 and $2 <= 12 and $3 >= 1 and $3 <= 31 and $4 <= 23 and $5 <= 59 and $6 <= 60
!ll&&!rl&&r
0053
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $2 >= 1 and $2 <= 12 and $3 >= 1 and $3 <= 31 and $4 <= 23 and $5 <= 59
!ll&&!rl&&r
0053
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $2 >= 1 and $2 <= 12 and $3 >= 1 and $3 <= 31 and $4 <= 23
!ll&&!rl&&r
0053
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $2 >= 1 and $2 <= 12 and $3 >= 1 and $3 <= 31
!ll&&!rl&&r
0053
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $2 >= 1 and $2 <= 12 and $3 >= 1
!ll&&!rl&&r
0053
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $2 >= 1 and $2 <= 12
!ll&&!rl&&r
0053
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $2 >= 1
!ll&&!rl&&r
0053
not defined $7 or abs $7 <= 23
l!l&&r!l&&!r
33200
not defined $8 or $8 <= 59
l!l&&r!l&&!r
33200
$3 <= days_in_month($2) or $2 == 2 and $3 == 29 and $1 % 4 == 0 and $1 % 100 != 0 || $1 % 400 == 0
l!l&&r!l&&!r
4166
$2 == 2 and $3 == 29 and $1 % 4 == 0 and $1 % 100 != 0 || $1 % 400 == 0
!ll&&!rl&&r
246
$2 == 2 and $3 == 29 and $1 % 4 == 0
!ll&&!rl&&r
0210
$2 == 2 and $3 == 29
!ll&&!rl&&r
0012
$1 % 100 != 0 or $1 % 400 == 0
l!l&&r!l&&!r
244
$6 < 60 or do { () = ($1, $2, $3, $4, $5); if (defined $7 and $7 != 0 || $8 != 0) { my $mult = $7 < 0 ? 1 : -1; $hour += $mult * abs($7); $minute += $mult * $8; $minute += 60, $hour -= 1 if $minute < 0; $minute -= 60, $hour += 1 if $minute >= 60; $hour += 24, $day -= 1 if $hour < 0; $hour -= 24, $day += 1 if $hour >= 24; $day += days_in_month(($month + 11) % 12), $month -= 1 if $day < 1; $day -= days_in_month($month), $month += 1 if $day > days_in_month($month); $month += 12, $year -= 1 if $month < 1; $month -= 12, $year += 1 if $month > 12; } ; $hour == 23 and $minute == 59 and $month == 6 && $day == 30 || $month == 12 && $day == 31 }
l!l&&r!l&&!r
112016
MC/DC0%0/20
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai && $2 >= 1 && $2 <= 12 && $3 >= 1 && $3 <= 31 && $4 <= 23 && $5 <= 59 && $6 <= 60 && (!defined($7) || abs $7 <= 23) && (!defined($8) || $8 <= 59) && ($3 <= days_in_month($2) || $2 == 2 && $3 == 29 && $1 % 4 == 0 && ($1 % 100 != 0 || $1 % 400 == 0)) && ($6 < 60 || do { () = ($1, $2, $3, $4, $5); if (defined $7 and $7 != 0 || $8 != 0) { my $mult = $7 < 0 ? 1 : -1; $hour += $mult * abs($7); $minute += $mult * $8; $minute += 60, $hour -= 1 if $minute < 0; $minute -= 60, $hour += 1 if $minute >= 60; $hour += 24, $day -= 1 if $hour < 0; $hour -= 24, $day += 1 if $hour >= 24; $day += days_in_month(($month + 11) % 12), $month -= 1 if $day < 1; $day -= days_in_month($month), $month += 1 if $day > days_in_month($month); $month += 12, $year -= 1 if $month < 1; $month -= 12, $year += 1 if $month > 12; } ; $hour == 23 and $minute == 59 and $month == 6 && $day == 30 || $month == 12 && $day == 31 })
too many conditions
108 36 my ($year, $month, $day, $hour, $minute) = ($1, $2, $3, $4, $5);
109  
110 36 ▶ if (defined $7 && ($7 != 0 || $8 != 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $7 and $7 != 0 || $8 != 0) 20 16 36
Condition50%3/6
defined $7 and $7 != 0 || $8 != 0
!ll&&!rl&&r
16020
$7 != 0 or $8 != 0
l!l&&r!l&&!r
2000
MC/DC33%1/3
defined $7 and $7 != 0 || $8 != 0
defined $7 $7 != 0 $8 != 0
Truth table50%2/4
A and B or C
A= defined $7B= $7 != 0C= $8 != 0
ABCresult
0XX0
1000
11X1
1011
111 20 ▶ my $mult = ($7 < 0 ? 1 : -1); # if offset is negative, we ADD; if positive, we SUBTRACT
Branch: 1 branch
BranchTrueFalseTotal
$7 < 0 ? : 18 2 20
112 20 $hour += $mult * abs($7);
113 20 $minute += $mult * $8;
114  
115 20 ▶ $minute += 60, $hour -= 1 if $minute < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $minute < 0 2 18 20
116 20 ▶ $minute -= 60, $hour += 1 if $minute >= 60;
Branch: 1 branch
BranchTrueFalseTotal
if $minute >= 60 0 20 20
117  
118 20 ▶ $hour += 24, $day -= 1 if $hour < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $hour < 0 2 18 20
119 20 ▶ $hour -= 24, $day += 1 if $hour >= 24;
Branch: 1 branch
BranchTrueFalseTotal
if $hour >= 24 0 20 20
120  
121 20 ▶ $day += days_in_month(($month + 11) % 12), $month -= 1 if $day < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $day < 1 2 18 20
122 20 ▶ $day -= days_in_month($month), $month += 1 if $day > days_in_month($month);
Branch: 1 branch
BranchTrueFalseTotal
if $day > days_in_month($month) 0 20 20
123  
124 20 ▶ $month += 12, $year -= 1 if $month < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $month < 1 2 18 20
125 20 ▶ $month -= 12, $year += 1 if $month > 12;
Branch: 1 branch
BranchTrueFalseTotal
if $month > 12 0 20 20
126 }
127  
128 # a leap second can appear only as 23:59:60 UTC, and only on June 30 or December 31
129 36 ▶ $hour == 23 && $minute == 59
Branch: 1 branch
BranchTrueFalseTotal
$hour == 23 and $minute == 59 and $month == 6 && $day == 30 || $month == 12 && $day == 31 36 0 36
Condition53%8/15
$hour == 23 && $minute == 59 && ($month == 6 && $day == 30 || $month == 12 && $day == 31)
!ll&&!rl&&r
01620
$hour == 23 and $minute == 59
!ll&&!rl&&r
0036
$month == 6 and $day == 30 or $month == 12 and $day == 31
l!l&&r!l&&!r
02016
$month == 6 and $day == 30
!ll&&!rl&&r
3600
$month == 12 and $day == 31
!ll&&!rl&&r
01620
MC/DC16%1/6
$hour == 23 && $minute == 59 && ($month == 6 && $day == 30 || $month == 12 && $day == 31)
$hour == 23 $minute == 59 $month == 6 $day == 30 $month == 12 $day == 31
Truth table22%2/9
A and B && C and D or E and F
A= $hour == 23B= $minute == 59C= $month == 6D= $day == 30E= $month == 12F= $day == 31
ABCDEFresult
0XXXXX0
10XXXX0
110X0X0
110X100
11100X0
1110100
1111XX1
110X111
1110111
130 && (($month == 6 && $day == 30) || ($month == 12 && $day == 31));
131 }
132 );
133 },
134 6 ▶ date => sub {
Subroutine __ANON__: called CC=11 SCAR=42.5
135 # https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6 full-date
136 6 ▶ $_[0] =~ m/^(\d{4})-(\d\d)-(\d\d)\z/a
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)\z/a and $2 >= 1 and $2 <= 12 and $3 >= 1 and $3 <= 31 and $3 <= days_in_month($2) || $2 == 2 && $3 == 29 && $1 % 4 == 0 && ($1 % 100 != 0 || $1 % 400 == 0) 0 6 6
Condition16%5/30
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)\z/a && $2 >= 1 && $2 <= 12 && $3 >= 1 && $3 <= 31 && ($3 <= days_in_month($2) || $2 == 2 && $3 == 29 && $1 % 4 == 0 && ($1 % 100 != 0 || $1 % 400 == 0))
!ll&&!rl&&r
600
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)\z/a and $2 >= 1 and $2 <= 12 and $3 >= 1 and $3 <= 31
!ll&&!rl&&r
600
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)\z/a and $2 >= 1 and $2 <= 12 and $3 >= 1
!ll&&!rl&&r
600
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)\z/a and $2 >= 1 and $2 <= 12
!ll&&!rl&&r
600
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)\z/a and $2 >= 1
!ll&&!rl&&r
600
$3 <= days_in_month($2) or $2 == 2 and $3 == 29 and $1 % 4 == 0 and $1 % 100 != 0 || $1 % 400 == 0
l!l&&r!l&&!r
000
$2 == 2 and $3 == 29 and $1 % 4 == 0 and $1 % 100 != 0 || $1 % 400 == 0
!ll&&!rl&&r
000
$2 == 2 and $3 == 29 and $1 % 4 == 0
!ll&&!rl&&r
000
$2 == 2 and $3 == 29
!ll&&!rl&&r
000
$1 % 100 != 0 or $1 % 400 == 0
l!l&&r!l&&!r
000
MC/DC0%0/11
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)\z/a && $2 >= 1 && $2 <= 12 && $3 >= 1 && $3 <= 31 && ($3 <= days_in_month($2) || $2 == 2 && $3 == 29 && $1 % 4 == 0 && ($1 % 100 != 0 || $1 % 400 == 0))
$_[0] =~ /^(\d{4})-(\d\d)-(\d\d)\z/a $2 >= 1 $2 <= 12 $3 >= 1 $3 <= 31 $3 <= days_in_month($2) $2 == 2 $3 == 29 $1 % 4 == 0 $1 % 100 != 0 $1 % 400 == 0
Truth table8%1/12
A and B and C and D and E && F or G and H and I and J or K
A= $_[0] =~ /^(\d{4})-(\d\d)-(\d\d)\z/aB= $2 >= 1C= $2 <= 12D= $3 >= 1E= $3 <= 31F= $3 <= days_in_month($2)G= $2 == 2H= $3 == 29I= $1 % 4 == 0J= $1 % 100 != 0K= $1 % 400 == 0
ABCDEFGHIJKresult
0XXXXXXXXXX0
10XXXXXXXXX0
110XXXXXXXX0
1110XXXXXXX0
11110XXXXXX0
1111100XXXX0
11111010XXX0
111110110XX0
111110111000
111111XXXXX1
1111101111X1
111110111011
137 && $2 >= 1 && $2 <= 12 # date-month
138 && $3 >= 1 && $3 <= 31 # date-mday
139 && ($3 <= days_in_month($2)
140 || ($2 == 2 && $3 == 29 && $1 % 4 == 0 && ($1 % 100 != 0 || $1 % 400 == 0)));
141 },
142 80 ▶ time => sub {
Subroutine __ANON__: called CC=17 SCAR=29.4
143 # https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6 full-time
144 $_[0] =~ m/^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ia
145 && $1 <= 23 # time-hour
146 && $2 <= 59 # time-minute
147 && $3 <= 60 # time-second
148 && (!defined $4 || abs($4) <= 23) # time-hour in time-numoffset
149 && (!defined $5 || $5 <= 59) # time-minute in time-numoffset
150 80 ▶ && ($3 < 60 || do {
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $1 <= 23 and $2 <= 59 and $3 <= 60 and !defined($4) || abs $4 <= 23 and !defined($5) || $5 <= 59 and $3 < 60 || do { () = ($1, $2); if (defined $4 and $4 != 0 || $5 != 0) { my $mult = $4 < 0 ? 1 : -1; $hour += $mult * abs($4); $minute += $mult * $5; $minute += 60, $hour -= 1 if $minute < 0; $minute -= 60, $hour += 1 if $minute >= 60; } ; $hour % 24 == 23 and $minute == 59 } 68 12 80
Condition74%20/27
$_[0] =~ /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai && $1 <= 23 && $2 <= 59 && $3 <= 60 && (!defined($4) || abs $4 <= 23) && (!defined($5) || $5 <= 59) && ($3 < 60 || do { () = ($1, $2); if (defined $4 and $4 != 0 || $5 != 0) { my $mult = $4 < 0 ? 1 : -1; $hour += $mult * abs($4); $minute += $mult * $5; $minute += 60, $hour -= 1 if $minute < 0; $minute -= 60, $hour += 1 if $minute >= 60; } ; $hour % 24 == 23 and $minute == 59 })
!ll&&!rl&&r
123632
$_[0] =~ /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $1 <= 23 and $2 <= 59 and $3 <= 60 and !defined($4) || abs $4 <= 23 and !defined($5) || $5 <= 59
!ll&&!rl&&r
12068
$_[0] =~ /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $1 <= 23 and $2 <= 59 and $3 <= 60 and !defined($4) || abs $4 <= 23
!ll&&!rl&&r
12068
$_[0] =~ /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $1 <= 23 and $2 <= 59 and $3 <= 60
!ll&&!rl&&r
12068
$_[0] =~ /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $1 <= 23 and $2 <= 59
!ll&&!rl&&r
12068
$_[0] =~ /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai and $1 <= 23
!ll&&!rl&&r
12068
not defined $4 or abs $4 <= 23
l!l&&r!l&&!r
18500
not defined $5 or $5 <= 59
l!l&&r!l&&!r
18500
$3 < 60 or do { () = ($1, $2); if (defined $4 and $4 != 0 || $5 != 0) { my $mult = $4 < 0 ? 1 : -1; $hour += $mult * abs($4); $minute += $mult * $5; $minute += 60, $hour -= 1 if $minute < 0; $minute -= 60, $hour += 1 if $minute >= 60; } ; $hour % 24 == 23 and $minute == 59 }
l!l&&r!l&&!r
23036
MC/DC30%3/10
$_[0] =~ /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai && $1 <= 23 && $2 <= 59 && $3 <= 60 && (!defined($4) || abs $4 <= 23) && (!defined($5) || $5 <= 59) && ($3 < 60 || do { () = ($1, $2); if (defined $4 and $4 != 0 || $5 != 0) { my $mult = $4 < 0 ? 1 : -1; $hour += $mult * abs($4); $minute += $mult * $5; $minute += 60, $hour -= 1 if $minute < 0; $minute -= 60, $hour += 1 if $minute >= 60; } ; $hour % 24 == 23 and $minute == 59 })
$_[0] =~ /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/ai $1 <= 23 $2 <= 59 $3 <= 60 not defined $4 abs $4 <= 23 not defined $5 $5 <= 59 $3 < 60 do { () = ($1, $2); if (defined $4 and $4 != 0 || $5 != 0) { my $mult = $4 < 0 ? 1 : -1; $hour += $mult * abs($4); $minute += $mult * $5; $minute += 60, $hour -= 1 if $minute < 0; $minute -= 60, $hour += 1 if $minute >= 60; } ; $hour % 24 == 23 and $minute == 59 }
Truth table31%6/19
A and B and C and D and not(E) or F and not(G) or H && I or J
A= $_[0] =~ /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:Z|([+-]\d\d):(\d\d))\z/aiB= $1 <= 23C= $2 <= 59D= $3 <= 60E= not defined $4F= abs $4 <= 23G= not defined $5H= $5 <= 59I= $3 < 60J= do { () = ($1, $2); if (defined $4 and $4 != 0 || $5 != 0) { my $mult = $4 < 0 ? 1 : -1; $hour += $mult * abs($4); $minute += $mult * $5; $minute += 60, $hour -= 1 if $minute < 0; $minute -= 60, $hour += 1 if $minute >= 60; } ; $hour % 24 == 23 and $minute == 59 }
ABCDEFGHIJresult
0XXXXXXXXX0
10XXXXXXXX0
110XXXXXXX0
1110XXXXXX0
111100XXXX0
11111X00XX0
11110100XX0
11111X1X000
11111X01000
1111011X000
11110101000
11111X1X1X1
11111X1X011
11111X011X1
11111X01011
1111011X1X1
1111011X011
111101011X1
11110101011
151 66 my ($hour, $minute) = ($1, $2);
152 66 ▶ if (defined $4 && ($4 != 0 || $5 != 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $4 and $4 != 0 || $5 != 0) 48 18 66
Condition66%4/6
defined $4 and $4 != 0 || $5 != 0
!ll&&!rl&&r
18048
$4 != 0 or $5 != 0
l!l&&r!l&&!r
36120
MC/DC33%1/3
defined $4 and $4 != 0 || $5 != 0
defined $4 $4 != 0 $5 != 0
Truth table75%3/4
A and B or C
A= defined $4B= $4 != 0C= $5 != 0
ABCresult
0XX0
1000
11X1
1011
153 48 ▶ my $mult = ($4 < 0 ? 1 : -1); # if offset is negative, we ADD; if positive, we SUBTRACT
Branch: 1 branch
BranchTrueFalseTotal
$4 < 0 ? : 18 30 48
154 48 $hour += $mult * abs($4);
155 48 $minute += $mult * $5;
156  
157 48 ▶ $minute += 60, $hour -= 1 if $minute < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $minute < 0 12 36 48
158 48 ▶ $minute -= 60, $hour += 1 if $minute >= 60; # this line not really needed; always invalid
Branch: 1 branch
BranchTrueFalseTotal
if $minute >= 60 0 48 48
159 }
160  
161 # a leap second can appear only as 23:59:60 UTC
162 66 ▶ $hour % 24 == 23 && $minute == 59;
Branch: 1 branch
BranchTrueFalseTotal
$hour % 24 == 23 and $minute == 59 48 18 66
163 }
164 );
165 },
166 56 ▶ duration => sub { $_[0] =~ $duration_re && $_[0] !~ m{[.,][0-9]+[A-Z].} },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /$duration_re/u and not $_[0] =~ /[.,][0-9]+[A-Z]./u 24 32 56
167 0 ▶ email => sub { $is_email->($_[0]) && $_[0] !~ /[^[:ascii:]]/ },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
&$is_email($_[0]) and not $_[0] =~ /[^[:ascii:]]/u 0 0 0
168 'idn-email' => $is_email,
169 hostname => $is_hostname,
170 0 ▶ 'idn-hostname' => sub { $is_hostname->($idn_decode->($_[0])) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
171 ipv4 => $is_ipv4,
172 107 ▶ ipv6 => sub {
Subroutine __ANON__: called CC=16 SCAR=31.9
173 ($_[0] =~ /^(?:[[:xdigit:]]{0,4}:){0,8}[[:xdigit:]]{0,4}\z/a
174 || $_[0] =~ /^(?:[[:xdigit:]]{0,4}:){1,7}((?:[0-9]{1,3}\.){3}[0-9]{1,3})\z/a
175 && $is_ipv4->($1))
176 && $_[0] !~ /:::/
177 && $_[0] !~ /^:[^:]/
178 && $_[0] !~ /[^:]:\z/
179 107 ▶ && do {
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^(?:[[:xdigit:]]{0,4}:){0,8}[[:xdigit:]]{0,4}\z/a || $_[0] =~ /^(?:[[:xdigit:]]{0,4}:){1,7}((?:[0-9]{1,3}\.){3}[0-9]{1,3})\z/a && &$is_ipv4($1) and not $_[0] =~ /:::/u and not $_[0] =~ /^:[^:]/u and not $_[0] =~ /[^:]:\z/u and do { my $double_colons = (() = $_[0] =~ /::/gu); my $colon_components = grep(length($_), split(/:+/u, $_[0], -1)); $double_colons == 1 and !defined($1) && $colon_components < 8 || defined $1 && $colon_components < 7 or $double_colons == 0 and !defined($1) && $colon_components == 8 || defined $1 && $colon_components == 7 } 78 29 107
Condition73%11/15
$_[0] =~ /^(?:[[:xdigit:]]{0,4}:){0,8}[[:xdigit:]]{0,4}\z/a || $_[0] =~ /^(?:[[:xdigit:]]{0,4}:){1,7}((?:[0-9]{1,3}\.){3}[0-9]{1,3})\z/a && &$is_ipv4($1) and not $_[0] =~ /:::/u and not $_[0] =~ /^:[^:]/u and not $_[0] =~ /[^:]:\z/u
!ll&&!rl&&r
23678
$_[0] =~ /^(?:[[:xdigit:]]{0,4}:){0,8}[[:xdigit:]]{0,4}\z/a || $_[0] =~ /^(?:[[:xdigit:]]{0,4}:){1,7}((?:[0-9]{1,3}\.){3}[0-9]{1,3})\z/a && &$is_ipv4($1) and not $_[0] =~ /:::/u and not $_[0] =~ /^:[^:]/u
!ll&&!rl&&r
17684
$_[0] =~ /^(?:[[:xdigit:]]{0,4}:){0,8}[[:xdigit:]]{0,4}\z/a || $_[0] =~ /^(?:[[:xdigit:]]{0,4}:){1,7}((?:[0-9]{1,3}\.){3}[0-9]{1,3})\z/a && &$is_ipv4($1) and not $_[0] =~ /:::/u
!ll&&!rl&&r
17090
$_[0] =~ /^(?:[[:xdigit:]]{0,4}:){0,8}[[:xdigit:]]{0,4}\z/a or $_[0] =~ /^(?:[[:xdigit:]]{0,4}:){1,7}((?:[0-9]{1,3}\.){3}[0-9]{1,3})\z/a and &$is_ipv4($1)
l!l&&r!l&&!r
90017
$_[0] =~ /^(?:[[:xdigit:]]{0,4}:){1,7}((?:[0-9]{1,3}\.){3}[0-9]{1,3})\z/a and &$is_ipv4($1)
!ll&&!rl&&r
1700
MC/DC50%3/6
$_[0] =~ /^(?:[[:xdigit:]]{0,4}:){0,8}[[:xdigit:]]{0,4}\z/a || $_[0] =~ /^(?:[[:xdigit:]]{0,4}:){1,7}((?:[0-9]{1,3}\.){3}[0-9]{1,3})\z/a && &$is_ipv4($1) and not $_[0] =~ /:::/u and not $_[0] =~ /^:[^:]/u and not $_[0] =~ /[^:]:\z/u
$_[0] =~ /^(?:[[:xdigit:]]{0,4}:){0,8}[[:xdigit:]]{0,4}\z/a $_[0] =~ /^(?:[[:xdigit:]]{0,4}:){1,7}((?:[0-9]{1,3}\.){3}[0-9]{1,3})\z/a &$is_ipv4($1) not $_[0] =~ /:::/u not $_[0] =~ /^:[^:]/u not $_[0] =~ /[^:]:\z/u
Truth table40%4/10
A or B and C and not(D) and not(E) and not(F)
A= $_[0] =~ /^(?:[[:xdigit:]]{0,4}:){0,8}[[:xdigit:]]{0,4}\z/aB= $_[0] =~ /^(?:[[:xdigit:]]{0,4}:){1,7}((?:[0-9]{1,3}\.){3}[0-9]{1,3})\z/aC= &$is_ipv4($1)D= not $_[0] =~ /:::/uE= not $_[0] =~ /^:[^:]/uF= not $_[0] =~ /[^:]:\z/u
ABCDEFresult
00XXXX0
010XXX0
1XX0XX0
0110XX0
1XX10X0
01110X0
1XX1100
0111100
1XX1111
0111111
180 78 my $double_colons = ()= ($_[0] =~ /::/g);
181 78 my $colon_components = grep length, split(/:+/, $_[0], -1);
182 78 ▶ ($double_colons == 1
Branch: 1 branch
BranchTrueFalseTotal
$double_colons == 1 and !defined($1) && $colon_components < 8 || defined $1 && $colon_components < 7 or $double_colons == 0 and !defined($1) && $colon_components == 8 || defined $1 && $colon_components == 7 54 24 78
Condition55%15/27
$double_colons == 1 && (!defined($1) && $colon_components < 8 || defined $1 && $colon_components < 7) || $double_colons == 0 && (!defined($1) && $colon_components == 8 || defined $1 && $colon_components == 7)
l!l&&r!l&&!r
54186
$double_colons == 1 and !defined($1) && $colon_components < 8 || defined $1 && $colon_components < 7
!ll&&!rl&&r
18654
not defined $1 and $colon_components < 8 or defined $1 and $colon_components < 7
l!l&&r!l&&!r
5406
not defined $1 and $colon_components < 8
!ll&&!rl&&r
0654
defined $1 and $colon_components < 7
!ll&&!rl&&r
600
$double_colons == 0 and !defined($1) && $colon_components == 8 || defined $1 && $colon_components == 7
!ll&&!rl&&r
6018
not defined $1 and $colon_components == 8 or defined $1 and $colon_components == 7
l!l&&r!l&&!r
1800
not defined $1 and $colon_components == 8
!ll&&!rl&&r
0018
defined $1 and $colon_components == 7
!ll&&!rl&&r
000
MC/DC10%1/10
$double_colons == 1 && (!defined($1) && $colon_components < 8 || defined $1 && $colon_components < 7) || $double_colons == 0 && (!defined($1) && $colon_components == 8 || defined $1 && $colon_components == 7)
$double_colons == 1 not defined $1 $colon_components < 8 defined $1 $colon_components < 7 $double_colons == 0 not defined $1 $colon_components == 8 defined $1 $colon_components == 7
Truth table6%3/43
A and not(B) and C or D and E || F and not(G) and H or I and J
A= $double_colons == 1B= not defined $1C= $colon_components < 8D= defined $1E= $colon_components < 7F= $double_colons == 0G= not defined $1H= $colon_components == 8I= defined $1J= $colon_components == 7
ABCDEFGHIJresult
111XXXXXXX1
10X11XXXXX1
11011XXXXX1
0XXXX111XX1
0XXXX10X111
0XXXX110111
10X0X111XX1
10X0X10X111
10X0X110111
10X10111XX1
10X1010X111
10X10110111
1100X111XX1
1100X10X111
1100X110111
11010111XX1
1101010X111
11010110111
0XXXX0XXXX0
0XXXX10X0X0
0XXXX10X100
0XXXX1100X0
0XXXX110100
10X0X0XXXX0
10X0X10X0X0
10X0X10X100
10X0X1100X0
10X0X110100
10X100XXXX0
10X1010X0X0
10X1010X100
10X101100X0
10X10110100
1100X0XXXX0
1100X10X0X0
1100X10X100
1100X1100X0
1100X110100
110100XXXX0
1101010X0X0
1101010X100
110101100X0
11010110100
183 && ((!defined $1 && $colon_components < 8) || (defined $1 && $colon_components < 7)))
184 ||
185 ($double_colons == 0
186 && ((!defined $1 && $colon_components == 8) || (defined $1 && $colon_components == 7)));
187 };
188 },
189 4 ▶ uri => sub {
Subroutine __ANON__: called CC=7 SCAR=25.1
190 4 ▶ return if $_[0] =~ /%.?\z/ or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a 0 4 4
Condition33%2/6
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a
l!l&&r!l&&!r
004
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a
l!l&&r!l&&!r
004
MC/DC0%0/3
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a
$_[0] =~ /%.?\z/u $_[0] =~ /%[^[:xdigit:]]/a $_[0] =~ /%.[^[:xdigit:]]/a
Truth table25%1/4
A or B or C
A= $_[0] =~ /%.?\z/uB= $_[0] =~ /%[^[:xdigit:]]/aC= $_[0] =~ /%.[^[:xdigit:]]/a
ABCresult
1XX1
01X1
0011
0000
191 4 ▶ return if $_[0] =~ /[^[:ascii:]]/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /[^[:ascii:]]/u 0 4 4
192 4 my $uri = Mojo::URL->new($_[0]);
193 4 ▶ return if not fc($uri->to_unsafe_string) eq fc($_[0]) && $uri->is_abs;
Branch: 1 branch
BranchTrueFalseTotal
unless fc $uri->to_unsafe_string eq fc $_[0] and $uri->is_abs 0 4 4
Condition33%1/3
fc $uri->to_unsafe_string eq fc $_[0] and $uri->is_abs
!ll&&!rl&&r
004
MC/DC0%0/2
fc $uri->to_unsafe_string eq fc $_[0] and $uri->is_abs
fc $uri->to_unsafe_string eq fc $_[0] $uri->is_abs
Truth table33%1/3
A and B
A= fc $uri->to_unsafe_string eq fc $_[0]B= $uri->is_abs
ABresult
0X0
100
111
194 4 require Data::Validate::URI;
195 0 return Data::Validate::URI::is_uri($_[0]);
196 },
197 4 ▶ 'uri-reference' => sub {
Subroutine __ANON__: called CC=5 SCAR=20.1
198 4 ▶ return if $_[0] =~ /%.?\z/ or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a 0 4 4
Condition33%2/6
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a
l!l&&r!l&&!r
004
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a
l!l&&r!l&&!r
004
MC/DC0%0/3
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a
$_[0] =~ /%.?\z/u $_[0] =~ /%[^[:xdigit:]]/a $_[0] =~ /%.[^[:xdigit:]]/a
Truth table25%1/4
A or B or C
A= $_[0] =~ /%.?\z/uB= $_[0] =~ /%[^[:xdigit:]]/aC= $_[0] =~ /%.[^[:xdigit:]]/a
ABCresult
1XX1
01X1
0011
0000
199 4 ▶ return if $_[0] =~ /[^[:ascii:]]/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /[^[:ascii:]]/u 0 4 4
200 4 fc(Mojo::URL->new($_[0])->to_unsafe_string) eq fc($_[0]);
201 },
202 0 ▶ iri => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
203 0 ▶ return if $_[0] =~ /%.?\z/ or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a 0 0 0
Condition0%0/6
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a
l!l&&r!l&&!r
000
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a
l!l&&r!l&&!r
000
MC/DC0%0/3
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a
$_[0] =~ /%.?\z/u $_[0] =~ /%[^[:xdigit:]]/a $_[0] =~ /%.[^[:xdigit:]]/a
Truth table0%0/4
A or B or C
A= $_[0] =~ /%.?\z/uB= $_[0] =~ /%[^[:xdigit:]]/aC= $_[0] =~ /%.[^[:xdigit:]]/a
ABCresult
1XX1
01X1
0011
0000
204 0 Mojo::URL->new($_[0])->is_abs;
205 },
206 0 ▶ 'iri-reference' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
207 0 ▶ return if $_[0] =~ /%.?\z/ or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a 0 0 0
Condition0%0/6
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a
l!l&&r!l&&!r
000
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a
l!l&&r!l&&!r
000
MC/DC0%0/3
$_[0] =~ /%.?\z/u or $_[0] =~ /%[^[:xdigit:]]/a or $_[0] =~ /%.[^[:xdigit:]]/a
$_[0] =~ /%.?\z/u $_[0] =~ /%[^[:xdigit:]]/a $_[0] =~ /%.[^[:xdigit:]]/a
Truth table0%0/4
A or B or C
A= $_[0] =~ /%.?\z/uB= $_[0] =~ /%[^[:xdigit:]]/aC= $_[0] =~ /%.[^[:xdigit:]]/a
ABCresult
1XX1
01X1
0011
0000
208 0 return 1;
209 },
210 4 ▶ uuid => sub { $_[0] =~ /^[[:xdigit:]]{8}-(?:[[:xdigit:]]{4}-){3}[[:xdigit:]]{12}\z/a },
Subroutine __ANON__: called CC=1 SCAR=0.0
211 0 ▶ 'json-pointer' => sub { (!length($_[0]) || $_[0] =~ m{^/}) && $_[0] !~ m{~(?![01])} },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
!length($_[0]) || $_[0] =~ m[^/]u and not $_[0] =~ /~(?![01])/u 0 0 0
Condition0%0/3
not length $_[0] or $_[0] =~ m[^/]u
l!l&&r!l&&!r
000
MC/DC0%0/2
not length $_[0] or $_[0] =~ m[^/]u
not length $_[0] $_[0] =~ m[^/]u
Truth table0%0/3
not(A) or B
A= not length $_[0]B= $_[0] =~ m[^/]u
ABresult
1X1
011
000
212 42 ▶ 'relative-json-pointer' => sub { $_[0] =~ m{^(?:0|[1-9][0-9]*)(?:#\z|\z|/)} && $_[0] !~ m{~(?![01])} },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ m[^(?:0|[1-9][0-9]*)(?:#\z|\z|/)]u and not $_[0] =~ /~(?![01])/u 24 18 42
213 1 ▶ regex => sub {
Subroutine __ANON__: called CC=1 SCAR=0.6
214 0 ▶ local $SIG{__WARN__} = sub { die @_ };
Subroutine __ANON__: not called CC=1 SCAR=1.2
215 0 eval { qr/$_[0]/; 1 };
216 },
217 # uri-template is not implemented, but user can add a custom definition
218 38 };
219  
220 38 my %formats_by_spec_version = (
221 draft4 => [qw(
222 date-time
223 email
224 hostname
225 ipv4
226 ipv6
227 uri
228 )],
229 );
230 38 $formats_by_spec_version{draft6} = [$formats_by_spec_version{draft4}->@*, qw(
231 uri-reference
232 uri-template
233 json-pointer
234 )];
235 38 $formats_by_spec_version{draft7} = [$formats_by_spec_version{draft6}->@*, qw(
236 iri
237 iri-reference
238 idn-email
239 idn-hostname
240 relative-json-pointer
241 regex
242 date
243 time
244 )];
245 $formats_by_spec_version{'draft2019-09'} =
246 38 $formats_by_spec_version{'draft2020-12'} = [$formats_by_spec_version{draft7}->@*, qw(duration uuid)];
247  
248 916 ▶ sub _get_default_format_validation ($class, $state, $format) {
Subroutine _get_default_format_validation: called CC=3 SCAR=11.0
249 # all core formats are of type string (so far)
250 return { type => 'string', sub => $formats->{$format} }
251 if grep $format eq $_, $formats_by_spec_version{$state->{specification_version}}->@*
252 916 ▶ and $formats->{$format};
Branch: 1 branch
BranchTrueFalseTotal
if grep(($format eq $_), @{$formats_by_spec_version{$$state{"specification_version"}}}) and $$formats{$format} 758 158 916
Condition100%3/3
grep(($format eq $_), @{$formats_by_spec_version{$$state{"specification_version"}}}) and $$formats{$format}
!ll&&!rl&&r
13424758
MC/DC100%2/2
grep(($format eq $_), @{$formats_by_spec_version{$$state{"specification_version"}}}) and $$formats{$format}
grep(($format eq $_), @{$formats_by_spec_version{$$state{"specification_version"}}}) $$formats{$format}
Truth table100%3/3
A and B
A= grep(($format eq $_), @{$formats_by_spec_version{$$state{"specification_version"}}})B= $$formats{$format}
ABresult
0X0
100
111
253 }
254 }
255  
256 38 my $warnings = {
257 0 ▶ email => sub { require Email::Address::XS; Email::Address::XS->VERSION(1.04); 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
258 0 ▶ hostname => sub { require Data::Validate::Domain; Data::Validate::Domain->VERSION(0.13); 1 },
Subroutine __ANON__: called CC=1 SCAR=2.6
259 0 ▶ 'idn-hostname' => sub { require Data::Validate::Domain; Data::Validate::Domain->VERSION(0.13); require Net::IDN::Encode; Net::IDN::Encode->VERSION('2.600'); 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
260 0 ▶ uri => sub { require Data::Validate::URI; 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
261 38 };
262 38 $warnings->{'idn-email'} = $warnings->{email};
263  
264 25 ▶sub _traverse_keyword_format ($class, $schema, $state) {
Subroutine _traverse_keyword_format: called CC=5 SCAR=16.1
265 25 ▶ return if not assert_keyword_type($state, $schema, 'string');
Branch: 1 branch
BranchTrueFalseTotal
unless assert_keyword_type($state, $schema, "string") 0 25 25
266  
267 # warn when prereq is missing for a format implementation
268 25 ▶ if (my $warn_sub = $warnings->{$schema->{format}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $warn_sub = $$warnings{$$schema{"format"}}) 1 24 25
269 1 try { $warn_sub->() } catch ($e) { warn $e }
270 }
271  
272 # §7.2.2 (draft2020-12) "When the Format-Assertion vocabulary is declared with a value of true,
273 # implementations MUST provide full validation support for all of the formats defined by this
274 # specification. Implementations that cannot provide full validation support MUST refuse to
275 # process the schema."
276 return E($state, 'unimplemented core format "%s"', $schema->{format})
277 if $schema->{format} eq 'uri-template'
278 25 ▶ and not $state->{evaluator}->_get_format_validation($schema->{format});
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{"format"} eq "uri-template" and not $$state{"evaluator"}->_get_format_validation($$schema{"format"}) 2 23 25
Condition100%3/3
$$schema{"format"} eq "uri-template" and not $$state{"evaluator"}->_get_format_validation($$schema{"format"})
!ll&&!rl&&r
2212
MC/DC100%2/2
$$schema{"format"} eq "uri-template" and not $$state{"evaluator"}->_get_format_validation($$schema{"format"})
$$schema{"format"} eq "uri-template" not $$state{"evaluator"}->_get_format_validation($$schema{"format"})
Truth table100%3/3
A and not(B)
A= $$schema{"format"} eq "uri-template"B= not $$state{"evaluator"}->_get_format_validation($$schema{"format"})
ABresult
0X0
100
111
279  
280 # unimplemented custom formats are detected at runtime, only if actually evaluated
281  
282 23 return 1;
283 }
284  
285 # Note that this method is only callable in draft2020-12 and later, because this vocabulary does not
286 # exist in previous versions
287 27 ▶sub _eval_keyword_format ($class, $data, $schema, $state) {
Subroutine _eval_keyword_format: called CC=13 SCAR=28.2
288 27 A($state, $schema->{format});
289  
290 # unimplemented core formats were already detected in the traverse phase
291  
292 my $spec = $state->{evaluator}->_get_format_validation($schema->{format})
293 27 ▶ // $class->_get_default_format_validation($state, $schema->{format});
Condition66%2/3
$$state{"evaluator"}->_get_format_validation($$schema{"format"}) // $class->_get_default_format_validation($state, $$schema{"format"})
l!l&&r!l&&!r
6210
MC/DC0%0/2
$$state{"evaluator"}->_get_format_validation($$schema{"format"}) // $class->_get_default_format_validation($state, $$schema{"format"})
$$state{"evaluator"}->_get_format_validation($$schema{"format"}) $class->_get_default_format_validation($state, $$schema{"format"})
Truth table66%2/3
A // B
A= $$state{"evaluator"}->_get_format_validation($$schema{"format"})B= $class->_get_default_format_validation($state, $$schema{"format"})
ABresult
1X1
011
000
294  
295 # §7.2.3 (draft2020-12) "When the Format-Assertion vocabulary is specified, implementations MUST
296 # fail upon encountering unknown formats."
297 27 ▶ abort($state, 'unimplemented custom format "%s"', $schema->{format}) if not $spec;
Branch: 1 branch
BranchTrueFalseTotal
unless $spec 1 26 27
298  
299 26 my $type = get_type($data);
300 26 ▶ $type = 'number' if $type eq 'integer';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "integer" 2 24 26
301  
302 return 1 if
303 0 ▶ not ref $spec->{type} eq 'ARRAY' ? any { $type eq $_ } $spec->{type}->@* : $type eq $spec->{type}
Branch: 1 branch
BranchTrueFalseTotal
ref $$spec{'type'} eq 'ARRAY' ? : 0 3 3
Condition44%4/9
$$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
!ll&&!rl&&r
012
$$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number"
!ll&&!rl&&r
003
$$state{"stringy_numbers"} and $type eq "string"
!ll&&!rl&&r
003
MC/DC0%0/4
$$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
$$state{"stringy_numbers"} $type eq "string" ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" &looks_like_number($data)
Truth table0%0/5
A and B and C and D
A= $$state{"stringy_numbers"}B= $type eq "string"C= ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number"D= &looks_like_number($data)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
304 and not ($state->{stringy_numbers} and $type eq 'string'
305 0 ▶ and ref $spec->{type} eq 'ARRAY' ? any { $_ eq 'number' } $spec->{type}->@* : $spec->{type} eq 'number'
Branch: 2 branches
BranchTrueFalseTotal
unless ref $$spec{"type"} eq "ARRAY" ? CORE::any({$type eq $_;} @{$$spec{"type"}}) : $type eq $$spec{"type"} or $$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data) 1 25 26
ref $$spec{'type'} eq 'ARRAY' ? : 0 26 26
Condition100%3/3
ref $$spec{"type"} eq "ARRAY" ? CORE::any({$type eq $_;} @{$$spec{"type"}}) : $type eq $$spec{"type"} or $$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
l!l&&r!l&&!r
2321
MC/DC0%0/2
ref $$spec{"type"} eq "ARRAY" ? CORE::any({$type eq $_;} @{$$spec{"type"}}) : $type eq $$spec{"type"} or $$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
ref $$spec{"type"} eq "ARRAY" ? CORE::any({$type eq $_;} @{$$spec{"type"}}) : $type eq $$spec{"type"} $$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
Truth table66%2/3
A or B
A= ref $$spec{"type"} eq "ARRAY" ? CORE::any({$type eq $_;} @{$$spec{"type"}}) : $type eq $$spec{"type"}B= $$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
ABresult
1X1
011
000
306 and looks_like_number($data));
307  
308 return E($state, 'not a valid %s %s', $schema->{format},
309 ref $spec->{type} eq 'ARRAY' ? join(', ', $spec->{type}->@*) : $spec->{type})
310 25 ▶ if not $spec->{sub}->($data);
Branch: 2 branches
BranchTrueFalseTotal
unless $$spec{"sub"}($data) 13 11 24
ref $$spec{'type'} eq 'ARRAY' ? : 0 13 13
311  
312 11 return 1;
313 }
314  
315 38 1;
316  
317 __END__
↑ Summary Modern/Result.pm »