| 1 | package Data::Sah::Normalize; | ||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | our $DATE = '2021-07-29'; # DATE | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | our $DIST = 'Data-Sah-Normalize'; # DIST | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.051'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||
| 15 | normalize_clset | ||||||||||||||||||||||||||||||||||||||||||||
| 16 | normalize_schema | ||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | $type_re | ||||||||||||||||||||||||||||||||||||||||||||
| 19 | $clause_name_re | ||||||||||||||||||||||||||||||||||||||||||||
| 20 | $clause_re | ||||||||||||||||||||||||||||||||||||||||||||
| 21 | $attr_re | ||||||||||||||||||||||||||||||||||||||||||||
| 22 | $funcset_re | ||||||||||||||||||||||||||||||||||||||||||||
| 23 | $compiler_re | ||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | our $type_re = qr/\A(?:[A-Za-z_]\w*::)*[A-Za-z_]\w*\z/; | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | our $clause_name_re = qr/\A[A-Za-z_]\w*\z/; | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | our $clause_re = qr/\A[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*\z/; | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | our $attr_re = $clause_re; | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | our $funcset_re = qr/\A(?:[A-Za-z_]\w*::)*[A-Za-z_]\w*\z/; | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | our $compiler_re = qr/\A[A-Za-z_]\w*\z/; | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | our $clause_attr_on_empty_clause_re = qr/\A(?:\.[A-Za-z_]\w*)+\z/; | |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | ▶ | sub normalize_clset($;$) { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_clset: called CC=36 SCAR=38.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | my ($clset0, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | $opts //= {}; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts //= {}
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | my $clset = {}; | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | for my $c (sort keys %$clset0) { | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | my $c0 = $c; | |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | my $v = $clset0->{$c}; | |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | # ignore expression | ||||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | my $expr; | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | ▶ | if ($c =~ s/=\z//) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | $expr++; | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # XXX currently can't disregard merge prefix when checking | ||||||||||||||||||||||||||||||||||||||||||||
| 49 | # conflict | ||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | die "Conflict between '$c=' and '$c'" if exists $clset0->{$c}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | $clset->{"$c.is_expr"} = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | my $sc = ""; | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | my $cn; | |||||||||||||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 57 | 5 | my $errp = "Invalid clause name syntax '$c0'"; # error prefix | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | ▶ | if (!$expr && $c =~ s/\A!(?=.)//) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition100%3/3
not $expr and $c =~ s/\A!(?=.)//
MC/DC100%2/2
not $expr and $c =~ s/\A!(?=.)//
not $expr
$c =~ s/\A!(?=.)//
Truth table100%3/3
not(A) and B
A= not $exprB= $c =~ s/\A!(?=.)//
| |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | die "$errp, syntax should be !CLAUSE" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 60 | unless $c =~ $clause_name_re; | ||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | $sc = "!"; | |||||||||||||||||||||||||||||||||||||||||||
| 62 | ▶ | } elsif (!$expr && $c =~ s/(?<=.)\|\z//) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $expr and $c =~ s/(?<=.)\|\z//
MC/DC100%2/2
not $expr and $c =~ s/(?<=.)\|\z//
not $expr
$c =~ s/(?<=.)\|\z//
Truth table100%3/3
not(A) and B
A= not $exprB= $c =~ s/(?<=.)\|\z//
| |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | die "$errp, syntax should be CLAUSE|" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 64 | unless $c =~ $clause_name_re; | ||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | $sc = "|"; | |||||||||||||||||||||||||||||||||||||||||||
| 66 | ▶ | } elsif (!$expr && $c =~ s/(?<=.)\&\z//) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $expr and $c =~ s/(?<=.)\&\z//
MC/DC100%2/2
not $expr and $c =~ s/(?<=.)\&\z//
not $expr
$c =~ s/(?<=.)\&\z//
Truth table100%3/3
not(A) and B
A= not $exprB= $c =~ s/(?<=.)\&\z//
| |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | die "$errp, syntax should be CLAUSE&" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 68 | unless $c =~ $clause_name_re; | ||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | $sc = "&"; | |||||||||||||||||||||||||||||||||||||||||||
| 70 | ▶ | } elsif (!$expr && $c =~ /\A([^.]+)(?:\.(.+))?\((\w+)\)\z/) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not $expr and $c =~ /\A([^.]+)(?:\.(.+))?\((\w+)\)\z/
MC/DC50%1/2
not $expr and $c =~ /\A([^.]+)(?:\.(.+))?\((\w+)\)\z/
not $expr
$c =~ /\A([^.]+)(?:\.(.+))?\((\w+)\)\z/
Truth table66%2/3
not(A) and B
A= not $exprB= $c =~ /\A([^.]+)(?:\.(.+))?\((\w+)\)\z/
| |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | my ($c2, $a, $lang) = ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | die "$errp, syntax should be CLAUSE(LANG) or C.ATTR(LANG)" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$c2 =~ /$Data::Sah::Normalize::clause_name_re/ and !defined($a) || $a =~ /$Data::Sah::Normalize::attr_re/
not defined $a or $a =~ /$Data::Sah::Normalize::attr_re/
MC/DC0%0/3
$c2 =~ /$Data::Sah::Normalize::clause_name_re/ and !defined($a) || $a =~ /$Data::Sah::Normalize::attr_re/
$c2 =~ /$Data::Sah::Normalize::clause_name_re/
not defined $a
$a =~ /$Data::Sah::Normalize::attr_re/
Truth table25%1/4
A and not(B) or C
A= $c2 =~ /$Data::Sah::Normalize::clause_name_re/B= not defined $aC= $a =~ /$Data::Sah::Normalize::attr_re/
| |||||||||||||||||||||||||||||||||||||||||||||
| 73 | unless $c2 =~ $clause_name_re && | ||||||||||||||||||||||||||||||||||||||||||||
| 74 | (!defined($a) || $a =~ $attr_re); | ||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | $sc = "(LANG)"; | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | $cn = $c2 . (defined($a) ? ".$a" : "") . ".alt.lang.$lang"; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 77 | ▶ | } elsif ($c !~ $clause_re && | |||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$c =~ /$Data::Sah::Normalize::clause_re/ || $c =~ /$Data::Sah::Normalize::clause_attr_on_empty_clause_re/
MC/DC0%0/2
$c =~ /$Data::Sah::Normalize::clause_re/ || $c =~ /$Data::Sah::Normalize::clause_attr_on_empty_clause_re/
$c =~ /$Data::Sah::Normalize::clause_re/
$c =~ /$Data::Sah::Normalize::clause_attr_on_empty_clause_re/
Truth table33%1/3
A || B
A= $c =~ /$Data::Sah::Normalize::clause_re/B= $c =~ /$Data::Sah::Normalize::clause_attr_on_empty_clause_re/
| |||||||||||||||||||||||||||||||||||||||||||||
| 78 | $c !~ $clause_attr_on_empty_clause_re) { | ||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | die "$errp, please use letter/digit/underscore only"; | |||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | # XXX can't disregard merge prefix when checking conflict | ||||||||||||||||||||||||||||||||||||||||||||
| 84 | 5 | ▶ | if ($sc eq '!') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 85 | die "Conflict between clause shortcuts '!$c' and '$c'" | ||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | if exists $clset0->{$c}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 87 | die "Conflict between clause shortcuts '!$c' and '$c|'" | ||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | if exists $clset0->{"$c|"}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 89 | die "Conflict between clause shortcuts '!$c' and '$c&'" | ||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | if exists $clset0->{"$c&"}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | $clset->{$c} = $v; | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | $clset->{"$c.op"} = "not"; | |||||||||||||||||||||||||||||||||||||||||||
| 93 | } elsif ($sc eq '&') { | ||||||||||||||||||||||||||||||||||||||||||||
| 94 | die "Conflict between clause shortcuts '$c&' and '$c'" | ||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | if exists $clset0->{$c}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 96 | die "Conflict between clause shortcuts '$c&' and '$c|'" | ||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | if exists $clset0->{"$c|"}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | die "Clause 'c&' value must be an array" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 99 | unless ref($v) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $clset->{$c} = $v; | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | $clset->{"$c.op"} = "and"; | |||||||||||||||||||||||||||||||||||||||||||
| 102 | } elsif ($sc eq '|') { | ||||||||||||||||||||||||||||||||||||||||||||
| 103 | die "Conflict between clause shortcuts '$c|' and '$c'" | ||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | if exists $clset0->{$c}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | die "Clause 'c|' value must be an array" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 106 | unless ref($v) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | $clset->{$c} = $v; | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | $clset->{"$c.op"} = "or"; | |||||||||||||||||||||||||||||||||||||||||||
| 109 | } elsif ($sc eq '(LANG)') { | ||||||||||||||||||||||||||||||||||||||||||||
| 110 | die "Conflict between clause '$c' and '$cn'" | ||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | if exists $clset0->{$cn}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | $clset->{$cn} = $v; | |||||||||||||||||||||||||||||||||||||||||||
| 113 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | $clset->{$c} = $v; | |||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | ▶ | $clset->{req} = 1 if $opts->{has_req}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | # XXX option to recursively normalize clset, any's of, all's of, ... | ||||||||||||||||||||||||||||||||||||||||||||
| 121 | #if ($clset->{clset}) { | ||||||||||||||||||||||||||||||||||||||||||||
| 122 | # local $opts->{has_req}; | ||||||||||||||||||||||||||||||||||||||||||||
| 123 | # if ($clset->{'clset.op'} && $clset->{'clset.op'} =~ /and|or/) { | ||||||||||||||||||||||||||||||||||||||||||||
| 124 | # # multiple clause sets | ||||||||||||||||||||||||||||||||||||||||||||
| 125 | # $clset->{clset} = map { $self->normalize_clset($_, $opts) } | ||||||||||||||||||||||||||||||||||||||||||||
| 126 | # @{ $clset->{clset} }; | ||||||||||||||||||||||||||||||||||||||||||||
| 127 | # } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 128 | # $clset->{clset} = $self->normalize_clset($_, $opts); | ||||||||||||||||||||||||||||||||||||||||||||
| 129 | # } | ||||||||||||||||||||||||||||||||||||||||||||
| 130 | #} | ||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 3 | $clset; | |||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 4 | ▶ | sub normalize_schema($) { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_schema: called CC=17 SCAR=35.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 4 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | my $ref = ref($s); | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | ▶ | if (!defined($s)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | die "Schema is missing"; | |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | } elsif (!$ref) { | ||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | my $has_req = $s =~ s/\*\z//; | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | $s =~ $type_re or die "Invalid type syntax $s, please use ". | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 147 | "letter/digit/underscore only"; | ||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | ▶ | return [$s, $has_req ? {req=>1} : {}]; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } elsif ($ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | my $t = $s->[0]; | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | my $has_req = $t && $t =~ s/\*\z//; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$t && $t =~ s/\*\z//
MC/DC0%0/2
$t && $t =~ s/\*\z//
$t
$t =~ s/\*\z//
Truth table33%1/3
A && B
A= $tB= $t =~ s/\*\z//
| |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | ▶ | if (!defined($t)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | die "For array form, at least 1 element is needed for type"; | |||||||||||||||||||||||||||||||||||||||||||
| 156 | } elsif (ref $t) { | ||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | die "For array form, first element must be a string"; | |||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | ▶ | $t =~ $type_re or die "Invalid type syntax $s, please use ". | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 160 | "letter/digit/underscore only"; | ||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 2 | my $clset0; | |||||||||||||||||||||||||||||||||||||||||||
| 163 | my $extras; | ||||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | ▶ | if (defined($s->[1])) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | ▶ | if (ref($s->[1]) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | $clset0 = $s->[1]; | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | $extras = $s->[2]; | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | ▶ | die "For array form, there should not be more than 3 elements" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 169 | if @$s > 3; | ||||||||||||||||||||||||||||||||||||||||||||
| 170 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 171 | # flattened clause set [t, c=>1, c2=>2, ...] | ||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | die "For array in the form of [t, c1=>1, ...], there must be ". | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 173 | "3 elements (or 5, 7, ...)" | ||||||||||||||||||||||||||||||||||||||||||||
| 174 | unless @$s % 2; | ||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $clset0 = { @{$s}[1..@$s-1] }; | |||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 177 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $clset0 = {}; | |||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | # check clauses and parse shortcuts (!c, c&, c|, c=) | ||||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | my $clset = normalize_clset($clset0, {has_req=>$has_req}); | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | ▶ | if (defined $extras) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 2 | ▶ | die "For array form with 3 elements, extras must be hash" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 185 | unless ref($extras) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | ▶ | die "Extras must be empty hashref (Sah 0.9.47)" if keys %$extras; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 187 | # we remove extras to comply with Sah 0.9.47+ | ||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | return [$t, $clset]; | |||||||||||||||||||||||||||||||||||||||||||
| 189 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return [$t, $clset]; | |||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | die "Schema must be a string or arrayref (not $ref)"; | |||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||
| 198 | # ABSTRACT: Normalize Sah schema | ||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||