| 1 | 10 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | no warnings qw(uninitialized); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | package XML::Pastor::Schema::Parser; | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Cwd; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use URI::file; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use Class::Accessor; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | ▶ | use Data::HashArray; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | ▶ | use XML::Pastor::Stack; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | ▶ | use XML::Pastor::Schema; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | ▶ | use XML::Pastor::Util qw(getAttributeHash sprint_xml_element); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 10 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 10 | our @ISA = qw(Class::Accessor); | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 10 | XML::Pastor::Schema::Parser->mk_accessors(qw(model contextStack counter verbose)); | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 9 | ▶ | sub new () { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 9 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 9 | my $self = {@_}; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | unless ($self->{model}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | $self->{model} = XML::Pastor::Schema::Model->new(); | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | ▶ | unless ($self->{contextStack}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | $self->{contextStack} = XML::Pastor::Stack->new(); | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 9 | return bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Parser context gets changed (by a PUSH on the stack) each time a new | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # schema file is processed (via includes and such). The context keeps track of | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # the parser state for that file. | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # This method will return the top-most context for the parser. | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2277 | ▶ | sub context { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
context: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2277 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2277 | return $self->contextStack()->peek(); | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # Parse one or more schemas and create a schema model (internal Pastor | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # structure that represents the object model of the schemas. | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # ARGUMENTS : | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # schema : A single file name or an array of schema file names to be processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # If you give an array, the result is the same as parsing them one after the other | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # They all accumulate in the parser 'model'. | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 9 | ▶ | sub parse { &process;} | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # An alias for 'process'. See Process. | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub processSchema { &process;} | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
processSchema: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 9 | ▶ | sub process { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 9 | $self->_process(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # Called internally when an 'include' element is encountered in a schema. | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 13 | ▶ | sub includeSchema() { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
includeSchema: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 13 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 13 | $self->_process(@_, operation=>"include"); | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # Called internally when an 'import' element is encountered in a schema. | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | sub importSchema() { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
importSchema: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | $self->_process(@_, operation=>"import"); | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | # die "Pastor : Schema IMPORT functionality not yet supported!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Called internally when an 'redefine' element is encountered in a schema. | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub redefineSchema() { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
redefineSchema: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $self->_process(@_, operation=>"redefine"); | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Parse a given schema into a LibXML DOM tree. | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 24 | ▶ | sub parseToDom() { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parseToDom: called CC=9 SCAR=23.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 24 | my $args = {@_}; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 24 | ▶ | my $verbose = $self->verbose || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->verbose || 0
MC/DC0%0/1
$self->verbose || 0
$self->verbose
Truth table50%1/2
A
A= $self->verbose
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 24 | my $schema_url = $args->{schema_url}; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 24 | my $schema_str = $args->{schema_str}; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 24 | ▶ | unless ( defined($schema_url) || defined ($schema_str) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $schema_url or defined $schema_str
MC/DC0%0/2
defined $schema_url or defined $schema_str
defined $schema_url
defined $schema_str
Truth table33%1/3
A or B
A= defined $schema_urlB= defined $schema_str
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | die "Pastor: Parse Schema : Undefined schema !\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 24 | ▶ | if (defined($schema_url)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 24 | ▶ | print STDERR "Pastor : Fetching schema : '$schema_url' ...\n" if ($verbose >= 2); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 24 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 24 | $ua->agent("Pastor/0.1 "); | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # Create a request | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 24 | my $req = HTTP::Request->new(GET => $schema_url); | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Pass request to the user agent and get a response back | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 24 | my $res = $ua->request($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # Check the outcome of the response | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 24 | ▶ | unless ($res->is_success) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | die "Pastor: Schema Parser : cannot GET from URL '$schema_url' : " . $res->status_line . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 24 | $schema_str = $res->content; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 24 | ▶ | print STDERR "Pastor : Parsing schema ...\n" if ($verbose >= 2); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 24 | my $parser = XML::LibXML->new(); | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 24 | my $doc = $parser->parse_string($schema_str); | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 24 | ▶ | print STDERR "Pastor : Parsing ended\n" if ($verbose >= 2); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 24 | return $doc; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # Parse a schema or an array of schemas into a Pastor schema model. | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # Recurse if given an array. | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # see 'parse' for more details. | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 33 | ▶ | sub _process { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process: called CC=15 SCAR=28.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 33 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 33 | my $args = {@_}; | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 33 | my $verbose = $self->verbose; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # We need a schema to process. Otherwise why are we here? | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 33 | ▶ | defined($args->{schema}) or die "Pastor: Process Schema : Undefined schema!\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # If the given 'schema' argument is an ARRAY, then | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # recurse on each of the items one by one. | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 33 | my $schema = $args->{schema}; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 33 | ▶ | if (ref($schema) =~ /ARRAY/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 9 | foreach my $s (@$schema) { | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | 9 | $args->{schema} = $s; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | 9 | $self->_process(%$args); | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 9 | return $self->model(); | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 24 | ▶ | print STDERR "Pastor : Processing schema : '$args->{schema}' ...\n" if($verbose >= 2); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # By default the 'operation' is 'process', but it could have been | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # 'include' for example. | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 24 | ▶ | unless (defined($args->{operation})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 9 | $args->{operation} = "process"; | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # chdir into the directory of the schema | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # TODO : How to handle HTTP or FTP URLs. | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 24 | $schema = $args->{schema}; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 24 | my $schema_url; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | my $file_possible; | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 24 | SWITCH: for ($schema) { | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | # A URL | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | /^(http|https|ftp|file):/i and do { $schema_url = URI->new($schema); last SWITCH; }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # An XSD string | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | /<\// and do { $schema_url = undef; $args->{schema_str} = $schema; last SWITCH; }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # A file name | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 24 | OTHERWISE: do { $schema_url = URI->new($schema); $file_possible=1; last SWITCH; }; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 24 | ▶ | if ( defined($schema_url) && defined($self->context()) && defined($self->context()->schema_url)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
defined $schema_url and defined $self->context and defined $self->context->schema_url
defined $schema_url and defined $self->context
MC/DC33%1/3
defined $schema_url and defined $self->context and defined $self->context->schema_url
defined $schema_url
defined $self->context
defined $self->context->schema_url
Truth table50%2/4
A and B and C
A= defined $schema_urlB= defined $self->contextC= defined $self->context->schema_url
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 15 | $schema_url = $schema_url->abs($self->context()->schema_url); | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | ▶ | }elsif (defined($schema_url) && $file_possible) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $schema_url and $file_possible
MC/DC0%0/2
defined $schema_url and $file_possible
defined $schema_url
$file_possible
Truth table33%1/3
A and B
A= defined $schema_urlB= $file_possible
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 9 | $schema_url = $schema_url->abs(URI::file->cwd); | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 24 | $args->{schema_url} = $schema_url; | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # Push a new CONTEXT on the stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 24 | my $context = XML::Pastor::Schema::Context->new(%$args); | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 24 | $self->contextStack->push($context); | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # Parse the schema into a DOM tree. | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 24 | my $schema_doc = $self->parseToDom(%$args); | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # Now start processing each node of the schema, starting from the ROOT element. | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | #_print_xml_doc($schema_doc); | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 24 | $self->_processNode($schema_doc); | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # Pop the context from the stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 24 | $self->contextStack->pop(); | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 24 | ▶ | print STDERR "Pastor : Process ENDED : '$args->{schema}' ...\n" if($verbose >= 2); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # return our resulting "model" | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 24 | return $self->model(); | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # This routine is the heart of the parsing process. | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # It will "process" an element that is encountered in the | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # schema and then it will recurse in order to process its children. | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # Keeps track of the parser state with a 'nodeStack' that holds the | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # previously created model objects (Attribute, Element, ComplexType, SimpleType, Group, ...). | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # On the top of the stack will appear the object that was most recently created. | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 645 | ▶ | sub _processNode { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processNode: called CC=38 SCAR=37.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 645 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 241 | 645 | my $node=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | 645 | my $verbose = $self->verbose; | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # If we are given a DOM document, instead of an ELEMENT, then | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # just recurse with the ROOT element. | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 645 | ▶ | if (UNIVERSAL::isa($node, "XML::LibXML::Document")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 24 | return $self->_processNode($node->documentElement()); | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # We only process DOM elements here, nothing else means much to us. | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 621 | ▶ | unless (UNIVERSAL::isa($node, "XML::LibXML::Element")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 621 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | 621 | my $model = $self->model(); | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | 621 | my $nodeStack = $context->nodeStack(); | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 621 | my $obj =undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # TODO : Namespaces | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 621 | my $name = $node->localName; | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 621 | ▶ | if ($verbose >= 10) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $attribs = getAttributeHash($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | print STDERR " $name ($attribs->{name})\n" ; | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # If the element name matches any string below, we'll do the corresponding action. | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 621 | SWITCH: for ($name){ # iterator = $_ (we'll do pattern matching on it) | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | 621 | ▶ | /^all$/ and do { last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 620 | ▶ | /^annotation$/ and do { last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 574 | ▶ | /^appinfo$/ and return 0; # ignore children as well | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 574 | ▶ | /^attribute$/ and do { $obj=$self->_processAttribute($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 484 | ▶ | /^attributeGroup$/ and do { $obj=$self->_processAttributeGroup($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | /^choice$/ and do { last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 482 | ▶ | /^complexContent$/ and do { last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 479 | ▶ | /^complexType$/ and do { $obj=$self->_processComplexType($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 421 | ▶ | /^documentation$/ and do { $obj=$self->_processDocumentation($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 375 | ▶ | /^element$/ and do { $obj=$self->_processElement($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 247 | ▶ | /^extension$/ and do { $obj=$self->_processExtension($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 239 | ▶ | /^enumeration$/ and do { $obj=$self->_processEnumeration($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | /^field$/ and do { return 0;}; # ignore children as well | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 234 | ▶ | /^group$/ and do { $obj=$self->_processGroup($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 232 | ▶ | /^import$/ and do { $obj=$self->_processImport($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 230 | ▶ | /^include$/ and do { $obj=$self->_processInclude($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | /^key$/ and do { return 0;}; # ignore children as well | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | /^keyref$/ and do { return 0;}; # ignore children as well | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 217 | ▶ | /^list$/ and do { $obj=$self->_processList($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | /^redefine$/ and do { $obj=$self->_processRedefine($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 211 | ▶ | /^restriction$/ and do { $obj=$self->_processRestriction($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 179 | ▶ | /^schema$/ and do { $obj=$self->_processSchemaNode($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | /^selector$/ and do { return 0;}; # ignore children as well | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 155 | ▶ | /^sequence$/ and do { last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 124 | ▶ | /^simpleContent$/ and do { $obj=$self->_processSimpleContent($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 119 | ▶ | /^simpleType$/ and do { $obj=$self->_processSimpleType($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | /^unique$/ and do { return 0;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 69 | ▶ | /^union$/ and do { $obj=$self->_processUnion($node); last SWITCH;}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 57 | OTHERWISE: { $obj=$self->_processOtherNodes($node);}; | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # If the above created a model object, push it on the node stack within the current | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 621 | ▶ | if (defined($obj)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 372 | $nodeStack->push($obj); | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # RECURSE into children. | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 621 | my @children = grep {UNIVERSAL::isa($_, "XML::LibXML::Element")} $node->childNodes(); | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | 621 | foreach my $child (@children) { | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | 597 | $self->_processNode($child); | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # CLEAN UP | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 621 | ▶ | if (defined($obj)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 372 | $self->_fixNameSpaces($obj, $node, ['type', 'base', 'ref']); | |||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # 'Union' must be post-processed | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 372 | ▶ | if (UNIVERSAL::isa($obj, "XML::Pastor::Schema::Union")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 12 | $self->_postProcessUnion($obj, $node); | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # 'List' must be post-processed | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 372 | ▶ | if (UNIVERSAL::isa($obj, "XML::Pastor::Schema::List")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 6 | $self->_postProcessList($obj, $node); | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 372 | $nodeStack->pop(); | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 621 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # This routine is called whenever an 'attribute' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 90 | ▶ | sub _processAttribute { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processAttribute: called CC=5 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 90 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | 90 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 339 | 90 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # Create an "Attribute" schema model object and set all fields with the | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # attributes of this node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 90 | my $obj = XML::Pastor::Schema::Attribute->new()->setFields(getAttributeHash($node)); | |||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # Fix-up the scope and the name of the newly created object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 90 | $self->_fixUpObject($obj, $node); | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # All attributes must have a name. | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 90 | ▶ | unless ($obj->name()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | die "Pastor : Attribute must have a name!\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 90 | ▶ | if ($obj->scope() =~ /local/io) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # local attribute. Add it to the attribute list of the corresponding | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # ComplexType or AttributeGroup that is closest to the top of the node stack in | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # the current context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 90 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::ComplexType", | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | "XML::Pastor::Schema::AttributeGroup"])) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 90 | my $attribs=$host->attributes(); | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | 90 | my $attribInfo=$host->attributeInfo(); | |||||||||||||||||||||||||||||||||||||||||||||
| 361 | 90 | push @$attribs, $obj->name(); | |||||||||||||||||||||||||||||||||||||||||||||
| 362 | 90 | $attribInfo->{$obj->name()} = $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 363 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # An 'orphan' attribute. What is it doing here? | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | die "Pastor : Attribute '" . $obj->name . "' found where unexpected!\n" . sprint_xml_element($node->parentNode() || $node) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$node->parentNode || $node
MC/DC0%0/2
$node->parentNode || $node
$node->parentNode
$node
Truth table0%0/3
A || B
A= $node->parentNodeB= $node
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # Global attribute. Add it to the model. | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $self->model()->add(object=>$obj, operation=>$context->operation()); | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | # Return the model object to be pushed on the node stack of the current context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 90 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # This routine is called whenever an 'attributeGroup' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | ▶ | sub _processAttributeGroup { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processAttributeGroup: called CC=5 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | 2 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 383 | 2 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # Create an "AttributeGroup" schema model object and set all fields with the | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # attributes of this node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 2 | my $obj = XML::Pastor::Schema::AttributeGroup->new()->setFields(getAttributeHash($node)); | |||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # Fix-up the scope and the name of the newly created object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 2 | $self->_fixUpObject($obj, $node); | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | ▶ | unless ($obj->name()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | die "Pastor : Attribute Group must have a name!\n" . sprint_xml_element($node) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 2 | ▶ | if ($obj->scope() =~ /local/io) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # Local scope.Add it to the attribute list of the corresponding | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # ComplexType that is closest to the top of the node stack in | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # the current context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::ComplexType", "XML::Pastor::Schema::AttributeGroup"])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | my $attribs=$host->attributes(); | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | 1 | my $attribInfo=$host->attributeInfo(); | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | 1 | push @$attribs, $obj->name(); | |||||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | $attribInfo->{$obj->name()} = $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # An 'orphan' attribute group. What is it doing here? | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | die "Pastor : Element '" . $obj->name . "' found where unexpected!\n" . sprint_xml_element($node->parentNode() || $node) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$node->parentNode || $node
MC/DC0%0/2
$node->parentNode || $node
$node->parentNode
$node
Truth table0%0/3
A || B
A= $node->parentNodeB= $node
| |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # Global attribute group. Add it to the model. | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | $self->model()->add(object=>$obj, operation=>$context->operation()); | |||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # Return the model object to be pushed on the node stack of the current context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 2 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||
| 418 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # This routine is called whenever an 'element' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 128 | ▶ | sub _processElement { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processElement: called CC=6 SCAR=20.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 128 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | 128 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | 128 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # Create an "Element" schema model object and set all fields with the | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # attributes of this node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 128 | my $obj = XML::Pastor::Schema::Element->new()->setFields(getAttributeHash($node)); | |||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # Fix-up the scope and the name of the newly created object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 128 | $self->_fixUpObject($obj, $node); | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | 128 | ▶ | unless ($obj->name()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | die "Pastor : Element must have a name!\n" . sprint_xml_element($node->parentNode() || $node) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$node->parentNode || $node
MC/DC0%0/2
$node->parentNode || $node
$node->parentNode
$node
Truth table0%0/3
A || B
A= $node->parentNodeB= $node
| |||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 128 | ▶ | if ($obj->scope() =~ /local/io) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # local element. | ||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # Add it to the element list of the corresponding | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # ComplexType that is closest to the top of the node stack in | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # the current context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 87 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::ComplexType", "XML::Pastor::Schema::Group"])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 87 | my $elems=$host->elements(); | |||||||||||||||||||||||||||||||||||||||||||||
| 444 | 87 | my $elemInfo=$host->elementInfo(); | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | 87 | push @$elems, $obj->name(); | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | 87 | $elemInfo->{$obj->name()} = $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 447 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | # An 'orphan' element. What is it doing here? | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | die "Pastor : Element '" . $obj->name . "' found where unexpected!\n" . sprint_xml_element($node->parentNode() || $node) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$node->parentNode || $node
MC/DC0%0/2
$node->parentNode || $node
$node->parentNode
$node
Truth table0%0/3
A || B
A= $node->parentNodeB= $node
| |||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # Global element. Add it to the model. | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 41 | $self->model()->add(object=>$obj,operation=>$context->operation()); | |||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # Return the model object to be pushed on the node stack of the current context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 128 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # This routine is called whenever a 'group' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 2 | ▶ | sub _processGroup { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processGroup: called CC=6 SCAR=20.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 466 | 2 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 467 | 2 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # Create an "Group" schema model object and set all fields with the | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # attributes of this node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 2 | my $obj = XML::Pastor::Schema::Group->new()->setFields(getAttributeHash($node)); | |||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # Fix-up the scope and the name of the newly created object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 2 | $self->_fixUpObject($obj, $node); | |||||||||||||||||||||||||||||||||||||||||||||
| 475 | 2 | ▶ | unless ($obj->name()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | die "Pastor : Group must have a name!\n" . sprint_xml_element($node->parentNode() || $node) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$node->parentNode || $node
MC/DC0%0/2
$node->parentNode || $node
$node->parentNode
$node
Truth table0%0/3
A || B
A= $node->parentNodeB= $node
| |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 2 | ▶ | if ($obj->scope() =~ /local/io) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 480 | # local scope. | ||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # Add it to the element list of the corresponding | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | # ComplexType that is closest to the top of the node stack in | ||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # the current context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 1 | ▶ | if (my $host=$context->findNode(class=>"XML::Pastor::Schema::ComplexType")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 1 | my $elems=$host->elements(); | |||||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | my $elemInfo=$host->elementInfo(); | |||||||||||||||||||||||||||||||||||||||||||||
| 487 | 1 | push @$elems, $obj->name(); | |||||||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | $elemInfo->{$obj->name()} = $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 489 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # An 'orphan' group. What is it doing here? | ||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | die "Pastor : Element '" . $obj->name . "' found where unexpected!\n" . sprint_xml_element($node->parentNode() || $node) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$node->parentNode || $node
MC/DC0%0/2
$node->parentNode || $node
$node->parentNode
$node
Truth table0%0/3
A || B
A= $node->parentNodeB= $node
| |||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 493 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # Global group. Add it to the model. | ||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 1 | $self->model()->add(object=>$obj,operation=>$context->operation()); | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | # Return the model object to be pushed on the node stack of the current context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 2 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # This routine is called whenever an 'documentation' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 506 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 46 | ▶ | sub _processDocumentation { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processDocumentation: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 46 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 509 | 46 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 510 | 46 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 511 | 46 | my $attribs = getAttributeHash($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 512 | 46 | my $value = $attribs->{value}; | |||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | # Find the top-most SimpleType model object closest to the top of the node-stack | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | # of the current context. This will become our 'host' object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 46 | ▶ | if (my $host=$context->findNode(class=>"XML::Pastor::Schema::Object")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # If this is the first enumeration. Create the array. | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 46 | ▶ | unless (defined($host->documentation())) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 46 | $host->documentation(Data::HashArray->new()); | |||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | # Create the nex documentation | ||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 46 | my $doc = XML::Pastor::Schema::Documentation->new(); | |||||||||||||||||||||||||||||||||||||||||||||
| 524 | 46 | $doc->setFields($attribs); | |||||||||||||||||||||||||||||||||||||||||||||
| 525 | 46 | $doc->text($node->textContent()); | |||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 46 | my $docs = $host->documentation; | |||||||||||||||||||||||||||||||||||||||||||||
| 528 | 46 | push @$docs, $doc; | |||||||||||||||||||||||||||||||||||||||||||||
| 529 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # What is an 'documentation' doing outside the scope of a 'Schema::Object'? | ||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | die "Pastor : Documentation found where unexpected!\n" . sprint_xml_element($node->parentNode() || $node) . "\n";; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$node->parentNode || $node
MC/DC0%0/2
$node->parentNode || $node
$node->parentNode
$node
Truth table0%0/3
A || B
A= $node->parentNodeB= $node
| |||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | # Nothing will get pushed on the node-stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 46 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||
| 538 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # This routine is called whenever an 'enumeration' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 541 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 5 | ▶ | sub _processEnumeration { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processEnumeration: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 544 | 5 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 545 | 5 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 546 | 5 | my $attribs = getAttributeHash($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 547 | 5 | my $value = $attribs->{value}; | |||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||
| 549 | # Find the top-most SimpleType model object closest to the top of the node-stack | ||||||||||||||||||||||||||||||||||||||||||||||
| 550 | # of the current context. This will become our 'host' object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 5 | ▶ | if (my $host=$context->findNode(class=>"XML::Pastor::Schema::SimpleType")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 552 | # If this is the first enumeration. Create the hash. | ||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 5 | ▶ | unless (defined($host->enumeration())) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 1 | $host->enumeration({}) | |||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # register this enumeration value. | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 5 | my $enums=$host->enumeration(); | |||||||||||||||||||||||||||||||||||||||||||||
| 558 | 5 | $enums->{$value}=1; | |||||||||||||||||||||||||||||||||||||||||||||
| 559 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # What is an 'enumeration' doing outside the scope of a 'SimpleType'? | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | die "Pastor : Enumeration found where unexpected!\n" . sprint_xml_element($node->parentNode() || $node) . "\n";; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$node->parentNode || $node
MC/DC0%0/2
$node->parentNode || $node
$node->parentNode
$node
Truth table0%0/3
A || B
A= $node->parentNodeB= $node
| |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # Nothing will get pushed on the node-stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 5 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||
| 570 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # This routine is called whenever an 'extension' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 572 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 573 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 574 | # Extension is easy. We don't create any object to be pushed on the node stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 575 | # It is effectively ignored except for its attributes which are copied onto | ||||||||||||||||||||||||||||||||||||||||||||||
| 576 | # the Complex or Simple Type object that is closest to the top of the node stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 577 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 8 | ▶ | sub _processExtension { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processExtension: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 580 | 8 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 581 | 8 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 582 | 8 | my $attribs = getAttributeHash($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 8 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::ComplexType", "XML::Pastor::Schema::SimpleType"])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 8 | $host->setFields($attribs); | |||||||||||||||||||||||||||||||||||||||||||||
| 587 | 8 | $host->derivedBy("extension"); | |||||||||||||||||||||||||||||||||||||||||||||
| 588 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | die "Pastor : Extension found where unexpected!\n" . sprint_xml_element($node->parentNode()) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # Nothing will get pushed on the node-stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 8 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||
| 596 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 597 | # This routine is called whenever a 'union' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 598 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 600 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 12 | ▶ | sub _processUnion { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processUnion: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 603 | 12 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 604 | 12 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||
| 606 | # Create a "Union" schema model object and set all fields with the | ||||||||||||||||||||||||||||||||||||||||||||||
| 607 | # attributes of this node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 12 | my $obj = XML::Pastor::Schema::Union->new()->setFields(getAttributeHash($node)); | |||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 12 | $self->_fixMemberTypesNameSpace($obj, $node); # Patch by IKEGAMI | |||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 12 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::SimpleType"])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 12 | $host->base("Union|http://www.w3.org/2001/XMLSchema"); | |||||||||||||||||||||||||||||||||||||||||||||
| 614 | 12 | $host->derivedBy("union"); | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | die "Pastor : 'union' found where unexpected!\n" . sprint_xml_element($node->parentNode()) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||
| 619 | # This object will get pushed on the node-stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 12 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||
| 623 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 12 | ▶ | sub _postProcessUnion { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_postProcessUnion: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 626 | 12 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 627 | 12 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 628 | 12 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||
| 630 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 12 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::SimpleType"])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 12 | $host->setFields(%$obj); | |||||||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 12 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||
| 638 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 639 | # This routine is called whenever a 'list' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 640 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 641 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 642 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 6 | ▶ | sub _processList { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processList: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 645 | 6 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 646 | 6 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||
| 648 | # Create a "List" schema model object and set all fields with the | ||||||||||||||||||||||||||||||||||||||||||||||
| 649 | # attributes of this node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 6 | my $obj = XML::Pastor::Schema::List->new()->setFields(getAttributeHash($node)); | |||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 6 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::SimpleType"])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 6 | $host->base("List|http://www.w3.org/2001/XMLSchema"); | |||||||||||||||||||||||||||||||||||||||||||||
| 654 | 6 | $host->derivedBy("list"); | |||||||||||||||||||||||||||||||||||||||||||||
| 655 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | die "Pastor : 'list' found where unexpected!\n" . sprint_xml_element($node->parentNode()) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||
| 659 | # This object will get pushed on the node-stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 6 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||
| 663 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 6 | ▶ | sub _postProcessList { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_postProcessList: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 666 | 6 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 667 | 6 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 668 | 6 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 6 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::SimpleType"])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 6 | $host->setFields(%$obj); | |||||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 6 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||
| 677 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 678 | # This routine is called whenever an 'include' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 679 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 680 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 13 | ▶ | sub _processInclude { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processInclude: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 683 | 13 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 684 | 13 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 685 | 13 | my $attribs = getAttributeHash($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 686 | 13 | my $schemaLocation = $attribs->{schemaLocation}; | |||||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||||||
| 688 | # "inlude" element must be a child of the schema element. It can't be deeper. | ||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 13 | ▶ | unless (UNIVERSAL::isa($context->topNode(), "XML::Pastor::Schema")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | die "Pastor : Schema INCLUDE must be global!\n" . sprint_xml_element($node) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||
| 693 | # Just call the method that does the inclusion. | ||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 13 | $self->includeSchema(schema=>$schemaLocation); | |||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||
| 696 | # Nothing will get pushed on the node-stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 13 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||
| 700 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 701 | # This routine is called whenever an 'import' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 702 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 703 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 2 | ▶ | sub _processImport { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processImport: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 706 | 2 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 707 | 2 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 708 | 2 | my $attribs = getAttributeHash($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 709 | 2 | my $schemaLocation = $attribs->{schemaLocation}; | |||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||
| 711 | # "import" element must be a child of the schema element. It can't be deeper. | ||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 2 | ▶ | unless (UNIVERSAL::isa($context->topNode(), "XML::Pastor::Schema")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | die "Pastor : Schema IMPORT must be global!\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||
| 716 | # Just call the method that does the import. | ||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 2 | $self->importSchema(schema=>$schemaLocation); | |||||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||||||
| 719 | # Nothing will get pushed on the node-stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||||||
| 723 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 724 | # This routine is called whenever an 'redfine' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 725 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 726 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | ▶ | sub _processRedefine { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processRedefine: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | my $attribs = getAttributeHash($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | my $schemaLocation = $attribs->{schemaLocation}; | |||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||
| 734 | # "redefine" element must be a child of the schema element. It can't be deeper. | ||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | unless (UNIVERSAL::isa($context->topNode(), "XML::Pastor::Schema")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | die "Pastor : Schema REPLACE must be global!\n" . sprint_xml_element($node) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||
| 739 | # Just call the method that does the redefine. | ||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | $self->redefineSchema(schema=>$schemaLocation); | |||||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||||||
| 742 | # Nothing will get pushed on the node-stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||
| 746 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 747 | # This routine is called whenever an 'restriction' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 749 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 750 | # "Restriction" is easy. We don't create any object to be pushed on the node stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 751 | # It is effectively ignored except for its attributes which are copied onto | ||||||||||||||||||||||||||||||||||||||||||||||
| 752 | # the Complex or Simple Type object that is closest to the top of the node stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 753 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 32 | ▶ | sub _processRestriction { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processRestriction: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 32 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 756 | 32 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 757 | 32 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 758 | 32 | my $attribs = getAttributeHash($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 32 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::SimpleType", "XML::Pastor::Schema::ComplexType"])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 32 | $host->setFields($attribs); | |||||||||||||||||||||||||||||||||||||||||||||
| 762 | 32 | $host->derivedBy("restriction"); | |||||||||||||||||||||||||||||||||||||||||||||
| 763 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | die "Pastor : Restriction found where unexpected!\n" . sprint_xml_element($node->parentNode()) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 32 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||||||
| 770 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 771 | # This routine is called whenever an 'schema' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 772 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 773 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 774 | # Normally this should occur only once and first in a given schema file. | ||||||||||||||||||||||||||||||||||||||||||||||
| 775 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 24 | ▶ | sub _processSchemaNode { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processSchemaNode: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 778 | 24 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 779 | 24 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 780 | 24 | my $obj = XML::Pastor::Schema->new()->setFields(getAttributeHash($node)); | |||||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 24 | ▶ | if ($context->nodeStack->count()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | die "Pastor : Schema elements cannot be nested!\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 24 | my $nsUri = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 787 | 24 | ▶ | if ($obj->targetNamespace) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 788 | # Schema defines a targetNamspace. It's easy. | ||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 8 | $nsUri = $obj->targetNamespace(); | |||||||||||||||||||||||||||||||||||||||||||||
| 790 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 791 | # This schema doesn't define a targetNamespace itself. It probably means its included. | ||||||||||||||||||||||||||||||||||||||||||||||
| 792 | # But perhaps we can get it from the previous schema. | ||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 16 | my $cstack= $self->contextStack; | |||||||||||||||||||||||||||||||||||||||||||||
| 794 | 16 | ▶ | if ($cstack->count > 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 795 | # Lucky, we've got one. | ||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 13 | my $prevContext = $cstack->[1]; # This is the one before the top. Becuase a push is actually unshift. | |||||||||||||||||||||||||||||||||||||||||||||
| 797 | 13 | $nsUri = $prevContext->targetNamespace(); | |||||||||||||||||||||||||||||||||||||||||||||
| 798 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 799 | # Hmmm. This is a truely no-namespace schema. | ||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 3 | $nsUri = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 24 | $context->targetNamespace($nsUri); | |||||||||||||||||||||||||||||||||||||||||||||
| 806 | 24 | $self->model->addNamespaceUri($nsUri); | |||||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 24 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||||||
| 812 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 813 | # This routine is called whenever an 'simpleType' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 814 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 815 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 5 | ▶ | sub _processSimpleContent { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processSimpleContent: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 818 | 5 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 819 | 5 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||||||
| 821 | # if this is a local definition, then our host element/attribute must be of this type | ||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 5 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::ComplexType", | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 823 | ])) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 5 | $host->setFields({isSimpleContent=>1}); | |||||||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||
| 827 | # Nothing to add to the model. | ||||||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||||||
| 829 | # Nothing will get pushed on the node-stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 5 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||||||
| 835 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 836 | # This routine is called whenever an 'simpleType' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 837 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 838 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 50 | ▶ | sub _processSimpleType { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processSimpleType: called CC=8 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 50 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 841 | 50 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 842 | 50 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||||||
| 844 | # Create an "SimpleType" schema model object and set all fields with the | ||||||||||||||||||||||||||||||||||||||||||||||
| 845 | # attributes of this node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 50 | my $obj = XML::Pastor::Schema::SimpleType->new()->setFields(getAttributeHash($node)); | |||||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||||||
| 848 | # Fix-up the scope and the name of the newly created object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 50 | $self->_fixUpObject($obj, $node); | |||||||||||||||||||||||||||||||||||||||||||||
| 850 | 50 | ▶ | unless ($obj->name()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | die "Pastor : SimpleType must have a name!\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 852 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||||||
| 854 | # if this is a local definition, then our host element/attribute must be of this type | ||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 50 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::Attribute", | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 856 | "XML::Pastor::Schema::Element", | ||||||||||||||||||||||||||||||||||||||||||||||
| 857 | "XML::Pastor::Schema::Union", | ||||||||||||||||||||||||||||||||||||||||||||||
| 858 | "XML::Pastor::Schema::List", | ||||||||||||||||||||||||||||||||||||||||||||||
| 859 | ])) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 17 | ▶ | if ( UNIVERSAL::isa($host, "XML::Pastor::Schema::Attribute") || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
UNIVERSAL::isa($host, "XML::Pastor::Schema::Attribute") or UNIVERSAL::isa($host, "XML::Pastor::Schema::Element")
MC/DC0%0/2
UNIVERSAL::isa($host, "XML::Pastor::Schema::Attribute") or UNIVERSAL::isa($host, "XML::Pastor::Schema::Element")
UNIVERSAL::isa($host, "XML::Pastor::Schema::Attribute")
UNIVERSAL::isa($host, "XML::Pastor::Schema::Element")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($host, "XML::Pastor::Schema::Attribute")B= UNIVERSAL::isa($host, "XML::Pastor::Schema::Element")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 861 | UNIVERSAL::isa($host, "XML::Pastor::Schema::Element") ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | $host->setFields({type=>$obj->name()}); | |||||||||||||||||||||||||||||||||||||||||||||
| 863 | }elsif (UNIVERSAL::isa($host, "XML::Pastor::Schema::Union")) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 17 | my $mbt=$host->memberTypes; | |||||||||||||||||||||||||||||||||||||||||||||
| 865 | 17 | ▶ | $mbt .= ' ' if ($mbt); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 17 | $mbt .= $obj->name(); | |||||||||||||||||||||||||||||||||||||||||||||
| 867 | 17 | $host->memberTypes($mbt); | |||||||||||||||||||||||||||||||||||||||||||||
| 868 | }elsif (UNIVERSAL::isa($host, "XML::Pastor::Schema::List")) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | $host->itemType($obj->name); | |||||||||||||||||||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||
| 873 | # SimpleTypes are always added to the model, regardless of local or global scope. | ||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 50 | $self->model()->add(object=>$obj, operation=>$context->operation()); | |||||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||||||
| 876 | # Return the model object to be pushed on the node stack of the current context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 50 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||||||
| 880 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 881 | # This routine is called whenever an 'complexType' element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 882 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 883 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 58 | ▶ | sub _processComplexType { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processComplexType: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 58 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 886 | 58 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 887 | 58 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||||||
| 889 | # Create an "ComplexType" schema model object and set all fields with the | ||||||||||||||||||||||||||||||||||||||||||||||
| 890 | # attributes of this node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 58 | my $obj = XML::Pastor::Schema::ComplexType->new()->setFields(getAttributeHash($node)); | |||||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||||||
| 893 | # Fix-up the scope and the name of the newly created object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 58 | $self->_fixUpObject($obj, $node); | |||||||||||||||||||||||||||||||||||||||||||||
| 895 | 58 | ▶ | unless ($obj->name()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 0 | die "Pastor : ComplexType must have a name!\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||||||
| 899 | # if this is a local definition, then our host element must be of this type | ||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 58 | ▶ | if (my $host=$context->findNode(class=>["XML::Pastor::Schema::Element"])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 16 | $host->setFields({type=>$obj->name()}); | |||||||||||||||||||||||||||||||||||||||||||||
| 902 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||||||
| 904 | # ComplexTypes are always added to the model, regardless of local or global scope. | ||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 58 | $self->model()->add(object=>$obj, %$context); | |||||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||||||
| 907 | # Return the model object to be pushed on the node stack of the current context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 58 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||||||
| 911 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 912 | # This routine is called whenever any other (unidentified) element is encountered | ||||||||||||||||||||||||||||||||||||||||||||||
| 913 | # in the schema being processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 914 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 915 | # One type of such elements are those who just have a 'value' attribute. In that | ||||||||||||||||||||||||||||||||||||||||||||||
| 916 | # case we treat it as just an attribute of the top-most object in the nodeStack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 917 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 918 | # Any other element will cause a FATAL error as it is unrecognized. | ||||||||||||||||||||||||||||||||||||||||||||||
| 919 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 57 | ▶ | sub _processOtherNodes { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_processOtherNodes: called CC=10 SCAR=27.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 57 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 922 | 57 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 923 | 57 | my $name = $node->localName(); | |||||||||||||||||||||||||||||||||||||||||||||
| 924 | 57 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 925 | 57 | my $attribs = getAttributeHash($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 926 | 57 | my $value = $attribs->{value}; | |||||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 57 | ▶ | if (defined($value)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 929 | # Element with a 'value' attribute | ||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 57 | ▶ | unless ($context->nodeStack()->count()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | die "Pastor : Element '$name' unexpected as root element in schema!\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 932 | }elsif (UNIVERSAL::isa($context->topNode(), "XML::Pastor::Schema")) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | die "Pastor : Element '$name' cannot be global in schema!\n" . sprint_xml_element($node) . "\n";; | |||||||||||||||||||||||||||||||||||||||||||||
| 934 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 935 | # Just set the value as a field in the host object | ||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 57 | ▶ | if (my $host=$context->findNode(class=>"XML::Pastor::Schema::Object")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 937 | # Multiplicity is allowed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 57 | my $oldValue = $host->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 57 | ▶ | if (defined($oldValue)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 5 | my $rt =reftype($oldValue); | |||||||||||||||||||||||||||||||||||||||||||||
| 942 | 5 | ▶ | unless (defined($rt) and (reftype($oldValue) eq 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $rt and builtin::reftype($oldValue) eq "ARRAY"
MC/DC0%0/2
defined $rt and builtin::reftype($oldValue) eq "ARRAY"
defined $rt
builtin::reftype($oldValue) eq "ARRAY"
Truth table33%1/3
A and B
A= defined $rtB= builtin::reftype($oldValue) eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 5 | $oldValue = [$oldValue]; | |||||||||||||||||||||||||||||||||||||||||||||
| 944 | 5 | $host->setFields({$name=>$oldValue}); | |||||||||||||||||||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 5 | push @$oldValue, $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 947 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 52 | $host->setFields({$name=>$value}); | |||||||||||||||||||||||||||||||||||||||||||||
| 949 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||||||
| 951 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 0 | ▶ | die "Pastor : Don't know what to do with element '$name'\n" . sprint_xml_element($node->parentNode() || $node) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$node->parentNode || $node
MC/DC0%0/2
$node->parentNode || $node
$node->parentNode
$node
Truth table0%0/3
A || B
A= $node->parentNodeB= $node
| |||||||||||||||||||||||||||||||||||||||||||||||
| 953 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 955 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 0 | ▶ | die "Pastor : Unexpected element '$name' in schema!\n" . sprint_xml_element($node->parentNode() || $node) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$node->parentNode || $node
MC/DC0%0/2
$node->parentNode || $node
$node->parentNode
$node
Truth table0%0/3
A || B
A= $node->parentNodeB= $node
| |||||||||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||||||
| 959 | # Nothing will get pushed on the node-stack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 57 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 961 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||||||
| 963 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 964 | # This routine is called for most newly created model objects. | ||||||||||||||||||||||||||||||||||||||||||||||
| 965 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 966 | # It fixes the 'scope' of the given object by looking at the nodeSstack. | ||||||||||||||||||||||||||||||||||||||||||||||
| 967 | # If we are just within a "schema" element, then we are in "global" context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 968 | # Othewise we must be in local context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 969 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 970 | # It also autogenerates a name for objects when there isn't one already given | ||||||||||||||||||||||||||||||||||||||||||||||
| 971 | # as an attribute. This is handy for elements with a 'ref' attribute what without a name. | ||||||||||||||||||||||||||||||||||||||||||||||
| 972 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 973 | # It is also handy for ComplexTypes that are anonymously defined locally. Since | ||||||||||||||||||||||||||||||||||||||||||||||
| 974 | # we globalize type definitions in all cases. We need distunguashible names for them. | ||||||||||||||||||||||||||||||||||||||||||||||
| 975 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 976 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 330 | ▶ | sub _fixUpObject { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fixUpObject: called CC=14 SCAR=26.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 330 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 979 | 330 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 980 | 330 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 981 | 330 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 330 | ▶ | unless ($context->nodeStack()->count() || UNIVERSAL::isa($obj, "XML::Pastor::Schema")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$context->nodeStack->count or UNIVERSAL::isa($obj, "XML::Pastor::Schema")
MC/DC0%0/2
$context->nodeStack->count or UNIVERSAL::isa($obj, "XML::Pastor::Schema")
$context->nodeStack->count
UNIVERSAL::isa($obj, "XML::Pastor::Schema")
Truth table33%1/3
A or B
A= $context->nodeStack->countB= UNIVERSAL::isa($obj, "XML::Pastor::Schema")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 0 | die "Pastor Unexpected root element '" . $obj->name() . "' in schema. This may not be a real XSD schema!" | |||||||||||||||||||||||||||||||||||||||||||||
| 985 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 330 | ▶ | if (UNIVERSAL::isa($context->topNode(), "XML::Pastor::Schema")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 988 | # If we are immediatly underneath a schema element, | ||||||||||||||||||||||||||||||||||||||||||||||
| 989 | # this means we are in a global scope | ||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 118 | $obj->scope("global") | |||||||||||||||||||||||||||||||||||||||||||||
| 991 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 992 | # Otherwise we are in LOCAL context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 212 | $obj->scope("local"); | |||||||||||||||||||||||||||||||||||||||||||||
| 994 | 212 | ▶ | if ($obj->ref() && !$obj->name()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$obj->ref and not $obj->name
MC/DC50%1/2
$obj->ref and not $obj->name
$obj->ref
not $obj->name
Truth table66%2/3
A and not(B)
A= $obj->refB= not $obj->name
| |||||||||||||||||||||||||||||||||||||||||||||||
| 995 | # No name but this a reference. | ||||||||||||||||||||||||||||||||||||||||||||||
| 996 | # Just set the name to the reference. | ||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 32 | $obj->name($obj->ref()); | |||||||||||||||||||||||||||||||||||||||||||||
| 998 | 32 | $obj->nameIsAutoGenerated(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 999 | ▶ | }elsif (!$obj->name() && | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
not $obj->name and $context->findNode("class", "XML::Pastor::Schema::Union") || $context->findNode("class", "XML::Pastor::Schema::List")
$context->findNode("class", "XML::Pastor::Schema::Union") or $context->findNode("class", "XML::Pastor::Schema::List")
MC/DC66%2/3
not $obj->name and $context->findNode("class", "XML::Pastor::Schema::Union") || $context->findNode("class", "XML::Pastor::Schema::List")
not $obj->name
$context->findNode("class", "XML::Pastor::Schema::Union")
$context->findNode("class", "XML::Pastor::Schema::List")
Truth table75%3/4
not(A) and B or C
A= not $obj->nameB= $context->findNode("class", "XML::Pastor::Schema::Union")C= $context->findNode("class", "XML::Pastor::Schema::List")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | $context->findNode(class=>"XML::Pastor::Schema::Union") || | ||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | $context->findNode(class=>"XML::Pastor::Schema::List") | ||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | # This is a union/list item. Just use the auto-incrementer. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 17 | ▶ | unless (defined($self->counter)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 6 | $self->counter(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 1009 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 17 | $self->counter($self->counter + 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 17 | my $name = "item_" . sprintf("%04d", $self->counter); | |||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 17 | my $path = $context->namePath(separator=>"_"); | |||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 17 | ▶ | $name = $path . "_" . $name if ($path); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 17 | $obj->name($name); | |||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 17 | $obj->nameIsAutoGenerated(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 1017 | }elsif (!$obj->name()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | # No name, no reference, not union/list member. Out of luck. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | # Set the name to the concationation of all non-autogenerated | ||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | # names in the context (bottom to top) with an underscore separator. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 16 | $obj->name($context->namePath(separator=>"_")); | |||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 16 | $obj->nameIsAutoGenerated(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 1023 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 330 | ▶ | if (UNIVERSAL::can($obj, 'targetNamespace')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 330 | ▶ | $obj->targetNamespace($context->targetNamespace) if ($context->targetNamespace); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 330 | $self->_fixNameSpaces($obj, $node, ['name'], localize => 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 330 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | # This routine is called for most newly created model objects. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | # It fixes the name space URI on given fields of the object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | # for example "xs:string" will become "string|http://www.w3.org/2001/XMLSchema". | ||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | # This way, we don't deal with the namespace prefix but the NS URI itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 702 | ▶ | sub _fixNameSpaces { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fixNameSpaces: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 702 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 702 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 702 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 702 | my $fields = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 702 | my $opts = {@_}; | |||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 702 | ▶ | my $localize= $opts->{localize} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{'localize'} || 0
MC/DC100%1/1
$opts->{'localize'} || 0
$opts->{'localize'}
Truth table100%2/2
A
A= $opts->{'localize'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 702 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 702 | my $verbose = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 702 | foreach my $field (@$fields) { | |||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 1446 | my $uri = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 1446 | my $v =$obj->{$field}; | |||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 1446 | ▶ | print STDERR "Fixing up namespaces for '$field' ('$v')...\n" if ($verbose >=9); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 1446 | ▶ | if ($v && ($v =~ /\|/)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$v and $v =~ /\|/
MC/DC100%2/2
$v and $v =~ /\|/
$v
$v =~ /\|/
Truth table100%3/3
A and B
A= $vB= $v =~ /\|/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | # Do nothing. There is already a namespace in there. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | ▶ | }elsif ($v && ($v =~ /:/o)) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$v and $v =~ /:/o
MC/DC100%2/2
$v and $v =~ /:/o
$v
$v =~ /:/o
Truth table100%3/3
A and B
A= $vB= $v =~ /:/o
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | # There is a namesapce prefix in there. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 135 | my ($prefix, $local) = split /:/, $v, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 135 | $uri = $node->lookupNamespaceURI($prefix); | |||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 135 | ▶ | if ($uri) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 135 | ▶ | if ($localize) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 2 | $obj->{$field} = $local; | |||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 2 | $obj->{targetNamespace} = $uri; | |||||||||||||||||||||||||||||||||||||||||||||
| 1068 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 133 | $obj->{$field} = "$local|$uri"; | |||||||||||||||||||||||||||||||||||||||||||||
| 1070 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | }elsif ($v) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 455 | ▶ | if ($localize) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 328 | $obj->{targetNamespace} = $context->targetNamespace(); | |||||||||||||||||||||||||||||||||||||||||||||
| 1075 | }elsif (my $uri = $context->targetNamespace()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 58 | $obj->{$field} = "$v|$uri"; | |||||||||||||||||||||||||||||||||||||||||||||
| 1077 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 702 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 1081 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | # Taken from the patch by IKEGAMI on RT bug report #44760: Namespaces broken for xs:union memberTypes | ||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 12 | ▶ | sub _fixMemberTypesNameSpace { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fixMemberTypesNameSpace: called CC=12 SCAR=30.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 12 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 12 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 12 | my $opts = {@_}; | |||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 12 | ▶ | my $localize= $opts->{localize} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{'localize'} || 0
MC/DC0%0/1
$opts->{'localize'} || 0
$opts->{'localize'}
Truth table50%1/2
A
A= $opts->{'localize'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 12 | my $context = $self->context(); | |||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 12 | ▶ | my $verbose = $self->verbose || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->verbose || 0
MC/DC0%0/1
$self->verbose || 0
$self->verbose
Truth table50%1/2
A
A= $self->verbose
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 12 | my @mbts = split ' ', $obj->memberTypes; | |||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 12 | ▶ | print STDERR "Fixing up namespaces for 'memberTypes' ('@mbts')...\n" if ($verbose >=9); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 12 | foreach my $mbt (@mbts) { | |||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 15 | ▶ | if ($mbt && ($mbt =~ /\|/)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$mbt and $mbt =~ /\|/
MC/DC0%0/2
$mbt and $mbt =~ /\|/
$mbt
$mbt =~ /\|/
Truth table33%1/3
A and B
A= $mbtB= $mbt =~ /\|/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | # Do nothing. There is already a namespace in there. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | ▶ | }elsif ($mbt && ($mbt =~ /:/o)) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$mbt and $mbt =~ /:/o
MC/DC0%0/2
$mbt and $mbt =~ /:/o
$mbt
$mbt =~ /:/o
Truth table33%1/3
A and B
A= $mbtB= $mbt =~ /:/o
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | # There is a namesapce prefix in there. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 0 | my ($prefix, $local) = split /:/, $mbt, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 0 | my $uri = $node->lookupNamespaceURI($prefix); | |||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 0 | ▶ | if ($uri) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 0 | $mbt = "$local|$uri"; | |||||||||||||||||||||||||||||||||||||||||||||
| 1106 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | }elsif ($mbt) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 15 | ▶ | if (my $uri = $context->targetNamespace()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 10 | $mbt = "$mbt|$uri"; | |||||||||||||||||||||||||||||||||||||||||||||
| 1110 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 12 | $obj->memberTypes(join ' ', @mbts); | |||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 12 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 1115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 1119 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||