| 1 | package XML::Validator::Schema::SimpleTypeNode; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use base 'XML::Validator::Schema::Node'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use XML::Validator::Schema::Util qw(_attr _err); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | XML::Validator::Schema::SimpleTypeNode | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | Temporary node in the schema parse tree to represent a simpleType. | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # Hash mapping facet names to allowable values | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | our %FACET_VALUE = (length => "nonNegativeInteger", | |||||||||||||||||||||||||||||||||||||||||
| 21 | minLength => "nonNegativeInteger", | ||||||||||||||||||||||||||||||||||||||||||
| 22 | maxLength => "nonNegativeInteger", | ||||||||||||||||||||||||||||||||||||||||||
| 23 | totalDigits => "positiveInteger", | ||||||||||||||||||||||||||||||||||||||||||
| 24 | fractionDigits => "nonNegativeInteger"); | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 42 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 42 | my ($pkg, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 42 | my $self = $pkg->new(); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 42 | my $name = _attr($data, 'name'); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 42 | ▶ | $self->name($name) if $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 42 | $self->{restrictions} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 42 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 39 | ▶ | sub parse_restriction { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_restriction: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 39 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 39 | my $base = _attr($data, 'base'); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 39 | ▶ | _err("Found restriction without required 'base' attribute.") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | unless $base; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 39 | $self->{base} = $base; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 59 | ▶ | sub parse_facet { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_facet: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 59 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 59 | my $facet = $data->{LocalName}; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 59 | my $value = _attr($data, 'value'); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 59 | ▶ | _err("Found facet <$facet> without required 'value' attribute.") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 59 | ▶ | $self->check_facet_value($facet, $value, $FACET_VALUE{$facet}) if defined $FACET_VALUE{$facet}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 54 | ▶ | push @{$self->{restrictions}{$facet} ||= []}, $value; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"restrictions"}{$facet} ||= []
MC/DC100%1/1
$self->{"restrictions"}{$facet} ||= []
$self->{"restrictions"}{$facet}
Truth table100%2/2
A
A= $self->{"restrictions"}{$facet}
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 33 | ▶ | sub compile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 33 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 33 | ▶ | if ( $self->{mother}->{is_union} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | my $mum=$self->{mother}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | $self->{name} = $mum->{name} . | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | $mum->{next_instance}; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | $self->{mother}->{next_instance} ++; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | # If my only child is a union, everything is already compiled | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 33 | ▶ | if ( $self->{got_union} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | # all compilation done at lower level | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # it looks sort of inappropriate to return a string when | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # everything is expecting a SimpleType in here. But my view is that | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # a union isn't really a simpletype and it isn't appropriate to | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # handle a union directly in SimpleType. This alerts ElementNode | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # to the fact that it has to do a little extra work. | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | return 'union'; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # compile a new type | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 31 | my $base = $self->root->{type_library}->find(name => $self->{base}); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 31 | my $type = $base->derive(); | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | # smoke 'em if you got 'em | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 31 | ▶ | $type->{name} = $self->{name} if $self->{name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | # add restrictions | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 31 | foreach my $facet (keys %{$self->{restrictions}}) { | |||||||||||||||||||||||||||||||||||||||||
| 89 | 40 | foreach my $value (@{$self->{restrictions}{$facet}}) { | |||||||||||||||||||||||||||||||||||||||||
| 90 | 48 | ▶ | if ($facet eq 'pattern') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 5 | $type->restrict($facet, qr/^$value$/); | |||||||||||||||||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 43 | $type->restrict($facet, $value); | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | # register in the library if this is a named type | ||||||||||||||||||||||||||||||||||||||||||
| 99 | $self->root->{type_library}->add(name => $self->{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | obj => $type) | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 30 | ▶ | if $self->{name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 30 | ▶ | if ( $self->{mother}->{is_union} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | # update great-gran with this simple type member | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # However this node is a SimpleTypeNode, and to make simple | ||||||||||||||||||||||||||||||||||||||||||
| 106 | # re-use of 'check' possible in ElementNode, what we should | ||||||||||||||||||||||||||||||||||||||||||
| 107 | # be pushing is an ElementNode | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | my $gg = $self->{mother}->{mother}->{mother}; | |||||||||||||||||||||||||||||||||||||||||
| 110 | # Make a new elementnode to stuff into members | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | my $mbr = XML::Validator::Schema::ElementNode->new(); | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | $mbr->{type} = $type; | |||||||||||||||||||||||||||||||||||||||||
| 114 | # make this simpletype the daughter of the new member element: | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | $mbr->add_daughter($self); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | push(@{$gg->{members}},$mbr); | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 30 | return $type; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 31 | ▶ | sub check_facet_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_facet_value: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 31 | my ($self, $facet, $value, $type_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 31 | my ($ok, $msg) = $self->root->{type_library}->find(name => $type_name)->check($value); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 31 | ▶ | _err("Facet <$facet> value $value is not a $type_name") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | unless $ok; | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 36 | ▶ | sub check_constraints { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_constraints: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 36 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 36 | my $r = $self->{restrictions}; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | # Schema Component Constraint: fractionDigits-totalDigits | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 36 | ▶ | if (exists $r->{fractionDigits} && exists $r->{totalDigits}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $r->{"fractionDigits"} and exists $r->{"totalDigits"}
MC/DC50%1/2
exists $r->{"fractionDigits"} and exists $r->{"totalDigits"}
exists $r->{"fractionDigits"}
exists $r->{"totalDigits"}
Truth table66%2/3
A and B
A= exists $r->{"fractionDigits"}B= exists $r->{"totalDigits"}
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | _err("Facet <fractionDigits> value $r->{fractionDigits}[0] is greater than facet <totalDigits> value $r->{totalDigits}[0]") | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 3 | ▶ | if ($r->{fractionDigits}[0] > $r->{totalDigits}[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | # Schema Component Constraint: length-minLength-maxLength | ||||||||||||||||||||||||||||||||||||||||||
| 140 | _err("Facet <length> is defined in addition to facets <minLength> or <maxLength>") | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 35 | ▶ | if (exists $r->{length} && (exists $r->{minLength} || exists $r->{maxLength})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
exists $r->{"length"} and exists $r->{"minLength"} || exists $r->{"maxLength"}
exists $r->{"minLength"} or exists $r->{"maxLength"}
MC/DC66%2/3
exists $r->{"length"} and exists $r->{"minLength"} || exists $r->{"maxLength"}
exists $r->{"length"}
exists $r->{"minLength"}
exists $r->{"maxLength"}
Truth table75%3/4
A and B or C
A= exists $r->{"length"}B= exists $r->{"minLength"}C= exists $r->{"maxLength"}
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | # Schema Component Constraint: minLength-less-than-equal-to-maxLength | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 34 | ▶ | if (exists $r->{minLength} && exists $r->{maxLength}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $r->{"minLength"} and exists $r->{"maxLength"}
MC/DC100%2/2
exists $r->{"minLength"} and exists $r->{"maxLength"}
exists $r->{"minLength"}
exists $r->{"maxLength"}
Truth table100%3/3
A and B
A= exists $r->{"minLength"}B= exists $r->{"maxLength"}
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | _err("Facet <minLength> value $r->{minLength}[0] is greater than than facet <maxLength> value $r->{maxLength}[0]") | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | ▶ | if ($r->{minLength}[0] > $r->{maxLength}[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||