| 1 | package XML::Validator::Schema::SimpleType; | ||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||
| 6 | =item NAME | ||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||
| 8 | XML::Validator::Schema::SimpleType | ||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||
| 12 | XML Schema simple type system. This module provides objects and class | ||||||||||||||||||||||||||||||||||||||
| 13 | methods to support simple types. For complex types see the ModelNode | ||||||||||||||||||||||||||||||||||||||
| 14 | class. | ||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | =head1 USAGE | ||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | # create a new anonymous type based on an existing type | ||||||||||||||||||||||||||||||||||||||
| 19 | my $type = $string->derive(); | ||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | # create a new named type based on an existing type | ||||||||||||||||||||||||||||||||||||||
| 22 | my $type = $string->derive(name => 'myString'); | ||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | # add a restriction | ||||||||||||||||||||||||||||||||||||||
| 25 | $type->restrict(enumeration => "10"); | ||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||
| 27 | # check a value against a type | ||||||||||||||||||||||||||||||||||||||
| 28 | ($ok, $msg) = $type->check($value); | ||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | use XML::Validator::Schema::Util qw(XSD _err); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | # facet support bit-patterns | ||||||||||||||||||||||||||||||||||||||
| 36 | 6 | ▶ | use constant LENGTH => 0b0000000000000001; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 37 | 6 | ▶ | use constant MINLENGTH => 0b0000000000000010; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | use constant MAXLENGTH => 0b0000000000000100; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | use constant PATTERN => 0b0000000000001000; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 40 | 6 | ▶ | use constant ENUMERATION => 0b0000000000010000; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 41 | 6 | ▶ | use constant WHITESPACE => 0b0000000000100000; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | use constant MAXINCLUSIVE => 0b0000000001000000; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | use constant MAXEXCLUSIVE => 0b0000000010000000; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 44 | 6 | ▶ | use constant MININCLUSIVE => 0b0000000100000000; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | use constant MINEXCLUSIVE => 0b0000001000000000; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 46 | 6 | ▶ | use constant TOTALDIGITS => 0b0000010000000000; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | use constant FRACTIONDIGITS => 0b0000100000000000; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | # hash mapping names to values | ||||||||||||||||||||||||||||||||||||||
| 50 | 6 | our %FACET = (length => LENGTH, | |||||||||||||||||||||||||||||||||||||
| 51 | minLength => MINLENGTH, | ||||||||||||||||||||||||||||||||||||||
| 52 | maxLength => MAXLENGTH, | ||||||||||||||||||||||||||||||||||||||
| 53 | pattern => PATTERN, | ||||||||||||||||||||||||||||||||||||||
| 54 | enumeration => ENUMERATION, | ||||||||||||||||||||||||||||||||||||||
| 55 | whiteSpace => WHITESPACE, | ||||||||||||||||||||||||||||||||||||||
| 56 | maxInclusive => MAXINCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 57 | maxExclusive => MAXEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 58 | minInclusive => MININCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 59 | minExclusive => MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 60 | totalDigits => TOTALDIGITS, | ||||||||||||||||||||||||||||||||||||||
| 61 | fractionDigits => FRACTIONDIGITS); | ||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | # initialize builtin types | ||||||||||||||||||||||||||||||||||||||
| 64 | 6 | our %BUILTIN; | |||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | # create the primitive types | ||||||||||||||||||||||||||||||||||||||
| 67 | 6 | $BUILTIN{string} = __PACKAGE__->new(name => 'string', | |||||||||||||||||||||||||||||||||||||
| 68 | facets => LENGTH|MINLENGTH|MAXLENGTH| | ||||||||||||||||||||||||||||||||||||||
| 69 | PATTERN|ENUMERATION|WHITESPACE, | ||||||||||||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||
| 72 | 6 | $BUILTIN{boolean} = __PACKAGE__->new(name => 'boolean', | |||||||||||||||||||||||||||||||||||||
| 73 | facets => PATTERN|WHITESPACE, | ||||||||||||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||||||||||||
| 75 | 6 | $BUILTIN{boolean}->restrict(enumeration => "1", | |||||||||||||||||||||||||||||||||||||
| 76 | enumeration => "0", | ||||||||||||||||||||||||||||||||||||||
| 77 | enumeration => "true", | ||||||||||||||||||||||||||||||||||||||
| 78 | enumeration => "false"); | ||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | 6 | $BUILTIN{decimal} = __PACKAGE__->new(name => 'decimal', | |||||||||||||||||||||||||||||||||||||
| 81 | facets => TOTALDIGITS|FRACTIONDIGITS| | ||||||||||||||||||||||||||||||||||||||
| 82 | PATTERN|WHITESPACE| | ||||||||||||||||||||||||||||||||||||||
| 83 | #ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 84 | MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 85 | MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||||||||
| 87 | 6 | $BUILTIN{decimal}->restrict(pattern => qr/^[+-]?(?:(?:\d+(?:\.\d+)?)|(?:\.\d+))$/); | |||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | 6 | $BUILTIN{dateTime} = __PACKAGE__->new(name => 'dateTime', | |||||||||||||||||||||||||||||||||||||
| 90 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 91 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 92 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 93 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||||||||||||
| 95 | 6 | $BUILTIN{dateTime}->restrict(pattern => qr/^[-+]?(\d{4,})-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:(?:Z)|(?:[-+]\d{2}:\d{2}))?$/); | |||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | 6 | $BUILTIN{float} = __PACKAGE__->new(name => 'float', | |||||||||||||||||||||||||||||||||||||
| 98 | facets => PATTERN|WHITESPACE, | ||||||||||||||||||||||||||||||||||||||
| 99 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 100 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 101 | #MININCLUSIVE|MINEXCLUSIVE); | ||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | 6 | $BUILTIN{float}->restrict(pattern => | |||||||||||||||||||||||||||||||||||||
| 105 | qr/^[+-]?(?:(?:INF)|(?:NaN)|(?:\d+(?:\.\d+)?)(?:[eE][+-]?\d+)?)$/); | ||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | 6 | $BUILTIN{double} = __PACKAGE__->new(name => 'double', | |||||||||||||||||||||||||||||||||||||
| 108 | facets => PATTERN|WHITESPACE, | ||||||||||||||||||||||||||||||||||||||
| 109 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 110 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 111 | #MININCLUSIVE|MINEXCLUSIVE); | ||||||||||||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | 6 | $BUILTIN{double}->restrict(pattern => | |||||||||||||||||||||||||||||||||||||
| 115 | qr/^[+-]?(?:(?:INF)|(?:NaN)|(?:\d+(?:\.\d+)?)(?:[eE][+-]?\d+)?)$/); | ||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||
| 117 | 6 | $BUILTIN{duration} = __PACKAGE__->new(name => 'duration', | |||||||||||||||||||||||||||||||||||||
| 118 | facets => PATTERN|WHITESPACE,); | ||||||||||||||||||||||||||||||||||||||
| 119 | #facets => PATTERN|WHITESPACE|ENUMERATION|MAXINCLUSIVE|MAXEXCLUSIVE|MININCLUSIVE|MINEXCLUSIVE); | ||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||
| 121 | # thanks to perlmonk Abigail-II | ||||||||||||||||||||||||||||||||||||||
| 122 | 6 | $BUILTIN{duration}->restrict(pattern => qr /^-? # Optional leading minus. | |||||||||||||||||||||||||||||||||||||
| 123 | P # Required. | ||||||||||||||||||||||||||||||||||||||
| 124 | (?=[T\d]) # Duration cannot be empty. | ||||||||||||||||||||||||||||||||||||||
| 125 | (?:(?!-) \d+ Y)? # Non-negative integer, Y (optional) | ||||||||||||||||||||||||||||||||||||||
| 126 | (?:(?!-) \d+ M)? # Non-negative integer, M (optional) | ||||||||||||||||||||||||||||||||||||||
| 127 | (?:(?!-) \d+ D)? # Non-negative integer, D (optional) | ||||||||||||||||||||||||||||||||||||||
| 128 | ( | ||||||||||||||||||||||||||||||||||||||
| 129 | (?:T (?=\d) # T, must be followed by a digit. | ||||||||||||||||||||||||||||||||||||||
| 130 | (?:(?!-) \d+ H)? # Non-negative integer, H (optional) | ||||||||||||||||||||||||||||||||||||||
| 131 | (?:(?!-) \d+ M)? # Non-negative integer, M (optional) | ||||||||||||||||||||||||||||||||||||||
| 132 | (?:(?!-) \d+\.\d+ S)? # Non-negative decimal, S (optional) | ||||||||||||||||||||||||||||||||||||||
| 133 | )? # Entire T part is optional | ||||||||||||||||||||||||||||||||||||||
| 134 | )$/x); | ||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||
| 136 | 6 | $BUILTIN{time} = __PACKAGE__->new(name => 'time', | |||||||||||||||||||||||||||||||||||||
| 137 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 138 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 139 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 140 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||||||||
| 142 | 6 | $BUILTIN{time}->restrict(pattern => | |||||||||||||||||||||||||||||||||||||
| 143 | qr /^[0-2]\d:[0-5]\d:[0-5]\d(\.\d+)?(Z?|([+|-]([0-1]\d|2[0-4])\:([0-5]\d))?)$/); | ||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | 6 | $BUILTIN{date} = __PACKAGE__->new(name => 'date', | |||||||||||||||||||||||||||||||||||||
| 146 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 147 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 148 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 149 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||||||||||||
| 151 | $BUILTIN{date}->restrict(pattern => | ||||||||||||||||||||||||||||||||||||||
| 152 | 6 | qr /^[-]?(\d{4,})-(\d\d)-(\d\d)(??{ _validate_date($1,$2,$3) })(Z?|([+|-]([0-1]\d|2[0-4])\:([0-5]\d))?)$/); | |||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||
| 155 | 6 | $BUILTIN{gYearMonth} = __PACKAGE__->new(name => 'gYearMonth', | |||||||||||||||||||||||||||||||||||||
| 156 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 157 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 158 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 159 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||||||||||||
| 161 | 6 | $BUILTIN{gYearMonth}->restrict(pattern => | |||||||||||||||||||||||||||||||||||||
| 162 | qr /^[-]?(\d{4,})-(1[0-2]{1}|0\d{1})(Z?|([+|-]([0-1]\d|2[0-4])\:([0-5]\d))?)$/); | ||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||
| 164 | 6 | $BUILTIN{gYear} = __PACKAGE__->new(name => 'gYear', | |||||||||||||||||||||||||||||||||||||
| 165 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 166 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 167 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 168 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||||||||||||
| 170 | 6 | $BUILTIN{gYear}->restrict(pattern => | |||||||||||||||||||||||||||||||||||||
| 171 | qr /^[-]?(\d{4,})(Z?|([+|-]([0-1]\d|2[0-4])\:([0-5]\d))?)$/); | ||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||
| 173 | 6 | $BUILTIN{gMonthDay} = __PACKAGE__->new(name => 'gMonthDay', | |||||||||||||||||||||||||||||||||||||
| 174 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 175 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 176 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 177 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 178 | ); | ||||||||||||||||||||||||||||||||||||||
| 179 | $BUILTIN{gMonthDay}->restrict(pattern => | ||||||||||||||||||||||||||||||||||||||
| 180 | 6 | qr /^--(\d{2,})-(\d\d)(??{_validate_date(1999,$1,$2)})(Z?|([+|-]([0-1]\d|2[0-4])\:([0-5]\d))?)$/ ); | |||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||
| 182 | 6 | $BUILTIN{gDay} = __PACKAGE__->new(name => 'gDay', | |||||||||||||||||||||||||||||||||||||
| 183 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 184 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 185 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 186 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||||||||||||
| 188 | 6 | $BUILTIN{gDay}->restrict(pattern => | |||||||||||||||||||||||||||||||||||||
| 189 | qr /^---([0-2]\d{1}|3[0|1])(Z?|([+|-]([0-1]\d|2[0-4])\:([0-5]\d))?)$/ ); | ||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||
| 191 | 6 | $BUILTIN{gMonth} = __PACKAGE__->new(name => 'gMonth', | |||||||||||||||||||||||||||||||||||||
| 192 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 193 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 194 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 195 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 196 | ); | ||||||||||||||||||||||||||||||||||||||
| 197 | 6 | $BUILTIN{gMonth}->restrict(pattern => | |||||||||||||||||||||||||||||||||||||
| 198 | qr /^--(0\d|1[0-2])(Z?|([+|-]([0-1]\d|2[0-4])\:([0-5]\d))?)$/ ); | ||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||
| 200 | 6 | $BUILTIN{hexBinary} = __PACKAGE__->new(name => 'hexBinary', | |||||||||||||||||||||||||||||||||||||
| 201 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 202 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 203 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 204 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 205 | ); | ||||||||||||||||||||||||||||||||||||||
| 206 | 6 | $BUILTIN{hexBinary}->restrict(pattern => | |||||||||||||||||||||||||||||||||||||
| 207 | qr /^([0-9a-fA-F][0-9a-fA-F])+$/); | ||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||
| 210 | 6 | $BUILTIN{base64Binary} = __PACKAGE__->new(name => 'base64Binary', | |||||||||||||||||||||||||||||||||||||
| 211 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 212 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 213 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 214 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||||||||
| 216 | 6 | $BUILTIN{base64Binary}->restrict(pattern => | |||||||||||||||||||||||||||||||||||||
| 217 | qr /^([0-9a-zA-Z\+\\\=][0-9a-zA-Z\+\\\=])+$/); | ||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||
| 219 | 6 | $BUILTIN{anyURI} = __PACKAGE__->new(name => 'anyURI', | |||||||||||||||||||||||||||||||||||||
| 220 | facets => LENGTH|MINLENGTH|MAXLENGTH| | ||||||||||||||||||||||||||||||||||||||
| 221 | PATTERN|ENUMERATION|WHITESPACE, | ||||||||||||||||||||||||||||||||||||||
| 222 | ); | ||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||
| 224 | 6 | $BUILTIN{QName} = __PACKAGE__->new(name => 'QName', | |||||||||||||||||||||||||||||||||||||
| 225 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 226 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 227 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 228 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 229 | ); | ||||||||||||||||||||||||||||||||||||||
| 230 | 6 | $BUILTIN{QName}->restrict(pattern => | |||||||||||||||||||||||||||||||||||||
| 231 | qr /^([A-z][A-z0-9]+:)?([A-z][A-z0-9]+)$/); | ||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||
| 233 | 6 | $BUILTIN{NOTATION} = __PACKAGE__->new(name => 'NOTATION', | |||||||||||||||||||||||||||||||||||||
| 234 | facets => PATTERN|WHITESPACE | ||||||||||||||||||||||||||||||||||||||
| 235 | #|ENUMERATION| | ||||||||||||||||||||||||||||||||||||||
| 236 | #MAXINCLUSIVE|MAXEXCLUSIVE| | ||||||||||||||||||||||||||||||||||||||
| 237 | #MININCLUSIVE|MINEXCLUSIVE, | ||||||||||||||||||||||||||||||||||||||
| 238 | ); | ||||||||||||||||||||||||||||||||||||||
| 239 | 6 | $BUILTIN{NOTATION}->restrict(pattern => | |||||||||||||||||||||||||||||||||||||
| 240 | qr /^([A-z][A-z0-9]+:)?([A-z][A-z0-9]+)$/); | ||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||
| 242 | # create derived types | ||||||||||||||||||||||||||||||||||||||
| 243 | 6 | $BUILTIN{integer} = $BUILTIN{decimal}->derive(name => 'integer'); | |||||||||||||||||||||||||||||||||||||
| 244 | 6 | $BUILTIN{integer}->restrict(pattern => qr/^[+-]?\d+$/); | |||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||
| 246 | # http://www.w3.org/TR/2000/CR-xmlschema-2-20001024/#nonPositiveInteger | ||||||||||||||||||||||||||||||||||||||
| 247 | 6 | $BUILTIN{nonPositiveInteger} = $BUILTIN{integer}->derive(name => 'nonPositiveInteger'); | |||||||||||||||||||||||||||||||||||||
| 248 | 6 | $BUILTIN{nonPositiveInteger}->restrict( maxInclusive => 0 ); | |||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | # http://www.w3.org/TR/2000/CR-xmlschema-2-20001024/#nonNegativeInteger | ||||||||||||||||||||||||||||||||||||||
| 251 | 6 | $BUILTIN{nonNegativeInteger} = $BUILTIN{integer}->derive(name => 'nonNegativeInteger'); | |||||||||||||||||||||||||||||||||||||
| 252 | 6 | $BUILTIN{nonNegativeInteger}->restrict( minInclusive => 0 ); | |||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||
| 254 | # http://www.w3.org/TR/2000/CR-xmlschema-2-20001024/#positiveInteger | ||||||||||||||||||||||||||||||||||||||
| 255 | 6 | $BUILTIN{positiveInteger} = $BUILTIN{nonNegativeInteger}->derive(name => 'positiveInteger'); | |||||||||||||||||||||||||||||||||||||
| 256 | 6 | $BUILTIN{positiveInteger}->restrict( minInclusive => 1 ); | |||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||
| 258 | # http://www.w3.org/TR/2000/CR-xmlschema-2-20001024/#negativeInteger | ||||||||||||||||||||||||||||||||||||||
| 259 | 6 | $BUILTIN{negativeInteger} = $BUILTIN{nonPositiveInteger}->derive(name => 'negativeInteger'); | |||||||||||||||||||||||||||||||||||||
| 260 | 6 | $BUILTIN{negativeInteger}->restrict( maxInclusive => -1 ); | |||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||
| 262 | 6 | $BUILTIN{int} = $BUILTIN{integer}->derive(name => 'int'); | |||||||||||||||||||||||||||||||||||||
| 263 | 6 | $BUILTIN{int}->restrict(minInclusive => -2147483648, | |||||||||||||||||||||||||||||||||||||
| 264 | maxInclusive => 2147483647); | ||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||
| 266 | 6 | $BUILTIN{unsignedInt} = $BUILTIN{integer}->derive(name => 'unsignedInt'); | |||||||||||||||||||||||||||||||||||||
| 267 | 6 | $BUILTIN{unsignedInt}->restrict(minInclusive => 0, | |||||||||||||||||||||||||||||||||||||
| 268 | maxInclusive => 4294967295); | ||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||
| 270 | 6 | $BUILTIN{short} = $BUILTIN{int}->derive(name => 'short'); | |||||||||||||||||||||||||||||||||||||
| 271 | 6 | $BUILTIN{short}->restrict(minInclusive => -32768, | |||||||||||||||||||||||||||||||||||||
| 272 | maxInclusive => 32767); | ||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||
| 274 | 6 | $BUILTIN{unsignedShort} = $BUILTIN{unsignedInt}->derive(name => | |||||||||||||||||||||||||||||||||||||
| 275 | 'unsignedShort'); | ||||||||||||||||||||||||||||||||||||||
| 276 | 6 | $BUILTIN{unsignedShort}->restrict(maxInclusive => 65535); | |||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||
| 278 | 6 | $BUILTIN{byte} = $BUILTIN{short}->derive(name => 'byte'); | |||||||||||||||||||||||||||||||||||||
| 279 | 6 | $BUILTIN{byte}->restrict(minInclusive => -128, | |||||||||||||||||||||||||||||||||||||
| 280 | maxInclusive => 127); | ||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||
| 282 | 6 | $BUILTIN{unsignedByte} = $BUILTIN{unsignedShort}->derive(name => | |||||||||||||||||||||||||||||||||||||
| 283 | 'unsignedByte'); | ||||||||||||||||||||||||||||||||||||||
| 284 | 6 | $BUILTIN{unsignedByte}->restrict(maxInclusive => 255); | |||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||
| 286 | 6 | $BUILTIN{normalizedString} = $BUILTIN{string}->derive(name => | |||||||||||||||||||||||||||||||||||||
| 287 | 'normalizedString'); | ||||||||||||||||||||||||||||||||||||||
| 288 | 6 | $BUILTIN{normalizedString}->restrict(whiteSpace => 'replace'); | |||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||
| 290 | 6 | $BUILTIN{token} = $BUILTIN{normalizedString}->derive(name => 'token'); | |||||||||||||||||||||||||||||||||||||
| 291 | 6 | $BUILTIN{token}->restrict(whiteSpace => 'collapse'); | |||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||
| 293 | 6 | $BUILTIN{NMTOKEN} = $BUILTIN{token}->derive(name => 'NMTOKEN'); | |||||||||||||||||||||||||||||||||||||
| 294 | 6 | $BUILTIN{NMTOKEN}->restrict(pattern => qr/^[-.:\w\d]*$/); | |||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||
| 296 | ###################### | ||||||||||||||||||||||||||||||||||||||
| 297 | # SimpleType methods # | ||||||||||||||||||||||||||||||||||||||
| 298 | ###################### | ||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||
| 300 | # create a new type, filing in the library if named | ||||||||||||||||||||||||||||||||||||||
| 301 | 231 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 302 | 231 | my ($pkg, %arg) = @_; | |||||||||||||||||||||||||||||||||||||
| 303 | 231 | my $self = bless(\%arg, $pkg); | |||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||
| 305 | 231 | return $self; | |||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||
| 308 | # create a type derived from this type | ||||||||||||||||||||||||||||||||||||||
| 309 | 117 | ▶ | sub derive { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
derive: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 310 | 117 | my ($self, @opt) = @_; | |||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||
| 312 | 117 | my $sub = ref($self)->new(@opt); | |||||||||||||||||||||||||||||||||||||
| 313 | 117 | $sub->{base} = $self; | |||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||
| 315 | 117 | return $sub; | |||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||
| 318 | 234 | ▶ | sub restrict { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
restrict: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 319 | 234 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 320 | 234 | my $root = $self->root; | |||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||
| 322 | 234 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 323 | 276 | my ($key, $value) = (shift, shift); | |||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||
| 326 | # is this a legal restriction? (base types can do whatever they want | ||||||||||||||||||||||||||||||||||||||
| 327 | _err("Found illegal restriction '$key' on type derived from '$root->{name}'.") | ||||||||||||||||||||||||||||||||||||||
| 328 | unless ($self == $root) or | ||||||||||||||||||||||||||||||||||||||
| 329 | 276 | ▶ | ($FACET{$key} & $root->{facets}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self == $root or $XML::Validator::Schema::SimpleType::FACET{$key} & $root->{"facets"}
MC/DC100%2/2
$self == $root or $XML::Validator::Schema::SimpleType::FACET{$key} & $root->{"facets"}
$self == $root
$XML::Validator::Schema::SimpleType::FACET{$key} & $root->{"facets"}
Truth table100%3/3
A or B
A= $self == $rootB= $XML::Validator::Schema::SimpleType::FACET{$key} & $root->{"facets"}
| |||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||
| 331 | 275 | ▶ | push @{$self->{restrict}{$key} ||= []}, $value; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"restrict"}{$key} ||= []
MC/DC100%1/1
$self->{"restrict"}{$key} ||= []
$self->{"restrict"}{$key}
Truth table100%2/2
A
A= $self->{"restrict"}{$key}
| |||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||
| 335 | # returns the ultimate base type for this type | ||||||||||||||||||||||||||||||||||||||
| 336 | 1077 | ▶ | sub root { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
root: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 337 | 1077 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 338 | 1077 | my $p = $self; | |||||||||||||||||||||||||||||||||||||
| 339 | 1077 | ▶ | while ($p->{base}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 340 | 911 | $p = $p->{base}; | |||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||
| 342 | 1077 | return $p; | |||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||
| 345 | 1420 | ▶ | sub normalize_ws { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_ws: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 346 | 1420 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||
| 348 | 1420 | ▶ | if ($self->{restrict}{whiteSpace}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 349 | 47 | my $ws = $self->{restrict}{whiteSpace}[0]; | |||||||||||||||||||||||||||||||||||||
| 350 | 47 | ▶ | if ($ws eq 'replace') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 351 | 25 | $value =~ s![\t\n\r]! !g; | |||||||||||||||||||||||||||||||||||||
| 352 | } elsif ($ws eq 'collapse') { | ||||||||||||||||||||||||||||||||||||||
| 353 | 22 | $value =~ s!\s+! !g; | |||||||||||||||||||||||||||||||||||||
| 354 | 22 | $value =~ s!^\s!!g; | |||||||||||||||||||||||||||||||||||||
| 355 | 22 | $value =~ s!\s$!!g; | |||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||
| 357 | 47 | return $value; | |||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||
| 359 | 1373 | ▶ | return $self->{base}->normalize_ws($value) if $self->{base}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 360 | 796 | return $value; | |||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||
| 363 | 843 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=38 SCAR=36.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 364 | 843 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||
| 365 | 843 | my $root = $self->root; | |||||||||||||||||||||||||||||||||||||
| 366 | 843 | my ($ok, $msg); | |||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||
| 368 | # first deal with whitespace, necessary before applying facets | ||||||||||||||||||||||||||||||||||||||
| 369 | 843 | $value = $self->normalize_ws($value); | |||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||
| 371 | # first check base restrictions | ||||||||||||||||||||||||||||||||||||||
| 372 | 843 | ▶ | if ($self->{base}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 373 | 405 | ($ok, $msg) = $self->{base}->check($value); | |||||||||||||||||||||||||||||||||||||
| 374 | 405 | ▶ | return ($ok, $msg) unless $ok; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||
| 377 | # check various constraints | ||||||||||||||||||||||||||||||||||||||
| 378 | 818 | my $r = $self->{restrict}; | |||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||
| 380 | 818 | ▶ | if ($r->{length}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 381 | 12 | foreach my $len (@{$r->{length}}) { | |||||||||||||||||||||||||||||||||||||
| 382 | 12 | ▶ | return (0, "is not exactly $len characters.") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 383 | unless length($value) eq $len; | ||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||
| 387 | 813 | ▶ | if ($r->{maxLength}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 388 | 9 | foreach my $len (@{$r->{maxLength}}) { | |||||||||||||||||||||||||||||||||||||
| 389 | 9 | ▶ | return (0, "is longer than maximum $len characters.") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 390 | if length($value) > $len; | ||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||
| 394 | 812 | ▶ | if ($r->{minLength}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 395 | 25 | foreach my $len (@{$r->{minLength}}) { | |||||||||||||||||||||||||||||||||||||
| 396 | 25 | ▶ | return (0, "is shorter than minimum $len characters.") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 397 | if length($value) < $len; | ||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||
| 401 | 811 | ▶ | if ($r->{enumeration}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 402 | return (0, 'not in allowed list (' . | ||||||||||||||||||||||||||||||||||||||
| 403 | 10 | join(', ', @{$r->{enumeration}}) . ')') | |||||||||||||||||||||||||||||||||||||
| 404 | 29 | ▶ | unless grep { $_ eq $value } (@{$r->{enumeration}}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||
| 407 | 801 | ▶ | if ($r->{pattern}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 408 | 371 | my $pass = 0; | |||||||||||||||||||||||||||||||||||||
| 409 | 371 | foreach my $pattern (@{$r->{pattern}}) { | |||||||||||||||||||||||||||||||||||||
| 410 | 373 | ▶ | if ($value =~ /$pattern/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 411 | 321 | $pass = 1; | |||||||||||||||||||||||||||||||||||||
| 412 | 321 | last; | |||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||
| 415 | 371 | ▶ | return (0, "does not match required pattern.") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 416 | unless $pass; | ||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||
| 419 | 751 | ▶ | if ($r->{minInclusive}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 420 | 112 | foreach my $min (@{$r->{minInclusive}}) { | |||||||||||||||||||||||||||||||||||||
| 421 | 112 | ▶ | return (0, "is below minimum (inclusive) allowed, $min") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 422 | if $value < $min; | ||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||
| 426 | 728 | ▶ | if ($r->{minExclusive}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 427 | 2 | foreach my $min (@{$r->{minExclusive}}) { | |||||||||||||||||||||||||||||||||||||
| 428 | 2 | ▶ | return (0, "is below minimum allowed, $min") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 429 | if $value <= $min; | ||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||
| 433 | 727 | ▶ | if ($r->{maxInclusive}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 434 | 68 | foreach my $max (@{$r->{maxInclusive}}) { | |||||||||||||||||||||||||||||||||||||
| 435 | 68 | ▶ | return (0, "is above maximum (inclusive) allowed, $max") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 436 | if $value > $max; | ||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||
| 440 | 715 | ▶ | if ($r->{maxExclusive}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 441 | 3 | foreach my $max (@{$r->{maxExclusive}}) { | |||||||||||||||||||||||||||||||||||||
| 442 | 3 | ▶ | return (0, "is above maximum allowed, $max") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 443 | if $value >= $max; | ||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||
| 447 | 714 | ▶ | if ($r->{totalDigits} or $r->{fractionDigits}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$r->{"totalDigits"} or $r->{"fractionDigits"}
MC/DC50%1/2
$r->{"totalDigits"} or $r->{"fractionDigits"}
$r->{"totalDigits"}
$r->{"fractionDigits"}
Truth table66%2/3
A or B
A= $r->{"totalDigits"}B= $r->{"fractionDigits"}
| |||||||||||||||||||||||||||||||||||||||
| 448 | # strip leading and trailing zeros for numeric constraints | ||||||||||||||||||||||||||||||||||||||
| 449 | 17 | (my $digits = $value) =~ s/^([+-]?)0*(\d*\.?\d*?)0*$/$1$2/g; | |||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||
| 451 | 17 | ▶ | if ($r->{totalDigits}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 452 | 17 | foreach my $tdigits (@{$r->{totalDigits}}) { | |||||||||||||||||||||||||||||||||||||
| 453 | 17 | ▶ | return (0, "has more total digits than allowed, $tdigits") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 454 | if $digits =~ tr!0-9!! > $tdigits; | ||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||
| 458 | 15 | ▶ | if ($r->{fractionDigits}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 459 | 15 | foreach my $fdigits (@{$r->{fractionDigits}}) { | |||||||||||||||||||||||||||||||||||||
| 460 | 15 | ▶ | return (0, "has more fraction digits than allowed, $fdigits") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 461 | if $digits =~ /\.\d{$fdigits}\d/; | ||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||
| 466 | 711 | return (1); | |||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||
| 469 | # | ||||||||||||||||||||||||||||||||||||||
| 470 | # begin code taken from Date::Simple | ||||||||||||||||||||||||||||||||||||||
| 471 | # | ||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||
| 473 | 6 | my @days_in_month = ([0,31,28,31,30,31,30,31,31,30,31,30,31], | |||||||||||||||||||||||||||||||||||||
| 474 | [0,31,29,31,30,31,30,31,31,30,31,30,31]); | ||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||
| 476 | 10 | ▶ | sub _validate_date { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_date: called CC=6 SCAR=19.3
| |||||||||||||||||||||||||||||||||||||||
| 477 | 10 | my ($y, $m, $d)= @_; | |||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||
| 479 | # any +ve integral year is valid | ||||||||||||||||||||||||||||||||||||||
| 480 | 10 | ▶ | return q{(?!)} if $y != abs int $y; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 481 | 10 | ▶ | return q{(?!)} unless 1 <= $m and $m <= 12; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
1 <= $m and $m <= 12
MC/DC0%0/2
1 <= $m and $m <= 12
1 <= $m
$m <= 12
Truth table33%1/3
A and B
A= 1 <= $mB= $m <= 12
| |||||||||||||||||||||||||||||||||||||||
| 482 | 10 | ▶ | return q{(?!)} unless 1 <= $d and $d <=$days_in_month[_leap_year($y)][$m]; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
1 <= $d and $d <= $days_in_month[_leap_year($y)][$m]
MC/DC50%1/2
1 <= $d and $d <= $days_in_month[_leap_year($y)][$m]
1 <= $d
$d <= $days_in_month[_leap_year($y)][$m]
Truth table66%2/3
A and B
A= 1 <= $dB= $d <= $days_in_month[_leap_year($y)][$m]
| |||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||
| 484 | # perl 5.10.0 choked on (?=) here, switching to just returning | ||||||||||||||||||||||||||||||||||||||
| 485 | # nothing, which should also always match. | ||||||||||||||||||||||||||||||||||||||
| 486 | 9 | return ''; | |||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||
| 489 | 10 | ▶ | sub _leap_year { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_leap_year: called CC=4 SCAR=14.9
| |||||||||||||||||||||||||||||||||||||||
| 490 | 10 | my $y = shift; | |||||||||||||||||||||||||||||||||||||
| 491 | 10 | ▶ | return (($y%4==0) and ($y%400==0 or $y%100!=0)) || 0; | ||||||||||||||||||||||||||||||||||||
|
Condition62%5/8
$y % 4 == 0 && ($y % 400 == 0 || $y % 100 != 0) || 0
$y % 4 == 0 and $y % 400 == 0 || $y % 100 != 0
$y % 400 == 0 or $y % 100 != 0
MC/DC33%1/3
$y % 4 == 0 && ($y % 400 == 0 || $y % 100 != 0) || 0
$y % 4 == 0
$y % 400 == 0
$y % 100 != 0
Truth table50%2/4
A and B or C
A= $y % 4 == 0B= $y % 400 == 0C= $y % 100 != 0
| |||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||
| 494 | # | ||||||||||||||||||||||||||||||||||||||
| 495 | # end code taken from Date::Simple | ||||||||||||||||||||||||||||||||||||||
| 496 | # | ||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||
| 498 | 6 | 1; | |||||||||||||||||||||||||||||||||||||