| 1 | package XML::Validator::Schema::RootNode; | ||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 5 | ▶ | use base 'XML::Validator::Schema::ElementNode'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 5 | ▶ | use XML::Validator::Schema::Util qw(_err); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 5 | ▶ | use Carp qw(croak); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | =head1 NAME | ||||||||||||||
| 11 | |||||||||||||||
| 12 | XML::Validator::Schema::RootNode - the root node in a schema document | ||||||||||||||
| 13 | |||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||
| 15 | |||||||||||||||
| 16 | This is an internal module used by XML::Validator::Schema to represent | ||||||||||||||
| 17 | the root node in an XML Schema document. Holds references to the | ||||||||||||||
| 18 | libraries for the schema document and is responsible for hooking up | ||||||||||||||
| 19 | named types to their uses in the node tree at the end of parsing. | ||||||||||||||
| 20 | |||||||||||||||
| 21 | =cut | ||||||||||||||
| 22 | |||||||||||||||
| 23 | 51 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 24 | 51 | my $pkg = shift; | |||||||||||||
| 25 | 51 | my $self = $pkg->SUPER::new(@_); | |||||||||||||
| 26 | |||||||||||||||
| 27 | # start up with empty libraries | ||||||||||||||
| 28 | 51 | $self->{type_library} = XML::Validator::Schema::TypeLibrary->new; | |||||||||||||
| 29 | 51 | $self->{element_library} = XML::Validator::Schema::ElementLibrary->new; | |||||||||||||
| 30 | 51 | $self->{attribute_library} = XML::Validator::Schema::AttributeLibrary->new; | |||||||||||||
| 31 | |||||||||||||||
| 32 | 51 | return $self; | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | |||||||||||||||
| 35 | # finish typing and references | ||||||||||||||
| 36 | 39 | ▶ | sub compile { | ||||||||||||
|
Subroutine
compile: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||
| 37 | 39 | my $self = shift; | |||||||||||||
| 38 | 39 | my $element_library = $self->{element_library}; | |||||||||||||
| 39 | |||||||||||||||
| 40 | # put global elements into the library (could move this to ::ElementNode) | ||||||||||||||
| 41 | 39 | foreach my $d ($self->daughters) { | |||||||||||||
| 42 | 80 | ▶ | if (ref($d) eq 'XML::Validator::Schema::ElementNode') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | $element_library->add(name => $d->{name}, | ||||||||||||||
| 44 | 80 | obj => $d); | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | |||||||||||||||
| 49 | # complete all element refs first, forming a complete tree | ||||||||||||||
| 50 | 39 | foreach my $element ($self->descendants) { | |||||||||||||
| 51 | 214 | $self->complete_ref($element); | |||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | # completa all element types, including their attributes | ||||||||||||||
| 55 | 39 | foreach my $element ($self->descendants) { | |||||||||||||
| 56 | 256 | $self->complete_type($element); | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | |||||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | 215 | ▶ | sub complete_ref { | ||||||||||||
|
Subroutine
complete_ref: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||
| 62 | 215 | my ($self, $ref) = @_; | |||||||||||||
| 63 | |||||||||||||||
| 64 | # handle any unresolved attribute types | ||||||||||||||
| 65 | 215 | ▶ | if ($ref->{attr}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 66 | $self->complete_attr_ref($_) | ||||||||||||||
| 67 | 16 | for (grep { $_->{unresolved_ref} } (@{$ref->{attr}})); | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | # all done unless unresolved | ||||||||||||||
| 71 | 215 | ▶ | return unless $ref->{unresolved_ref}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | |||||||||||||||
| 73 | 43 | my $name = $ref->{name}; | |||||||||||||
| 74 | 43 | my ($element) = $self->{element_library}->find(name => $ref->{name}); | |||||||||||||
| 75 | 43 | ▶ | _err("Found unresolved reference to element '$name'") | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | unless $element; | ||||||||||||||
| 77 | |||||||||||||||
| 78 | |||||||||||||||
| 79 | |||||||||||||||
| 80 | # replace the current element | ||||||||||||||
| 81 | 43 | $ref->replace_with($element->copy_at_and_under); | |||||||||||||
| 82 | |||||||||||||||
| 83 | 43 | return; | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | 278 | ▶ | sub complete_type { | ||||||||||||
|
Subroutine
complete_type: called CC=10 SCAR=23.2
Pod
undocumented
| |||||||||||||||
| 87 | 278 | my ($self, $element) = @_; | |||||||||||||
| 88 | 278 | my $library = $self->{type_library}; | |||||||||||||
| 89 | |||||||||||||||
| 90 | # handle any unresolved attribute types | ||||||||||||||
| 91 | 278 | ▶ | if ($element->{attr}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 92 | $self->complete_attr_type($_) | ||||||||||||||
| 93 | 28 | for (grep { $_->{unresolved_type} } (@{$element->{attr}})); | |||||||||||||
| 94 | } | ||||||||||||||
| 95 | |||||||||||||||
| 96 | # all done unless unresolved | ||||||||||||||
| 97 | 277 | ▶ | return unless $element->{unresolved_type}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 98 | |||||||||||||||
| 99 | # get type data | ||||||||||||||
| 100 | 160 | my $type_name = $element->{type_name}; | |||||||||||||
| 101 | 160 | my $type = $library->find(name => $type_name); | |||||||||||||
| 102 | |||||||||||||||
| 103 | # isn't there? | ||||||||||||||
| 104 | 160 | ▶ | _err("Element '<$element->{name}>' has unrecognized type '$type_name'.") | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 105 | unless $type; | ||||||||||||||
| 106 | |||||||||||||||
| 107 | |||||||||||||||
| 108 | 160 | ▶ | if ($type->isa('XML::Validator::Schema::ComplexTypeNode')) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 109 | # can't have daughters for this to work | ||||||||||||||
| 110 | 18 | ▶ | _err("Element '<$element->{name}>' is using a named complexType and has sub-elements of its own. That's not supported.") | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 111 | if $element->daughters; | ||||||||||||||
| 112 | |||||||||||||||
| 113 | # replace the current element with one based on the complex node | ||||||||||||||
| 114 | 18 | my $new_node = $type->copy_at_and_under; | |||||||||||||
| 115 | 18 | $new_node->name($element->{name}); | |||||||||||||
| 116 | 18 | ▶ | $new_node->{attr} = [ @{ $new_node->{attr} || [] }, | ||||||||||||
|
Condition100%2/2
$new_node->{'attr'} || []
MC/DC100%1/1
$new_node->{'attr'} || []
$new_node->{'attr'}
Truth table100%2/2
A
A= $new_node->{'attr'}
| |||||||||||||||
| 117 | 18 | ▶ | @{ $element->{attr} || [] } ]; | ||||||||||||
|
Condition100%2/2
$element->{'attr'} || []
MC/DC100%1/1
$element->{'attr'} || []
$element->{'attr'}
Truth table100%2/2
A
A= $element->{'attr'}
| |||||||||||||||
| 118 | 18 | $element->replace_with($new_node); | |||||||||||||
| 119 | |||||||||||||||
| 120 | |||||||||||||||
| 121 | } elsif ($type->isa('XML::Validator::Schema::SimpleType')) { | ||||||||||||||
| 122 | 142 | $element->{type} = $type; | |||||||||||||
| 123 | |||||||||||||||
| 124 | } else { | ||||||||||||||
| 125 | 0 | croak("Library returned '$type'!"); | |||||||||||||
| 126 | } | ||||||||||||||
| 127 | |||||||||||||||
| 128 | # fixed it | ||||||||||||||
| 129 | 160 | delete $element->{unresolved_type}; | |||||||||||||
| 130 | } | ||||||||||||||
| 131 | |||||||||||||||
| 132 | 21 | ▶ | sub complete_attr_type { | ||||||||||||
|
Subroutine
complete_attr_type: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 133 | 21 | my ($self, $attr) = @_; | |||||||||||||
| 134 | |||||||||||||||
| 135 | 21 | my $type = $self->{type_library}->find(name => $attr->{type_name}); | |||||||||||||
| 136 | 21 | ▶ | _err("Attribute '<$attr->{name}>' has unrecognized ". | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 137 | "type '$attr->{type_name}'.") | ||||||||||||||
| 138 | unless $type; | ||||||||||||||
| 139 | |||||||||||||||
| 140 | 20 | $attr->{type} = $type; | |||||||||||||
| 141 | 20 | delete $attr->{unresolved_type}; | |||||||||||||
| 142 | } | ||||||||||||||
| 143 | |||||||||||||||
| 144 | 1 | ▶ | sub complete_attr_ref { | ||||||||||||
|
Subroutine
complete_attr_ref: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||
| 145 | 1 | my ($self, $ref) = @_; | |||||||||||||
| 146 | |||||||||||||||
| 147 | 1 | my $attr = $self->{attribute_library}->find(name => $ref->{name}); | |||||||||||||
| 148 | 1 | ▶ | _err("Attribute reference '$ref->{name}' not found.") | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 149 | unless $attr; | ||||||||||||||
| 150 | |||||||||||||||
| 151 | # clone, keep use | ||||||||||||||
| 152 | 1 | my $use = $ref->{required}; | |||||||||||||
| 153 | 1 | %$ref = %$attr; | |||||||||||||
| 154 | 1 | $ref->{required} = $use; | |||||||||||||
| 155 | |||||||||||||||
| 156 | 1 | return; | |||||||||||||
| 157 | } | ||||||||||||||
| 158 | |||||||||||||||
| 159 | |||||||||||||||
| 160 | |||||||||||||||
| 161 | 5 | 1; | |||||||||||||