| 1 | # -*- mode: cperl -*- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Author: Slaven Rezic | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Copyright (C) 2006,2007,2008,2009,2010,2015,2020 Slaven Rezic. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # This package is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # Mail: srezic@cpan.org | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # WWW: http://www.rezic.de/eserte/ | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | package Kwalify; | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use vars qw(@EXPORT_OK $VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | @EXPORT_OK = qw(validate); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | $VERSION = '1.23'; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | sub validate ($$) { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 16 | ▶ | my($schema, $data) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 16 | my $self = Kwalify::Validator->new; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 16 | $self->validate($schema, $data, "/"); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 16 | ▶ | if (@{$self->{errors}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | die join("\n", map { " - $_" } @{$self->{errors}}) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 31 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | package Kwalify::Validator; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | use overload (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 16 | ▶ | my($class) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 16 | bless { errors => [] }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | sub validate { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 16 | ▶ | my($self, $schema, $data, $path, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 16 | $self->{done} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 16 | $self->_validate($schema, $data, $path, $args); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | sub _validate { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 177 | ▶ | my($self, $schema, $data, $path, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate: called CC=4 SCAR=14.4
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 177 | $self->{path} = $path; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 177 | ▶ | if (!UNIVERSAL::isa($schema, "HASH")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $self->_die("Schema structure must be a hash reference"); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 177 | my $type = $schema->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 177 | ▶ | if (!defined $type) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | $type = 'str'; # default type; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 177 | my $type_check_method = "validate_" . $type; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 177 | ▶ | if (!$self->can($type_check_method)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $self->_die("Invalid or unimplemented type '$type'"); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 177 | $self->$type_check_method($schema, $data, $path, $args); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | sub _additional_rules { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 116 | ▶ | my($self, $schema, $data, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_additional_rules: called CC=32 SCAR=44.7
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 6 | ▶ | no warnings 'uninitialized'; # legal undef values may happen everywhere | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 116 | for my $schema_key (keys %$schema) { | |||||||||||||||||||||||||||||||||||||||||
| 75 | 211 | ▶ | if (defined $schema->{$schema_key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 211 | ▶ | if ($schema_key eq 'pattern') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | (my $pattern = $schema->{pattern}) =~ s{^/(.*)/$}{$1}; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | ▶ | if ($data !~ qr{$pattern}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | $self->_error("Non-valid data '$data' does not match /$pattern/"); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } elsif ($schema_key eq 'length') { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | if (!UNIVERSAL::isa($schema->{'length'}, "HASH")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $self->_die("'length' must be a hash with keys max and/or min"); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | my $length = length($data); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | for my $sub_schema_key (keys %{ $schema->{'length'} }) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | ▶ | if ($sub_schema_key eq 'min') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | my $min = $schema->{'length'}->{min}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | if ($length < $min) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | $self->_error("'$data' is too short (length $length < min $min)"); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } elsif ($sub_schema_key eq 'min-ex') { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $min = $schema->{'length'}->{'min-ex'}; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ($length <= $min) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $self->_error("'$data' is too short (length $length <= min $min)"); | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } elsif ($sub_schema_key eq 'max') { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | my $max = $schema->{'length'}->{max}; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | if ($length > $max) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $self->_error("'$data' is too long (length $length > max $max)"); | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } elsif ($sub_schema_key eq 'max-ex') { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $max = $schema->{'length'}->{'max-ex'}; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($length >= $max) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $self->_error("'$data' is too long (length $length >= max $max)"); | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $self->_die("Unexpected key '$sub_schema_key' in length specification, expected min, max, min-ex and/or max-ex"); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } elsif ($schema_key eq 'enum') { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | ▶ | if (!UNIVERSAL::isa($schema->{enum}, 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $self->_die("'enum' must be an array"); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 4 | my %valid = map { ($_,1) } @{ $schema->{enum} }; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | ▶ | if (!exists $valid{$data}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | $self->_error("'$data': invalid " . _base_path($path) . " value"); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } elsif ($schema_key eq 'range') { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | ▶ | if (!UNIVERSAL::isa($schema->{range}, "HASH")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->_die("'range' must be a hash with keys max and/or min"); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | my($lt, $le, $gt, $ge); | |||||||||||||||||||||||||||||||||||||||||
| 124 | ## yes? no? | ||||||||||||||||||||||||||||||||||||||||||
| 125 | # if (eval { require Scalar::Util; defined &Scalar::Util::looks_like_number }) { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # if (Scalar::Util::looks_like_number($data)) { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # $lt = sub { $_[0] < $_[1] }; | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # $gt = sub { $_[0] > $_[1] }; | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # } else { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # $lt = sub { $_[0] lt $_[1] }; | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # $gt = sub { $_[0] gt $_[1] }; | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # } else { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # warn "Cannot determine whether $data is a number, assume so..."; # XXX show only once | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | ▶ | no warnings 'numeric'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 4 | ▶ | $lt = sub { $_[0] < $_[1] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | ▶ | $gt = sub { $_[0] > $_[1] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | ▶ | $le = sub { $_[0] <= $_[1] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | ▶ | $ge = sub { $_[0] >= $_[1] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | for my $sub_schema_key (keys %{ $schema->{range} }) { | |||||||||||||||||||||||||||||||||||||||||
| 143 | 8 | ▶ | if ($sub_schema_key eq 'min') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 4 | my $min = $schema->{range}->{min}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 4 | ▶ | if ($lt->($data, $min)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | $self->_error("'$data' is too small (< min $min)"); | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | } elsif ($sub_schema_key eq 'min-ex') { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $min = $schema->{range}->{'min-ex'}; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ($le->($data, $min)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $self->_error("'$data' is too small (<= min $min)"); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | } elsif ($sub_schema_key eq 'max') { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | my $max = $schema->{range}->{max}; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | ▶ | if ($gt->($data, $max)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $self->_error("'$data' is too large (> max $max)"); | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } elsif ($sub_schema_key eq 'max-ex') { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $max = $schema->{range}->{'max-ex'}; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ($ge->($data, $max)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $self->_error("'$data' is too large (>= max $max)"); | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $self->_die("Unexpected key '$sub_schema_key' in range specification, expected min, max, min-ex and/or max-ex"); | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | } elsif ($schema_key eq 'assert') { | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $self->_die("'assert' is not yet implemented"); | |||||||||||||||||||||||||||||||||||||||||
| 169 | } elsif ($schema_key !~ m{^(type|required|unique|name|classname|class|desc)$}) { | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $self->_die("Unexpected key '$schema_key' in type specification"); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | sub validate_text { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | ▶ | my($self, $schema, $data, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_text: called CC=4 SCAR=18.9
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | ▶ | if (!defined $data || ref $data) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $data or ref $data
MC/DC0%0/2
not defined $data or ref $data
not defined $data
ref $data
Truth table33%1/3
not(A) or B
A= not defined $dataB= ref $data
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | return $self->_error("Non-valid data '" . (defined $data ? $data : 'undef') . "', expected text"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | $self->_additional_rules($schema, $data, $path); | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | sub validate_str { | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 99 | ▶ | my($self, $schema, $data, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_str: called CC=5 SCAR=17.2
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 99 | ▶ | if (!defined $data || ref $data || $data =~ m{^\d+(\.\d+)?$}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not defined $data or ref $data or $data =~ /^\d+(\.\d+)?$/
not defined $data or ref $data
MC/DC33%1/3
not defined $data or ref $data or $data =~ /^\d+(\.\d+)?$/
not defined $data
ref $data
$data =~ /^\d+(\.\d+)?$/
Truth table50%2/4
not(A) or B or C
A= not defined $dataB= ref $dataC= $data =~ /^\d+(\.\d+)?$/
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | return $self->_error("Non-valid data '" . (defined $data ? $data : 'undef') . "', expected a str"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 98 | $self->_additional_rules($schema, $data, $path); | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | sub validate_int { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 10 | ▶ | my($self, $schema, $data, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_int: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 10 | ▶ | if ($data !~ m{^[+-]?\d+$}) { # XXX what about scientific notation? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | $self->_error("Non-valid data '" . $data . "', expected an int"); | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 10 | $self->_additional_rules($schema, $data, $path); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | sub validate_float { | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | my($self, $schema, $data, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_float: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ($data !~ m{^[+-]?\d+\.\d+$}) { # XXX other values? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $self->_error("Non-valid data '" . $data . "', expected a float"); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $self->_additional_rules($schema, $data, $path); | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | sub validate_number { | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | my($self, $schema, $data, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_number: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if ($data !~ m{^[+-]?\d+(\.\d+)?$}) { # XXX combine int+float regexp! | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $self->_error("Non-valid data '" . $data . "', expected a number"); | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $self->_additional_rules($schema, $data, $path); | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | sub validate_bool { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | my($self, $schema, $data, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_bool: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if ($data !~ m{^(yes|true|1|no|false|0)$}) { # XXX correct? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $self->_error("Non-valid data '" . $data . "', expected a boolean"); | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $self->_additional_rules($schema, $data, $path); | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | # XXX is this correct? | ||||||||||||||||||||||||||||||||||||||||||
| 225 | sub validate_scalar { | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | shift->validate_text(@_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_scalar: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | sub validate_date { | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 6 | ▶ | my($self, $schema, $data, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_date: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 6 | ▶ | if ($data !~ m{^\d{4}-\d{2}-\d{2}$}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | $self->_error("Non-valid data '" . $data . "', expected a date (YYYY-MM-DD)"); | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 6 | $self->_additional_rules($schema, $data, $path); | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | sub validate_time { | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | my($self, $schema, $data, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_time: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if ($data !~ m{^\d{2}:\d{2}:\d{2}$}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $self->_error("Non-valid data '" . $data . "', expected a time (HH:MM:SS)"); | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $self->_additional_rules($schema, $data, $path); | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | sub validate_timestamp { | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | my($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_timestamp: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $self->_error("timestamp validation NYI"); # XXX | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | sub validate_any { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | my($self, $schema, $data, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_any: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $self->_additional_rules($schema, $data, $path); | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | sub validate_seq { | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 26 | ▶ | my($self, $schema, $data, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_seq: called CC=9 SCAR=23.4
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 26 | ▶ | if (!exists $schema->{sequence}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $self->_die("'sequence' missing with 'seq' type"); | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 26 | my $sequence = $schema->{sequence}; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 26 | ▶ | if (!UNIVERSAL::isa($sequence, 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $self->_die("Expected array in 'sequence'"); | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 26 | ▶ | if (@$sequence != 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $self->_die("Expect exactly one element in sequence"); | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 26 | ▶ | if (!UNIVERSAL::isa($data, 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $self->_error("Non-valid data " . $data . ", expected sequence"); | |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 26 | ▶ | return if ($self->{done}{overload::StrVal($data)}{overload::StrVal($schema)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 26 | $self->{done}{overload::StrVal($data)}{overload::StrVal($schema)} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 26 | my $subschema = $sequence->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 26 | my $unique = _get_boolean($subschema->{unique}); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 26 | my %unique_val; | |||||||||||||||||||||||||||||||||||||||||
| 278 | my %unique_mapping_val; | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 26 | my $index = 0; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 26 | for my $elem (@$data) { | |||||||||||||||||||||||||||||||||||||||||
| 281 | 65 | my $subpath = _append_path($path, $index); | |||||||||||||||||||||||||||||||||||||||||
| 282 | 65 | $self->_validate($subschema, $elem, $subpath, { unique_mapping_val => \%unique_mapping_val}); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 65 | ▶ | if ($unique) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 26 | ▶ | if (exists $unique_val{$elem}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 2 | $self->_error("'$elem' is already used at '$unique_val{$elem}'"); | |||||||||||||||||||||||||||||||||||||||||
| 286 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 24 | $unique_val{$elem} = $subpath; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 65 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | sub validate_map { | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 34 | ▶ | my($self, $schema, $data, $path, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_map: called CC=19 SCAR=31.7
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 34 | my $unique_mapping_val; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 34 | ▶ | if ($args && $args->{unique_mapping_val}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args and $args->{"unique_mapping_val"}
MC/DC50%1/2
$args and $args->{"unique_mapping_val"}
$args
$args->{"unique_mapping_val"}
Truth table66%2/3
A and B
A= $argsB= $args->{"unique_mapping_val"}
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 30 | $unique_mapping_val = $args->{unique_mapping_val}; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 34 | ▶ | if (!exists $schema->{mapping}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $self->_die("'mapping' missing with 'map' type"); | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 34 | my $mapping = $schema->{mapping}; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 34 | ▶ | if (!UNIVERSAL::isa($mapping, 'HASH')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | $self->_die("Expected hash in 'mapping'"); | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 34 | ▶ | if (!defined $data) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $self->_error("Undefined data, expected mapping"); | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 34 | ▶ | if (!UNIVERSAL::isa($data, 'HASH')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $self->_error("Non-valid data " . $data . ", expected mapping"); | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 34 | ▶ | return if ($self->{done}{overload::StrVal($data)}{overload::StrVal($schema)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 34 | $self->{done}{overload::StrVal($data)}{overload::StrVal($schema)} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 34 | my %seen_key; | |||||||||||||||||||||||||||||||||||||||||
| 320 | my $default_key_schema; | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | ## Originally this was an each-loop, but this could lead into | ||||||||||||||||||||||||||||||||||||||||||
| 323 | ## endless recursions, because mapping may be reused in Kwalify, | ||||||||||||||||||||||||||||||||||||||||||
| 324 | ## thus the each iterator was shared between recursion levels. | ||||||||||||||||||||||||||||||||||||||||||
| 325 | # while(my($key,$subschema) = each %$mapping) { | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 34 | for my $key (keys %$mapping) { | |||||||||||||||||||||||||||||||||||||||||
| 327 | 114 | my $subschema = $mapping->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 114 | ▶ | if ($key eq '=') { # the "default" key | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $default_key_schema = $subschema; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 114 | my $subpath = _append_path($path, $key); | |||||||||||||||||||||||||||||||||||||||||
| 333 | 114 | $self->{path} = $subpath; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 114 | ▶ | if (!UNIVERSAL::isa($subschema, 'HASH')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $self->_die("Expected subschema (a hash)"); | |||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 114 | my $required = _get_boolean($subschema->{required}); | |||||||||||||||||||||||||||||||||||||||||
| 338 | 114 | ▶ | if (!defined $data->{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 18 | ▶ | if ($required) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 2 | $self->{path} = $path; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 2 | $self->_error("Expected required key '$key'"); | |||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||
| 343 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 16 | $seen_key{$key}++; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 16 | next; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 96 | my $unique = _get_boolean($subschema->{unique}); | |||||||||||||||||||||||||||||||||||||||||
| 349 | 96 | ▶ | if ($unique) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 16 | ▶ | if (defined $unique_mapping_val->{$data->{$key}}->{val} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $$unique_mapping_val{$data->{$key}}{"val"} and $$unique_mapping_val{$data->{$key}}{"val"} eq $data->{$key}
MC/DC50%1/2
defined $$unique_mapping_val{$data->{$key}}{"val"} and $$unique_mapping_val{$data->{$key}}{"val"} eq $data->{$key}
defined $$unique_mapping_val{$data->{$key}}{"val"}
$$unique_mapping_val{$data->{$key}}{"val"} eq $data->{$key}
Truth table66%2/3
A and B
A= defined $$unique_mapping_val{$data->{$key}}{"val"}B= $$unique_mapping_val{$data->{$key}}{"val"} eq $data->{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | && $unique_mapping_val->{$data->{$key}}->{val} eq $data->{$key}) { | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 3 | $self->_error("'$data->{$key}' is already used at '$unique_mapping_val->{$data->{$key}}->{path}'"); | |||||||||||||||||||||||||||||||||||||||||
| 353 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 13 | $unique_mapping_val->{$data->{$key}} = { val => $data->{$key}, | |||||||||||||||||||||||||||||||||||||||||
| 355 | path => $subpath, | ||||||||||||||||||||||||||||||||||||||||||
| 356 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 96 | $self->_validate($subschema, $data->{$key}, $subpath); | |||||||||||||||||||||||||||||||||||||||||
| 361 | 96 | $seen_key{$key}++; | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | # while(my($key,$val) = each %$data) { | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 34 | for my $key (keys %$data) { | |||||||||||||||||||||||||||||||||||||||||
| 366 | 101 | my $val = $data->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 101 | my $subpath = _append_path($path, $key); | |||||||||||||||||||||||||||||||||||||||||
| 368 | 101 | $self->{path} = $subpath; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 101 | ▶ | if (!$seen_key{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 5 | ▶ | if ($default_key_schema) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $self->_validate($default_key_schema, $val, $subpath); | |||||||||||||||||||||||||||||||||||||||||
| 372 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 5 | $self->_error("Unexpected key '$key'"); | |||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | sub _die { | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | my($self, $msg) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_die: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $msg = "[$self->{path}] $msg"; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | die $msg."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | sub _error { | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 24 | ▶ | my($self, $msg) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 24 | $msg = "[$self->{path}] $msg"; | |||||||||||||||||||||||||||||||||||||||||
| 388 | 24 | push @{$self->{errors}}, $msg; | |||||||||||||||||||||||||||||||||||||||||
| 389 | 24 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | # Functions: | ||||||||||||||||||||||||||||||||||||||||||
| 393 | sub _append_path { | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 280 | ▶ | my($root, $leaf) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_append_path: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 280 | ▶ | $root . ($root !~ m{/$} ? "/" : "") . $leaf; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | sub _base_path { | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | ▶ | my($path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_base_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | my($base) = $path =~ m{([^/]+)$}; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | $base; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | sub _get_boolean { | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 236 | ▶ | my($val) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_boolean: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 236 | ▶ | defined $val && $val =~ m{^(yes|true|1)$}; # XXX check for all boolean trues | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 410 | __END__ | ||||||||||||||||||||||||||||||||||||||||||