Compile/Translate.pm

filter: Statementstmt 93.2% 680 / 729 Branchbran 71.9% 387 / 538 Conditioncond 70.6% 147 / 208 MC/DCmcdc 40.9% 50 / 122 Subroutinesub 92.3% 60 / 65 Podpod 6.5% 3 / 46 totaltotal 77.6% 1327 / 1708 CC 360 SCAR 30.6
CC
360
Cov
82%
element
64.3
findHooks
33.2
attribute
32.8
CRAP 21.3
« Compile.pm ↑ Summary Compile/Schema.pm »
1 # Copyrights 2006-2024 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of distribution XML-Compile. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package XML::Compile::Translate;{
10 50 our $VERSION = '1.64';
11 }
12  
13  
14 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 50 ▶no warnings 'recursion'; # trees can be quite deep
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # Errors are either in _class 'usage': called with request
19 # or 'schema': syntax error in schema
20  
21 50 ▶use Log::Report 'xml-compile', syntax => 'SHORT';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 50 ▶use List::Util qw/first max/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 50 ▶use XML::Compile::Schema::Specs;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 50 ▶use XML::Compile::Schema::BuiltInFacets;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 50 ▶use XML::Compile::Schema::BuiltInTypes qw/%builtin_types/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 50 ▶use XML::Compile::Util qw/pack_type unpack_type type_of_node SCHEMA2001
Subroutine BEGIN: called CC=1 SCAR=0.0
28 50 unpack_id/;
29 50 ▶use XML::Compile::Iterator ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 50 my %translators =
32 ( READER => 'XML::Compile::Translate::Reader'
33 , WRITER => 'XML::Compile::Translate::Writer'
34 , TEMPLATE => 'XML::Compile::Translate::Template'
35 );
36  
37 # Elements from the schema to ignore: remember, we are collecting data
38 # from the schema, but only use selective items to produce processors.
39 # All the sub-elements of these will be ignored automatically
40 # Don't known whether we ever need the notation... maybe
41 50 my $assertions = qr/assert|report/;
42 50 my $id_constraints = qr/unique|key|keyref/;
43 50 my $ignore_elements = qr/^(?:notation|annotation|$id_constraints|$assertions)$/;
44  
45 50 my $particle_blocks = qr/^(?:sequence|choice|all|group)$/;
46 50 my $attribute_defs = qr/^(?:attribute|attributeGroup|anyAttribute)$/;
47  
48  
49 sub new($@)
50 779 ▶{ my ($baseclass, $trans) = (shift, shift);
Subroutine new: called CC=3 SCAR=11.3
Pod documented
51 779 ▶ my $class = $translators{$trans}
Branch: 1 branch
BranchTrueFalseTotal
my $class = $translators{$trans} or &error(&__x("translator back-end {name} not defined", "name", $trans)) 779 0 779
52 or error __x"translator back-end {name} not defined", name => $trans;
53  
54 779 eval "require $class";
55 779 ▶ fault $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 779 779
56  
57 779 (bless {}, $class)->init( {@_} );
58 }
59  
60 sub init($)
61 779 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=3 SCAR=11.4
Pod undocumented
62 779 ▶ $self->{nss} = $args->{nss} or panic "no namespace tables";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"nss"} = $args->{"nss"} or &panic("no namespace tables") 779 0 779
63 779 ▶ $self->{prefixes} = $args->{prefixes} || {};
Condition50%1/2
$args->{'prefixes'} || {}
l!l
0779
MC/DC0%0/1
$args->{'prefixes'} || {}
$args->{'prefixes'}
Truth table50%1/2
A
A= $args->{'prefixes'}
Aresult
11
00
64 779 $self;
65 }
66  
67  
68 sub register($)
69 0 ▶{ my ($class, $name) = @_;
Subroutine register: not called CC=2 SCAR=17.9
Pod documented
70 0 ▶ UNIVERSAL::isa($class, __PACKAGE__)
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($class, __PACKAGE__) or &error(&__x("back-end {class} does not extend {base}", "class", $class, "base", __PACKAGE__)) 0 0 0
71 or error __x"back-end {class} does not extend {base}"
72 , class => $class, base => __PACKAGE__;
73 0 $translators{$name} = $class;
74 }
75  
76  
77 # may disappear, so not documented publicly (yet)
78 0 ▶sub actsAs($) { panic "not implemented" }
Subroutine actsAs: not called CC=1 SCAR=6.9
Pod undocumented
79  
80 #--------
81  
82 sub compile($@)
83 779 ▶{ my ($self, $item, %args) = @_;
Subroutine compile: called CC=10 SCAR=24.3
Pod documented
84 779 @$self{keys %args} = values %args; # dirty. Always all the same fields
85  
86 779 ▶ my $path = $self->prefixed($item, 1) || $item;
Condition66%2/3
$self->prefixed($item, 1) || $item
l!l&&r!l&&!r
447350
MC/DC0%0/2
$self->prefixed($item, 1) || $item
$self->prefixed($item, 1) $item
Truth table66%2/3
A || B
A= $self->prefixed($item, 1)B= $item
ABresult
1X1
011
000
87 779 ▶ ref $item
Branch: 1 branch
BranchTrueFalseTotal
ref $item and &panic("expecting an item as point to start at $path") 0 779 779
88 and panic "expecting an item as point to start at $path";
89  
90 779 ▶ my $hooks = $self->{hooks} ||= [];
Condition100%2/2
$self->{"hooks"} ||= []
l!l
76019
MC/DC100%1/1
$self->{"hooks"} ||= []
$self->{"hooks"}
Truth table100%2/2
A
A= $self->{"hooks"}
Aresult
11
00
91 779 ▶ my $typemap = $self->{typemap} ||= {};
Condition100%2/2
$self->{"typemap"} ||= {}
l!l
76316
MC/DC100%1/1
$self->{"typemap"} ||= {}
$self->{"typemap"}
Truth table100%2/2
A
A= $self->{"typemap"}
Aresult
11
00
92 779 $self->typemapToHooks($hooks, $typemap);
93  
94 $self->{blocked_nss}
95 779 = $self->decodeBlocked(delete $self->{block_namespace});
96  
97 779 my $nsp = $self->namespaces;
98 779 foreach my $t (keys %$typemap)
99 9 ▶ { $nsp->find(complexType => $t) || $nsp->find(simpleType => $t)
Branch: 1 branch
BranchTrueFalseTotal
$nsp->find("complexType", $t) or $nsp->find("simpleType", $t) or &error(&__x("complex or simpleType {type} for typemap unknown", "type", $t)) 9 0 9
Condition33%1/3
$nsp->find("complexType", $t) or $nsp->find("simpleType", $t)
l!l&&r!l&&!r
900
MC/DC0%0/2
$nsp->find("complexType", $t) or $nsp->find("simpleType", $t)
$nsp->find("complexType", $t) $nsp->find("simpleType", $t)
Truth table33%1/3
A or B
A= $nsp->find("complexType", $t)B= $nsp->find("simpleType", $t)
ABresult
1X1
011
000
100 or error __x"complex or simpleType {type} for typemap unknown"
101 , type => $t;
102 }
103  
104 779 ▶ if(my $def = $self->namespaces->findID($item))
Branch: 1 branch
BranchTrueFalseTotal
if (my $def = $self->namespaces->findID($item)) 0 779 779
105 0 { my $node = $def->{node};
106 0 my $name = $node->localName;
107 0 $item = $def->{full};
108 }
109  
110 779 delete $self->{_created};
111 779 my $produce = $self->topLevel($path, $item, 1);
112 777 delete $self->{_created};
113  
114 my $in = $self->{include_namespaces}
115 777 ▶ or return $produce;
Branch: 1 branch
BranchTrueFalseTotal
my $in = $self->{"include_namespaces"} or return $produce 121 656 777
116  
117 121 $self->makeWrapperNs($path, $produce, $self->{prefixes}, $in);
118 }
119  
120 sub assertType($$$$)
121 2170 ▶{ my ($self, $where, $field, $type, $value) = @_;
Subroutine assertType: called CC=3 SCAR=13.5
Pod undocumented
122 2170 my $checker = $builtin_types{$type}{check};
123 2170 ▶ unless(defined $checker)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $checker) 0 2170 2170
124 0 { mistake "useless assert for type $type";
125 0 return;
126 }
127  
128 2170 ▶ return if $checker->($value);
Branch: 1 branch
BranchTrueFalseTotal
if &$checker($value) 2170 0 2170
129  
130 0 error __x"field {field} contains '{value}' which is not a valid {type} at {where}"
131 , field => $field, value => $value, type => $type, where => $where
132 , _class => 'usage';
133  
134 }
135  
136 sub extendAttrs($@)
137 54 ▶{ my ($self, $in, $add) = @_;
Subroutine extendAttrs: called CC=7 SCAR=19.8
Pod undocumented
138  
139 54 ▶ if(my $a = $add->{attrs})
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = $add->{"attrs"}) 54 0 54
140 { # new attrs overrule old definitions (restrictions)
141 54 my (@attrs, %code);
142 54 ▶ my @all = (@{$in->{attrs} || []}, @{$add->{attrs} || []});
Condition75%3/4
$in->{'attrs'} || []
l!l
3024
$add->{'attrs'} || []
l!l
540
MC/DC100%1/1
$in->{'attrs'} || []
$in->{'attrs'}
MC/DC0%0/1
$add->{'attrs'} || []
$add->{'attrs'}
Truth table100%2/2
A
A= $in->{'attrs'}
Aresult
11
00
Truth table50%1/2
A
A= $add->{'attrs'}
Aresult
11
00
143 54 ▶ while(@all)
Branch: 1 branch
BranchTrueFalseTotal
if (@all) 80 54 134
144 80 { my ($type, $code) = (shift @all, shift @all);
145 80 ▶ if($code{$type})
Branch: 1 branch
BranchTrueFalseTotal
if ($code{$type}) { } 0 80 80
146 0 { $attrs[$code{$type}] = $code;
147 }
148 else
149 80 { push @attrs, $type => $code;
150 80 $code{$type} = $#attrs;
151 }
152 }
153 54 $in->{attrs} = \@attrs;
154 }
155  
156 # doing this correctly is too complex for now
157 54 ▶ unshift @{$in->{attrs_any}}, @{$add->{attrs_any}} if $add->{attrs_any};
Branch: 1 branch
BranchTrueFalseTotal
if $add->{"attrs_any"} 54 0 54
158 54 $in;
159 }
160  
161 2500 ▶sub isTrue($) { $_[1] eq '1' || $_[1] eq 'true' }
Subroutine isTrue: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[1] eq 1 or $_[1] eq "true" 0 2500 2500
162  
163 # Find the namespace use details of a certain top-level element or
164 # attribute.
165 sub nsContext($)
166 2081 ▶{ my ($self, $def) = @_;
Subroutine nsContext: called CC=16 SCAR=30.2
Pod undocumented
167 2081 ▶ $def or return {};
Branch: 1 branch
BranchTrueFalseTotal
$def or return {} 2081 0 2081
168  
169 2081 my $tns = $def->{ns};
170  
171 # top elements are to be qualified unless there is no targetNamespace
172 2081 ▶ my %context = (tns => $tns, qual_top => ($tns ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
$tns ? : 2061 20 2081
173  
174 2081 my $el_qual = $def->{efd} eq 'qualified';
175 2081 ▶ if(exists $self->{elements_qualified})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"elements_qualified"}) 1843 238 2081
176 1843 ▶ { my $qual = $self->{elements_qualified} || 0;
Condition50%1/2
$self->{'elements_qualified'} || 0
l!l
18430
MC/DC0%0/1
$self->{'elements_qualified'} || 0
$self->{'elements_qualified'}
Truth table50%1/2
A
A= $self->{'elements_qualified'}
Aresult
11
00
177 1843 ▶ if($qual eq 'TOP')
Branch: 1 branch
BranchTrueFalseTotal
if ($qual eq 'TOP') { } 0 1843 1843
178 { $tns or error __x"application requires that element `{name}' has a targetNamespace"
179 0 ▶ , name => $def->{full};
Branch: 1 branch
BranchTrueFalseTotal
$tns or &error(&__x("application requires that element `{name}' has a targetNamespace", "name", $def->{"full"})) 0 0 0
180 }
181 else
182 1843 ▶ { $el_qual = $qual eq 'ALL' ? 1 : $qual eq 'NONE' ? 0 : $qual;
Branch: 2 branches
BranchTrueFalseTotal
$qual eq 'ALL' ? : 56 1787 1843
$qual eq 'NONE' ? : 1741 46 1787
183 }
184 1843 ▶ $context{qual_top} = 0 if $qual eq 'NONE';
Branch: 1 branch
BranchTrueFalseTotal
if $qual eq "NONE" 1741 102 1843
185 }
186 2081 $context{qual_elem} = $el_qual;
187  
188 2081 my $at_qual = $def->{afd} eq 'qualified';
189 2081 ▶ if(exists $self->{attributes_qualified})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"attributes_qualified"}) 22 2059 2081
190 22 ▶ { my $qual = $self->{attributes_qualified} || 0;
Condition50%1/2
$self->{'attributes_qualified'} || 0
l!l
220
MC/DC0%0/1
$self->{'attributes_qualified'} || 0
$self->{'attributes_qualified'}
Truth table50%1/2
A
A= $self->{'attributes_qualified'}
Aresult
11
00
191 22 ▶ if($qual eq 'TOP')
Branch: 1 branch
BranchTrueFalseTotal
if ($qual eq 'TOP') { } 0 22 22
192 0 ▶ { $tns or error __x"application requires that attibute `{name}' has a targetNamespace", name => $def->{full};
Branch: 1 branch
BranchTrueFalseTotal
$tns or &error(&__x("application requires that attibute `{name}' has a targetNamespace", "name", $def->{"full"})) 0 0 0
193 }
194 else
195 22 ▶ { $at_qual = $qual eq 'ALL' ? 1 : $qual eq 'NONE' ? 0 : $qual;
Branch: 2 branches
BranchTrueFalseTotal
$qual eq 'ALL' ? : 0 22 22
$qual eq 'NONE' ? : 0 22 22
196 }
197 }
198 2081 $context{qual_attr} = $at_qual;
199  
200 2081 \%context;
201 }
202  
203 5031 ▶sub namespaces() { $_[0]->{nss} }
Subroutine namespaces: called CC=1 SCAR=0.0
Pod undocumented
204  
205 sub topLevel($$;$)
206 779 ▶{ my ($self, $path, $fullname, $is_root) = @_;
Subroutine topLevel: called CC=10 SCAR=23.6
Pod undocumented
207  
208 # built-in types have to be handled differently.
209 my $internal = XML::Compile::Schema::Specs->builtInType(undef, $fullname
210 , sloppy_integers => $self->{sloppy_integers}
211 , sloppy_floats => $self->{sloppy_floats}
212 , json_friendly => $self->{json_friendly}
213 779 );
214  
215 779 ▶ if($internal)
Branch: 1 branch
BranchTrueFalseTotal
if ($internal) 2 777 779
216 { my $builtin = $self->makeBuiltin($fullname, undef
217 2 , $fullname, $internal, $self->{check_values});
218 my $builder = $self->actsAs('WRITER')
219 1 ▶ ? sub { $_[0]->createTextNode($builtin->(@_)) }
Subroutine __ANON__: called CC=1 SCAR=0.0
220 2 ▶ : $builtin;
Branch: 1 branch
BranchTrueFalseTotal
$self->actsAs('WRITER') ? : 1 1 2
221 2 return $self->makeElementWrapper($path, $builder);
222 }
223  
224 777 my $nss = $self->namespaces;
225 777 ▶ my $top = $nss->find(element => $fullname)
Branch: 2 branches
BranchTrueFalseTotal
my $top = $nss->find("element", $fullname) || $nss->find("attribute", $fullname) or &error(&__x(scalar($fullname eq $path ? &N__("cannot find element or attribute `{name}'") : &N__("cannot find element or attribute `{name}' at {where}")), "name", $fullname, "where", $path, "_class", "usage")) 777 0 777
$fullname eq $path ? : 0 0 0
Condition66%2/3
$nss->find('element', $fullname) || $nss->find('attribute', $fullname)
l!l&&r!l&&!r
76980
MC/DC0%0/2
$nss->find('element', $fullname) || $nss->find('attribute', $fullname)
$nss->find('element', $fullname) $nss->find('attribute', $fullname)
Truth table66%2/3
A || B
A= $nss->find('element', $fullname)B= $nss->find('attribute', $fullname)
ABresult
1X1
011
000
226 || $nss->find(attribute => $fullname)
227 or error __x(( $fullname eq $path
228 ? N__"cannot find element or attribute `{name}'"
229 : N__"cannot find element or attribute `{name}' at {where}"
230 ), name => $fullname, where => $path, _class => 'usage');
231  
232 # filter the nodes in the schema which are to be processed
233 777 my $node = $top->{node};
234 777 my $schemans = $node->namespaceURI;
235 my $tree = XML::Compile::Iterator->new($node, $path, sub
236 9135 ▶ { my $n = shift;
Subroutine __ANON__: called CC=3 SCAR=11.1
237 9135 ▶ $n->isa('XML::LibXML::Element')
Branch: 1 branch
BranchTrueFalseTotal
$n->isa("XML::LibXML::Element") and $n->namespaceURI eq $schemans and not $n->localName =~ /$ignore_elements/ 3344 5791 9135
Condition66%2/3
$n->isa("XML::LibXML::Element") and $n->namespaceURI eq $schemans
!ll&&!rl&&r
579103344
MC/DC50%1/2
$n->isa("XML::LibXML::Element") and $n->namespaceURI eq $schemans
$n->isa("XML::LibXML::Element") $n->namespaceURI eq $schemans
Truth table66%2/3
A and B
A= $n->isa("XML::LibXML::Element")B= $n->namespaceURI eq $schemans
ABresult
0X0
100
111
238 && $n->namespaceURI eq $schemans
239 && $n->localName !~ $ignore_elements
240 777 });
241  
242 777 delete $self->{_nest}; # reset recursion administration
243  
244 777 local $self->{_context} = $self->nsContext($top);
245 777 my $name = $node->localName;
246 777 my $data;
247 777 ▶ if($name eq 'element')
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'element') { } 769 8 777
elsif ($name eq 'attribute') { } 8 0 8
248 769 { my ($label, $make) = $self->element($tree, $is_root);
249 767 ▶ $data = $self->makeElementWrapper($path, $make) if $make;
Branch: 1 branch
BranchTrueFalseTotal
if $make 767 0 767
250 }
251 elsif($name eq 'attribute')
252 8 { my $make = $self->attribute($tree);
253 8 ▶ $data = $self->makeAttributeWrapper($path, $make) if $make;
Branch: 1 branch
BranchTrueFalseTotal
if $make 8 0 8
254 }
255 else
256 0 { error __x"top-level `{full}' is not an element or attribute but {name} at {where}"
257 , full => $fullname, name => $name, where => $tree->path
258 , _class => 'usage';
259 }
260  
261 775 $data;
262 }
263  
264 sub typeByName($$$)
265 1993 ▶{ my ($self, $where, $tree, $typename) = @_;
Subroutine typeByName: called CC=6 SCAR=18.1
Pod undocumented
266  
267 1993 my $node = $tree->node;
268  
269 #
270 # Try to detect a built-in type
271 #
272  
273 my $def = XML::Compile::Schema::Specs->builtInType($node, $typename
274 , sloppy_integers => $self->{sloppy_integers}
275 , sloppy_floats => $self->{sloppy_floats}
276 , json_friendly => $self->{json_friendly}
277 1993 );
278  
279 1993 ▶ if($def)
Branch: 1 branch
BranchTrueFalseTotal
if ($def) 1611 382 1993
280 { # Is built-in
281 1611 my $st = $self->makeBuiltin($where, $node, $typename, $def, $self->{check_values});
282  
283 1611 return +{ st => $st, is_list => $def->{is_list} };
284 }
285  
286 #
287 # not a schema standard type
288 #
289 382 ▶ my $top = $self->namespaces->find(complexType => $typename)
Branch: 1 branch
BranchTrueFalseTotal
my $top = $self->namespaces->find("complexType", $typename) || $self->namespaces->find("simpleType", $typename) or &error(&__x("cannot find type {type} at {where}", "type", $typename, "where", $where, "_class", "usage")) 382 0 382
Condition66%2/3
$self->namespaces->find('complexType', $typename) || $self->namespaces->find('simpleType', $typename)
l!l&&r!l&&!r
1931890
MC/DC0%0/2
$self->namespaces->find('complexType', $typename) || $self->namespaces->find('simpleType', $typename)
$self->namespaces->find('complexType', $typename) $self->namespaces->find('simpleType', $typename)
Truth table66%2/3
A || B
A= $self->namespaces->find('complexType', $typename)B= $self->namespaces->find('simpleType', $typename)
ABresult
1X1
011
000
290 || $self->namespaces->find(simpleType => $typename)
291 or error __x"cannot find type {type} at {where}"
292 , type => $typename, where => $where, _class => 'usage';
293  
294 382 local $self->{_context} = $self->nsContext($top);
295 382 my $typeimpl = $tree->descend($top->{node});
296  
297 382 my $typedef = $top->{type};
298 382 ▶ $typedef eq 'simpleType' ? $self->simpleType($typeimpl)
Branch: 2 branches
BranchTrueFalseTotal
$typedef eq 'simpleType' ? : 189 193 382
$typedef eq 'complexType' ? : 193 0 193
299 : $typedef eq 'complexType' ? $self->complexType($typeimpl)
300 : error __x"expecting simple- or complexType, not '{type}' at {where}"
301 , type => $typedef, where => $tree->path, _class => 'schema';
302 }
303  
304 sub simpleType($;$)
305 372 ▶{ my ($self, $tree, $in_list) = @_;
Subroutine simpleType: called CC=5 SCAR=16.2
Pod undocumented
306  
307 372 ▶ $tree->nrChildren==1
Branch: 1 branch
BranchTrueFalseTotal
$tree->nrChildren == 1 or &error(&__x("simpleType must have exactly one child at {where}", "where", $tree->path, "_class", "schema")) 372 0 372
308 or error __x"simpleType must have exactly one child at {where}"
309 , where => $tree->path, _class => 'schema';
310  
311 372 my $child = $tree->firstChild;
312 372 my $name = $child->localName;
313 372 my $nest = $tree->descend($child);
314  
315 # Full content:
316 # annotation?
317 # , (restriction | list | union)
318  
319 372 ▶ my $type
Branch: 3 branches
BranchTrueFalseTotal
$name eq 'restriction' ? : 279 93 372
$name eq 'list' ? : 56 37 93
$name eq 'union' ? : 37 0 37
320 = $name eq 'restriction' ? $self->simpleRestriction($nest, $in_list)
321 : $name eq 'list' ? $self->simpleList($nest)
322 : $name eq 'union' ? $self->simpleUnion($nest)
323 : error __x"simpleType contains '{local}', must be restriction, list, or union at {where}"
324 , local => $name, where => $tree->path, _class => 'schema';
325  
326 372 delete @$type{'attrs','attrs_any'}; # spec says ignore attrs
327 372 $type;
328 }
329  
330 sub simpleList($)
331 56 ▶{ my ($self, $tree) = @_;
Subroutine simpleList: called CC=7 SCAR=20.1
Pod undocumented
332  
333 # attributes: id, itemType = QName
334 # content: annotation?, simpleType?
335  
336 56 my $per_item;
337 56 my $node = $tree->node;
338 56 my $where = $tree->path . '#list';
339  
340 56 ▶ if(my $type = $node->getAttribute('itemType'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $node->getAttribute('itemType')) { } 40 16 56
341 40 ▶ { $tree->nrChildren==0
Branch: 1 branch
BranchTrueFalseTotal
$tree->nrChildren == 0 or &error(&__x("list with both itemType and content at {where}", "where", $where, "_class", "schema")) 40 0 40
342 or error __x"list with both itemType and content at {where}"
343 , where => $where, _class => 'schema';
344  
345 40 my $typename = $self->rel2abs($where, $node, $type);
346 40 ▶ $per_item = $self->blocked($where, simpleType => $typename)
Condition33%1/3
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
l!l&&r!l&&!r
0400
MC/DC0%0/2
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
$self->blocked($where, 'simpleType', $typename) $self->typeByName($where, $tree, $typename)
Truth table33%1/3
A || B
A= $self->blocked($where, 'simpleType', $typename)B= $self->typeByName($where, $tree, $typename)
ABresult
1X1
011
000
347 || $self->typeByName($where, $tree, $typename);
348 }
349 else
350 16 ▶ { $tree->nrChildren==1
Branch: 1 branch
BranchTrueFalseTotal
$tree->nrChildren == 1 or &error(&__x("list expects one simpleType child at {where}", "where", $where, "_class", "schema")) 16 0 16
351 or error __x"list expects one simpleType child at {where}"
352 , where => $where, _class => 'schema';
353  
354 16 ▶ $tree->currentLocal eq 'simpleType'
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentLocal eq "simpleType" or &error(&__x("list can only have a simpleType child at {where}", "where", $where, "_class", "schema")) 16 0 16
355 or error __x"list can only have a simpleType child at {where}"
356 , where => $where, _class => 'schema';
357  
358 16 $per_item = $self->simpleType($tree->descend, 1);
359 }
360  
361 my $st = $per_item->{st}
362 56 ▶ or panic "list did not produce a simple type at $where";
Branch: 1 branch
BranchTrueFalseTotal
my $st = $per_item->{"st"} or &panic("list did not produce a simple type at $where") 56 0 56
363  
364 56 $per_item->{st} = $self->makeList($where, $st);
365 56 $per_item->{is_list} = 1;
366 56 $per_item;
367 }
368  
369 sub simpleUnion($)
370 37 ▶{ my ($self, $tree) = @_;
Subroutine simpleUnion: called CC=7 SCAR=19.7
Pod undocumented
371  
372 # attributes: id, memberTypes = List of QName
373 # content: annotation?, simpleType*
374  
375 37 my $node = $tree->node;
376 37 my $where = $tree->path . '#union';
377  
378 # Normal error handling switched off, and check_values must be on
379 # When check_values is off, we may decide later to treat that as
380 # string, which is faster but not 100% safe, where int 2 may be
381 # formatted as float 1.999
382  
383 37 local $self->{check_values} = 1;
384  
385 37 my @types;
386 37 ▶ if(my $members = $node->getAttribute('memberTypes'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $members = $node->getAttribute("memberTypes")) 27 10 37
387 27 { foreach my $union (split " ", $members)
388 43 { my $typename = $self->rel2abs($where, $node, $union);
389 43 ▶ my $type = $self->blocked($where, simpleType => $typename)
Condition33%1/3
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
l!l&&r!l&&!r
0430
MC/DC0%0/2
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
$self->blocked($where, 'simpleType', $typename) $self->typeByName($where, $tree, $typename)
Truth table33%1/3
A || B
A= $self->blocked($where, 'simpleType', $typename)B= $self->typeByName($where, $tree, $typename)
ABresult
1X1
011
000
390 || $self->typeByName($where, $tree, $typename);
391 my $st = $type->{st}
392 43 ▶ or error __x"union only of simpleTypes, but {type} is complex at {where}"
Branch: 1 branch
BranchTrueFalseTotal
my $st = $type->{"st"} or &error(&__x("union only of simpleTypes, but {type} is complex at {where}", "type", $typename, "where", $where, "_class", "schema")) 43 0 43
393 , type => $typename, where => $where, _class => 'schema';
394  
395 43 push @types, $st;
396 }
397 }
398  
399 37 foreach my $child ($tree->childs)
400 39 { my $name = $child->localName;
401 39 ▶ $name eq 'simpleType'
Branch: 1 branch
BranchTrueFalseTotal
$name eq "simpleType" or &error(&__x("only simpleType's within union, found {local} at {where}", "local", $name, "where", $where, "_class", "schema")) 39 0 39
402 or error __x"only simpleType's within union, found {local} at {where}"
403 , local => $name, where => $where, _class => 'schema';
404  
405 39 my $ctype = $self->simpleType($tree->descend($child), 0);
406 39 push @types, $ctype->{st};
407 }
408  
409 37 my $do = $self->makeUnion($where, @types);
410 37 { st => $do, is_union => 1 };
411 }
412  
413 sub simpleRestriction($$)
414 279 ▶{ my ($self, $tree, $in_list) = @_;
Subroutine simpleRestriction: called CC=10 SCAR=31.1
Pod undocumented
415  
416 # attributes: id, base = QName
417 # content: annotation?, simpleType?, facet*
418  
419 279 my $node = $tree->node;
420 279 my $where = $tree->path . '#sres';
421  
422 279 my ($base, $typename);
423 279 ▶ if(my $basename = $node->getAttribute('base'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $basename = $node->getAttribute('base')) { } 279 0 279
424 279 { $typename = $self->rel2abs($where, $node, $basename);
425 279 ▶ $base = $self->blocked($where, simpleType => $typename)
Condition66%2/3
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
l!l&&r!l&&!r
22770
MC/DC0%0/2
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
$self->blocked($where, 'simpleType', $typename) $self->typeByName($where, $tree, $typename)
Truth table66%2/3
A || B
A= $self->blocked($where, 'simpleType', $typename)B= $self->typeByName($where, $tree, $typename)
ABresult
1X1
011
000
426 || $self->typeByName($where, $tree, $typename);
427 }
428 else
429 0 ▶ { my $simple = $tree->firstChild
Branch: 1 branch
BranchTrueFalseTotal
my $simple = $tree->firstChild or &error(&__x("no base in simple-restriction, so simpleType required at {where}", "where", $where, "_class", "schema")) 0 0 0
430 or error __x"no base in simple-restriction, so simpleType required at {where}"
431 , where => $where, _class => 'schema';
432  
433 0 ▶ $simple->localName eq 'simpleType'
Branch: 1 branch
BranchTrueFalseTotal
$simple->localName eq "simpleType" or &error(&__x("simpleType expected, because there is no base attribute at {where}", "where", $where, "_class", "schema")) 0 0 0
434 or error __x"simpleType expected, because there is no base attribute at {where}"
435 , where => $where, _class => 'schema';
436  
437 0 $base = $self->simpleType($tree->descend($simple, 'st'));
438  
439 0 ▶ if((my $r) = $simple->getChildrenByLocalName('restriction')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($r) = $simple->getChildrenByLocalName("restriction")) 0 0 0
440 # <simpleType><restriction><simpleType><restriction base=xxx></simpleType>@facets</simpleType>
441 0 my $basename = $r->getAttribute('base');
442 0 ▶ $typename = $self->rel2abs($where, $r, $basename) if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 0 0 0
443 }
444  
445 0 $tree->nextChild;
446 }
447  
448 my $st = $base->{st}
449 279 ▶ or error __x"simple-restriction is not a simpleType at {where}"
Branch: 1 branch
BranchTrueFalseTotal
my $st = $base->{"st"} or &error(&__x("simple-restriction is not a simpleType at {where}", "where", $where, "_class", "schema")) 279 0 279
450 , where => $where, _class => 'schema';
451  
452 my $do = $self->applySimpleFacets($tree, $st
453 279 ▶ , $in_list || $base->{is_list}, $typename);
Condition100%3/3
$in_list || $base->{'is_list'}
l!l&&r!l&&!r
1623240
MC/DC100%2/2
$in_list || $base->{'is_list'}
$in_list $base->{'is_list'}
Truth table100%3/3
A || B
A= $in_listB= $base->{'is_list'}
ABresult
1X1
011
000
454  
455 279 ▶ $tree->currentChild
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentChild and &error(&__x("elements left at tail at {where}", "where", $tree->path, "_class", "schema")) 0 279 279
456 and error __x"elements left at tail at {where}"
457 , where => $tree->path, _class => 'schema';
458  
459 279 +{ st => $do };
460 }
461  
462 # Early=lexical space, Late=value space
463 50 my %facets_early = map +($_ => 1), qw/whiteSpace pattern/;
464 #my %facets_late = map +($_ => 1), qw/totalDigits maxScale minScale enumeration
465 # maxInclusive maxExclusive minInclusive minExclusive fractionDigits
466 # length minLength maxLength/;
467  
468 50 my $qname_type = pack_type SCHEMA2001, 'QName';
469  
470 sub applySimpleFacets($$$$)
471 287 ▶{ my ($self, $tree, $st, $is_list, $type) = @_;
Subroutine applySimpleFacets: called CC=19 SCAR=29.5
Pod undocumented
472 287 my $nss = $self->{nss};
473  
474 # partial
475 # content: facet*
476 # facet = minExclusive | minInclusive | maxExclusive | maxInclusive
477 # | totalDigits | fractionDigits | maxScale | minScale | length
478 # | minLength | maxLength | enumeration | whiteSpace | pattern
479  
480 287 my $where = $tree->path . '#facet';
481 287 my (%facets, $is_qname);
482 287 ▶ for(my $child = $tree->currentChild; $child; $child = $tree->nextChild)
Branch: 1 branch
BranchTrueFalseTotal
if ($child) 280 279 559
483 280 { my $facet = $child->localName;
484 280 ▶ last if $facet =~ $attribute_defs;
Branch: 1 branch
BranchTrueFalseTotal
if $facet =~ /$attribute_defs/ 8 272 280
485  
486 272 my $value = $child->getAttribute('value');
487 272 ▶ defined $value
Branch: 1 branch
BranchTrueFalseTotal
defined $value or &error(&__x("no value for facet `{facet}' at {where}", "facet", $facet, "where", $where, "_class", "schema")) 272 0 272
488 or error __x"no value for facet `{facet}' at {where}"
489 , facet => $facet, where => $where, _class => 'schema';
490  
491 272 ▶ if($facet eq 'enumeration')
Branch: 3 branches
BranchTrueFalseTotal
if ($facet eq 'enumeration') { } 88 184 272
elsif ($facet eq 'pattern') { } 30 154 184
elsif (not exists $facets{$facet}) { } 154 0 154
492 88 ▶ { $is_qname = $nss->doesExtend($type, $qname_type)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $is_qname 62 26 88
493 unless defined $is_qname;
494  
495 88 ▶ if($is_qname)
Branch: 1 branch
BranchTrueFalseTotal
if ($is_qname) 10 78 88
496 { # rewrite prefixed values into "{ns}local"
497 10 ▶ my ($prefix, $local)
Branch: 1 branch
BranchTrueFalseTotal
$value =~ /\:/ ? : 10 0 10
498 = $value =~ m/\:/ ? split(/\:/, $value, 2) : ('', $value);
499 10 my $ns = $child->lookupNamespaceURI($prefix);
500 10 $value = pack_type $ns, $local;
501 10 $self->_registerNSprefix($prefix, $ns, 1);
502 }
503  
504 88 push @{$facets{enumeration}}, $value;
505 }
506 30 elsif($facet eq 'pattern') { push @{$facets{pattern}}, $value }
507 154 elsif(!exists $facets{$facet}) { $facets{$facet} = $value }
508 else
509 0 { error __x"facet `{facet}' defined twice at {where}"
510 , facet => $facet, where => $where, _class => 'schema';
511 }
512 }
513  
514 return $st
515 287 ▶ if $self->{ignore_facets} || !keys %facets;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ignore_facets"} or not keys %facets 77 210 287
Condition66%2/3
$self->{"ignore_facets"} or not keys %facets
l!l&&r!l&&!r
077210
MC/DC50%1/2
$self->{"ignore_facets"} or not keys %facets
$self->{"ignore_facets"} not keys %facets
Truth table66%2/3
A or not(B)
A= $self->{"ignore_facets"}B= not keys %facets
ABresult
1X1
011
000
516  
517 210 my %facets_info = %facets;
518  
519 #
520 # new facets overrule all of the base-class
521 #
522  
523 210 ▶ if(defined $facets{totalDigits} && defined $facets{fractionDigits})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $facets{"totalDigits"} and defined $facets{"fractionDigits"}) 3 207 210
Condition100%3/3
defined $facets{"totalDigits"} and defined $facets{"fractionDigits"}
!ll&&!rl&&r
181263
MC/DC100%2/2
defined $facets{"totalDigits"} and defined $facets{"fractionDigits"}
defined $facets{"totalDigits"} defined $facets{"fractionDigits"}
Truth table100%3/3
A and B
A= defined $facets{"totalDigits"}B= defined $facets{"fractionDigits"}
ABresult
0X0
100
111
524 3 { my $td = delete $facets{totalDigits};
525 3 my $fd = delete $facets{fractionDigits};
526 3 $facets{_totalFracDigits} = [$td, $fd];
527 }
528  
529 210 my (@early, @late);
530 210 ▶ my $action = $self->actsAs('WRITER') ? 'WRITER' : 'READER';
Branch: 1 branch
BranchTrueFalseTotal
$self->actsAs('WRITER') ? : 101 109 210
531 210 foreach my $facet (keys %facets)
532 { my $h = builtin_facet($where, $self, $facet
533 243 ▶ , $facets{$facet}, $is_list, $type, $nss, $action) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $h = &builtin_facet($where, $self, $facet, $facets{$facet}, $is_list, $type, $nss, $action) or next 241 2 243
534  
535 241 ▶ if($facets_early{$facet})
Branch: 1 branch
BranchTrueFalseTotal
if ($facets_early{$facet}) { } 34 207 241
536 34 { push @early, $h }
537 207 else { push @late, $h }
538 }
539  
540 $is_list
541 210 ▶ ? $self->makeFacetsList($where, $st, \%facets_info, \@early, \@late)
Branch: 1 branch
BranchTrueFalseTotal
$is_list ? : 23 187 210
542 : $self->makeFacets($where, $st, \%facets_info, \@early, \@late);
543 }
544  
545 sub element($;$)
546 1914 ▶{ my ($self, $tree, $is_root) = @_;
Subroutine element: called CC=59 SCAR=41.6
Pod undocumented
547  
548 # attributes: abstract, default, fixed, form, id, maxOccurs, minOccurs
549 # , name, nillable, ref, substitutionGroup, targetNamespace, type
550 # ignored: block, final, targetNamespace additional restrictions
551 # content: annotation?
552 # , (simpleType | complexType)?
553 # , (unique | key | keyref)*
554  
555 1914 my $node = $tree->node;
556 1914 my $parent = $node->parentNode;
557 1914 ▶ my $is_global= $parent
Condition83%5/6
$parent && $parent->isa('XML::LibXML::Element') && $parent->localname eq 'schema'
!ll&&!rl&&r
71031876
$parent and $parent->isa("XML::LibXML::Element")
!ll&&!rl&&r
071907
MC/DC66%2/3
$parent && $parent->isa('XML::LibXML::Element') && $parent->localname eq 'schema'
$parent $parent->isa("XML::LibXML::Element") $parent->localname eq 'schema'
Truth table75%3/4
A and B && C
A= $parentB= $parent->isa("XML::LibXML::Element")C= $parent->localname eq 'schema'
ABCresult
0XX0
10X0
1100
1111
558 && $parent->isa('XML::LibXML::Element')
559 && $parent->localname eq 'schema';
560  
561 1914 my $where = $tree->path;
562  
563 1914 ▶ my $name = $node->getAttribute('name')
Branch: 1 branch
BranchTrueFalseTotal
my $name = $node->getAttribute("name") or &error(&__x("element has no name nor ref at {where}", "where", $where, "_class", "schema")) 1914 0 1914
564 or error __x"element has no name nor ref at {where}"
565 , where => $where, _class => 'schema';
566 1914 $self->assertType($where, name => NCName => $name);
567  
568 # Full name based on current context. This might be a global name
569 # or a local name.
570  
571 1914 my $context = $self->{_context};
572  
573 # Determine the context of this element. When it is a global, we need
574 # to set-up a new context until end-of-function.
575  
576 1914 my $abstract = 0;
577 1914 my ($qual, $ns, $fullname);
578  
579 1914 ▶ if($is_global)
Branch: 1 branch
BranchTrueFalseTotal
if ($is_global) { } 876 1038 1914
580 876 ▶ { $ns = $node->getAttribute('targetNamespace')
Condition66%2/3
$node->getAttribute('targetNamespace') || $parent->getAttribute('targetNamespace')
l!l&&r!l&&!r
08688
MC/DC50%1/2
$node->getAttribute('targetNamespace') || $parent->getAttribute('targetNamespace')
$node->getAttribute('targetNamespace') $parent->getAttribute('targetNamespace')
Truth table66%2/3
A || B
A= $node->getAttribute('targetNamespace')B= $parent->getAttribute('targetNamespace')
ABresult
1X1
011
000
581 || $parent->getAttribute('targetNamespace');
582 876 $fullname= pack_type $ns, $name;
583 876 my $def = $self->namespaces->find(element => $fullname);
584 876 $context = $self->nsContext($def);
585 876 $qual = $context->{qual_top};
586  
587 # abstract elements are not to be used in messages.
588 876 ▶ $abstract = $self->{abstract_types} eq 'ACCEPT' ? 0 : $def->{abstract};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'abstract_types'} eq 'ACCEPT' ? : 0 876 876
589 }
590 else
591 1038 { $qual = $context->{qual_elem};
592 1038 ▶ $ns = $node->getAttribute('targetNamespace') || $context->{tns};
Condition66%2/3
$node->getAttribute('targetNamespace') || $context->{'tns'}
l!l&&r!l&&!r
010308
MC/DC50%1/2
$node->getAttribute('targetNamespace') || $context->{'tns'}
$node->getAttribute('targetNamespace') $context->{'tns'}
Truth table66%2/3
A || B
A= $node->getAttribute('targetNamespace')B= $context->{'tns'}
ABresult
1X1
011
000
593 1038 $fullname = pack_type $ns, $name;
594 }
595  
596 1914 ▶ if(my $form = $node->getAttribute('form'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $form = $node->getAttribute("form")) 8 1906 1914
597 8 ▶ { $qual
Branch: 2 branches
BranchTrueFalseTotal
$form eq 'qualified' ? : 4 4 8
$form eq 'unqualified' ? : 4 0 4
598 = $form eq 'qualified' ? 1
599 : $form eq 'unqualified' ? 0
600 : error __x"form must be (un)qualified, not `{form}' at {where}"
601 , form => $form, where => $where, _class => 'schema';
602 }
603  
604 1914 ▶ local $self->{_context} = $context if $is_global;
Branch: 1 branch
BranchTrueFalseTotal
if $is_global 876 1038 1914
605 1914 ▶ my $nodetype = $qual ? $fullname : $name;
Branch: 1 branch
BranchTrueFalseTotal
$qual ? : 247 1667 1914
606  
607 # SubstitionGroups
608 # We know the type of the message root, so do not need to look for
609 # alternative sgs (and it wouldn't work anyway)
610  
611 1914 my @sgs;
612 1914 ▶ @sgs = $self->namespaces->findSgMembers($node->localName, $fullname)
Branch: 1 branch
BranchTrueFalseTotal
unless $is_root 1105 809 1914
613 unless $is_root;
614  
615 # Handle re-usable fragments, fight against combinatorial explosions
616  
617 1914 my $nodeid = $node->unique_key; #$node->nodePath.'#'.$fullname;
618 1914 ▶ if(my $already = $self->{_created}{$nodeid})
Branch: 1 branch
BranchTrueFalseTotal
if (my $already = $self->{"_created"}{$nodeid}) 14 1900 1914
619 { # We cannot cache compile subst-group handlers, because sgs using
620 # elements which were already compiled into sgs does not work.
621 14 ▶ $already = $self->substitutionGroup($tree, $fullname, $nodetype
Branch: 1 branch
BranchTrueFalseTotal
if @sgs 0 14 14
622 , $already, \@sgs) if @sgs;
623 14 return ($nodetype, $already);
624 }
625  
626 # Detect recursion
627 # Very complicated: recursively nested structures. It is less of a
628 # problem when you handle in run-time what you see... but we here
629 # have to be prepared for everything.
630  
631 1900 ▶ if(exists $self->{_nest}{$nodeid})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_nest"}{$nodeid}) 12 1888 1900
632 12 { my $outer = \$self->{_nest}{$nodeid};
633 12 ▶ my $nested = sub { $$outer->(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
634  
635 # The code must be blessed in the right class, to be compiled
636 # correctly inside its parent.
637 12 ▶ bless $nested, 'BLOCK' if @sgs;
Branch: 1 branch
BranchTrueFalseTotal
if @sgs 0 12 12
638  
639 12 return ($nodetype, $nested);
640 }
641 1888 $self->{_nest}{$nodeid} = undef;
642  
643 # Construct XML tag to use
644  
645 1888 ▶ my $trans = $qual ? 'makeTagQualified' : 'makeTagUnqualified';
Branch: 1 branch
BranchTrueFalseTotal
$qual ? : 247 1641 1888
646 1888 my $tag = $self->$trans($where, $node, $name, $ns);
647  
648 # Construct type processor
649  
650 1888 my ($comptype, $comps);
651 1888 my $nr_childs = $tree->nrChildren;
652 1888 ▶ if(my $isa = $node->getAttribute('type'))
Branch: 3 branches
BranchTrueFalseTotal
if (my $isa = $node->getAttribute('type')) { } 1369 519 1888
elsif ($nr_childs == 0) { } 17 502 519
elsif ($nr_childs != 1) { } 0 502 502
653 { # explicitly names type
654 1369 ▶ $nr_childs==0
Branch: 1 branch
BranchTrueFalseTotal
$nr_childs == 0 or &error(&__x("no childs expected with attribute `type' at {where}", "where", $where, "_class", "schema")) 1369 0 1369
655 or error __x"no childs expected with attribute `type' at {where}", where => $where, _class => 'schema';
656  
657 1369 $comptype = $self->rel2abs($where, $node, $isa);
658 1369 ▶ $comps = $self->blocked($where, anyType => $comptype) || $self->typeByName($where, $tree, $comptype);
Condition66%2/3
$self->blocked($where, 'anyType', $comptype) || $self->typeByName($where, $tree, $comptype)
l!l&&r!l&&!r
1813510
MC/DC0%0/2
$self->blocked($where, 'anyType', $comptype) || $self->typeByName($where, $tree, $comptype)
$self->blocked($where, 'anyType', $comptype) $self->typeByName($where, $tree, $comptype)
Truth table66%2/3
A || B
A= $self->blocked($where, 'anyType', $comptype)B= $self->typeByName($where, $tree, $comptype)
ABresult
1X1
011
000
659 }
660 elsif($nr_childs==0)
661 { # default type for substGroups is type of base-class
662 17 my $base_node = $node;
663 17 local $self->{_context};
664 17 ▶ while(my $subst = $base_node->getAttribute('substitutionGroup'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $subst = $base_node->getAttribute("substitutionGroup")) 5 12 17
665 5 { my $subst_elem = $self->rel2abs($where, $base_node, $subst);
666 5 my $base_elem = $self->namespaces->find(element => $subst_elem);
667 5 $self->{_context} = $self->nsContext($base_elem);
668 5 $base_node = $base_elem->{node};
669 5 ▶ my $isa = $base_node->getAttribute('type')
Branch: 1 branch
BranchTrueFalseTotal
my $isa = $base_node->getAttribute("type") or next 5 0 5
670 or next;
671  
672 5 $comptype = $self->rel2abs($where, $base_node, $isa);
673 5 ▶ $comps = $self->blocked($where, complexType => $comptype) || $self->typeByName($where, $tree, $comptype);
Condition33%1/3
$self->blocked($where, 'complexType', $comptype) || $self->typeByName($where, $tree, $comptype)
l!l&&r!l&&!r
050
MC/DC0%0/2
$self->blocked($where, 'complexType', $comptype) || $self->typeByName($where, $tree, $comptype)
$self->blocked($where, 'complexType', $comptype) $self->typeByName($where, $tree, $comptype)
Truth table33%1/3
A || B
A= $self->blocked($where, 'complexType', $comptype)B= $self->typeByName($where, $tree, $comptype)
ABresult
1X1
011
000
674 5 last;
675 }
676 17 ▶ unless($comptype)
Branch: 1 branch
BranchTrueFalseTotal
unless ($comptype) 12 5 17
677 { # no type found, so anyType
678 12 $comptype = $self->anyType($node);
679 12 $comps = $self->typeByName($where, $tree, $comptype);
680 }
681 }
682 elsif($nr_childs!=1)
683 0 { error __x"expected is only one child node at {where}"
684 , where => $where, _class => 'schema';
685 }
686 else # nameless types
687 502 { my $child = $tree->firstChild;
688 502 my $local = $child->localname;
689 502 my $nest = $tree->descend($child);
690  
691 # Sometimes extension or restriction with base attribute required for hooks
692 502 my $ext = $nest->firstChild;
693 502 ▶ my $base = $ext ? $ext->getAttribute('base') : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ext ? : 490 12 502
694 502 ▶ my $basex = $base ? $self->rel2abs($where, $ext, $base) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$base ? : 104 398 502
695  
696 502 ▶ ($comps, $comptype)
Branch: 2 branches
BranchTrueFalseTotal
$local eq 'simpleType' ? : 117 385 502
$local eq 'complexType' ? : 385 0 385
Condition75%3/4
$basex // "unnamed simple"
l!l
10413
$basex // "unnamed complex"
l!l
0383
MC/DC100%1/1
$basex // "unnamed simple"
$basex
MC/DC0%0/1
$basex // "unnamed complex"
$basex
Truth table100%2/2
A
A= $basex
Aresult
11
00
Truth table50%1/2
A
A= $basex
Aresult
11
00
697 = $local eq 'simpleType'
698 ? ($self->simpleType($nest, 0), $basex // 'unnamed simple')
699 : $local eq 'complexType'
700 ? ($self->complexType($nest), $basex // 'unnamed complex')
701 : error __x"illegal element child `{name}' at {where}", name => $local, where => $where, _class => 'schema';
702 }
703  
704 my ($st, $elems, $attrs, $attrs_any)
705 1886 = @$comps{ qw/st elems attrs attrs_any/ };
706 1886 ▶ $_ ||= [] for $elems, $attrs, $attrs_any;
Condition100%2/2
$_ ||= []
l!l
16544004
MC/DC100%1/1
$_ ||= []
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
707  
708 # Construct basic element handler
709  
710 1886 my $is_simple = defined $st;
711 1886 ▶ my $nillable = $self->isTrue($node->getAttribute('nillable') || 'false');
Condition100%2/2
$node->getAttribute('nillable') || 'false'
l!l
441842
MC/DC100%1/1
$node->getAttribute('nillable') || 'false'
$node->getAttribute('nillable')
Truth table100%2/2
A
A= $node->getAttribute('nillable')
Aresult
11
00
712  
713 my $elem_handler
714 1886 ▶ = $comps->{mixed} ? 'makeMixedElement'
Branch: 3 branches
BranchTrueFalseTotal
$comps->{'mixed'} ? : 8 1878 1886
!$is_simple ? : 546 1332 1878
@$attrs || @$attrs_any ? : 20 1312 1332
Condition66%2/3
@$attrs or @$attrs_any
l!l&&r!l&&!r
2001312
MC/DC50%1/2
@$attrs or @$attrs_any
@$attrs @$attrs_any
Truth table66%2/3
A or B
A= @$attrsB= @$attrs_any
ABresult
1X1
011
000
715 : ! $is_simple ? 'makeComplexElement' # other complexType
716 : (@$attrs || @$attrs_any) ? 'makeTaggedElement' # complex/simpleContent
717 : 'makeSimpleElement';
718  
719 1886 ▶ my $r = $self->$elem_handler
Condition66%2/3
$st || $elems
l!l&&r!l&&!r
13325540
MC/DC0%0/2
$st || $elems
$st $elems
Truth table66%2/3
A || B
A= $stB= $elems
ABresult
1X1
011
000
720 ( $where, $tag, ($st||$elems), $attrs, $attrs_any, $comptype, $nillable);
721  
722 # Add defaults and stuff
723 1886 my $default = $node->getAttributeNode('default');
724 1886 my $fixed = $node->getAttributeNode('fixed');
725  
726 1886 ▶ $default && $fixed
Branch: 1 branch
BranchTrueFalseTotal
$default and $fixed and &error(&__x("element can not have default and fixed at {where}", "where", $tree->path, "_class", "schema")) 0 1886 1886
Condition66%2/3
$default and $fixed
!ll&&!rl&&r
1849370
MC/DC0%0/2
$default and $fixed
$default $fixed
Truth table66%2/3
A and B
A= $defaultB= $fixed
ABresult
0X0
100
111
727 and error __x"element can not have default and fixed at {where}", where => $tree->path, _class => 'schema';
728  
729 1886 ▶ my $value
Branch: 2 branches
BranchTrueFalseTotal
$default ? : 37 1849 1886
$fixed ? : 7 1842 1849
730 = $default ? $default->textContent
731 : $fixed ? $fixed->textContent
732 : undef;
733  
734 1886 ▶ my $generate
Branch: 3 branches
BranchTrueFalseTotal
$abstract ? : 20 1866 1886
$default ? : 37 1829 1866
$fixed ? : 7 1822 1829
735 = $abstract ? 'makeElementAbstract'
736 : $default ? 'makeElementDefault'
737 : $fixed ? 'makeElementFixed'
738 : 'makeElement';
739  
740 1886 my $do = $self->$generate($where, $ns, $nodetype, $r, $value, $tag);
741  
742 # hrefs are used by SOAP-RPC
743 $do = $self->makeElementHref($where, $ns, $nodetype, $do)
744 1886 ▶ if $self->{permit_href} && $self->actsAs('READER');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"permit_href"} and $self->actsAs("READER") 0 1886 1886
Condition33%1/3
$self->{"permit_href"} and $self->actsAs("READER")
!ll&&!rl&&r
188600
MC/DC0%0/2
$self->{"permit_href"} and $self->actsAs("READER")
$self->{"permit_href"} $self->actsAs("READER")
Truth table33%1/3
A and B
A= $self->{"permit_href"}B= $self->actsAs("READER")
ABresult
0X0
100
111
745  
746 # Implement hooks
747 1886 my ($before, $replace, $after) = $self->findHooks($where, $comptype, $node);
748  
749 1886 ▶ $do = $self->makeHook($where, $do, $tag, $before, $replace, $after, $comptype)
Branch: 1 branch
BranchTrueFalseTotal
if $before or $replace or $after 23 1863 1886
Condition100%6/6
$before or $replace or $after
l!l&&r!l&&!r
1491863
$before or $replace
l!l&&r!l&&!r
951872
MC/DC100%3/3
$before or $replace or $after
$before $replace $after
Truth table100%4/4
A or B or C
A= $beforeB= $replaceC= $after
ABCresult
1XX1
01X1
0011
0000
750 if $before || $replace || $after;
751  
752 $do = $self->xsiType($tree, $node, $name, $comptype, $do)
753 1886 ▶ if $comptype && $self->{xsi_type}{$comptype};
Branch: 1 branch
BranchTrueFalseTotal
if $comptype and $self->{"xsi_type"}{$comptype} 7 1879 1886
Condition66%2/3
$comptype and $self->{"xsi_type"}{$comptype}
!ll&&!rl&&r
018797
MC/DC50%1/2
$comptype and $self->{"xsi_type"}{$comptype}
$comptype $self->{"xsi_type"}{$comptype}
Truth table66%2/3
A and B
A= $comptypeB= $self->{"xsi_type"}{$comptype}
ABresult
0X0
100
111
754  
755 $do = $self->addTypeAttribute($comptype, $do)
756 1886 ▶ if $self->{xsi_type_everywhere} && $comptype !~ /^unnamed /;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"xsi_type_everywhere"} and not $comptype =~ /^unnamed / 1 1885 1886
Condition100%3/3
$self->{"xsi_type_everywhere"} and not $comptype =~ /^unnamed /
!ll&&!rl&&r
188411
MC/DC100%2/2
$self->{"xsi_type_everywhere"} and not $comptype =~ /^unnamed /
$self->{"xsi_type_everywhere"} not $comptype =~ /^unnamed /
Truth table100%3/3
A and not(B)
A= $self->{"xsi_type_everywhere"}B= not $comptype =~ /^unnamed /
ABresult
0X0
100
111
757  
758 1886 $self->{_created}{$nodeid} = $do;
759  
760 1886 ▶ $do = $self->substitutionGroup($tree, $fullname, $nodetype, $do, \@sgs)
Branch: 1 branch
BranchTrueFalseTotal
if @sgs 21 1865 1886
761 if @sgs;
762  
763 # handle recursion
764 # this must look very silly to you... however, this is resolving
765 # recursive schemas: this way nested use of the same element
766 # definition will catch the code reference of the outer definition.
767 1886 $self->{_nest}{$nodeid} = $do;
768 1886 delete $self->{_nest}{$nodeid}; # clean the outer definition
769  
770 1886 ($nodetype, $do);
771 }
772  
773 sub particle($)
774 1732 ▶{ my ($self, $tree) = @_;
Subroutine particle: called CC=23 SCAR=31.4
Pod undocumented
775  
776 1732 my $node = $tree->node;
777 1732 my $local = $node->localName;
778 1732 my $where = $tree->path;
779  
780 1732 my $min = $node->getAttribute('minOccurs');
781 1732 my $max = $node->getAttribute('maxOccurs');
782  
783 1732 ▶ unless(defined $min)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $min) 1470 262 1732
784 1470 ▶ { $min = ($self->actsAs('WRITER') || $self->{default_values} ne 'EXTEND')
Branch: 1 branch
BranchTrueFalseTotal
($self->actsAs('WRITER') || $self->{'default_values'} ne 'EXTEND') && ($node->getAttribute('default') || $node->getAttribute('fixed')) ? : 26 1444 1470
Condition100%9/9
$self->actsAs("WRITER") || $self->{"default_values"} ne "EXTEND" and $node->getAttribute("default") || $node->getAttribute("fixed")
!ll&&!rl&&r
79564926
$self->actsAs("WRITER") or $self->{"default_values"} ne "EXTEND"
l!l&&r!l&&!r
66312795
$node->getAttribute("default") or $node->getAttribute("fixed")
l!l&&r!l&&!r
224649
MC/DC100%4/4
$self->actsAs("WRITER") || $self->{"default_values"} ne "EXTEND" and $node->getAttribute("default") || $node->getAttribute("fixed")
$self->actsAs("WRITER") $self->{"default_values"} ne "EXTEND" $node->getAttribute("default") $node->getAttribute("fixed")
Truth table85%6/7
A or B and C or D
A= $self->actsAs("WRITER")B= $self->{"default_values"} ne "EXTEND"C= $node->getAttribute("default")D= $node->getAttribute("fixed")
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
785 && ($node->getAttribute('default') || $node->getAttribute('fixed'))
786 ? 0 : 1;
787 }
788  
789 $min = 0 if $self->{interpret_nillable_as_optional}
790 1732 ▶ && $self->isTrue($node->getAttribute('nillable') || 'false');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"interpret_nillable_as_optional"} and $self->isTrue($node->getAttribute("nillable") || "false") 2 1730 1732
Condition100%5/5
$self->{"interpret_nillable_as_optional"} and $self->isTrue($node->getAttribute("nillable") || "false")
!ll&&!rl&&r
172462
$node->getAttribute('nillable') || 'false'
l!l
26
MC/DC100%2/2
$self->{"interpret_nillable_as_optional"} and $self->isTrue($node->getAttribute("nillable") || "false")
$self->{"interpret_nillable_as_optional"} $self->isTrue($node->getAttribute("nillable") || "false")
MC/DC100%1/1
$node->getAttribute('nillable') || 'false'
$node->getAttribute('nillable')
Truth table100%3/3
A and B
A= $self->{"interpret_nillable_as_optional"}B= $self->isTrue($node->getAttribute("nillable") || "false")
ABresult
0X0
100
111
Truth table100%2/2
A
A= $node->getAttribute('nillable')
Aresult
11
00
791  
792 # default attribute in writer means optional, but we want to see
793 # them in the reader, to see the value.
794
795 1732 ▶ defined $max or $max = 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $max or $max = 1 144 1588 1732
796 $max = 'unbounded'
797 1732 ▶ if $max ne 'unbounded' && $max > 1 && !$self->{check_occurs};
Branch: 1 branch
BranchTrueFalseTotal
if $max ne "unbounded" and $max > 1 and not $self->{"check_occurs"} 6 1726 1732
Condition100%6/6
$max ne "unbounded" and $max > 1 and not $self->{"check_occurs"}
!ll&&!rl&&r
1665616
$max ne "unbounded" and $max > 1
!ll&&!rl&&r
75159067
MC/DC100%3/3
$max ne "unbounded" and $max > 1 and not $self->{"check_occurs"}
$max ne "unbounded" $max > 1 not $self->{"check_occurs"}
Truth table100%4/4
A and B and not(C)
A= $max ne "unbounded"B= $max > 1C= not $self->{"check_occurs"}
ABCresult
0XX0
10X0
1100
1111
798  
799 $min = 0
800 1732 ▶ if $max eq 'unbounded' && !$self->{check_occurs};
Branch: 1 branch
BranchTrueFalseTotal
if $max eq "unbounded" and not $self->{"check_occurs"} 8 1724 1732
Condition100%3/3
$max eq "unbounded" and not $self->{"check_occurs"}
!ll&&!rl&&r
1651738
MC/DC100%2/2
$max eq "unbounded" and not $self->{"check_occurs"}
$max eq "unbounded" not $self->{"check_occurs"}
Truth table100%3/3
A and not(B)
A= $max eq "unbounded"B= not $self->{"check_occurs"}
ABresult
0X0
100
111
801  
802 1732 ▶ return $self->anyElement($tree, $min, $max)
Branch: 1 branch
BranchTrueFalseTotal
if $local eq "any" 10 1722 1732
803 if $local eq 'any';
804  
805 1722 ▶ my ($label, $process)
Branch: 3 branches
BranchTrueFalseTotal
$local eq 'element' ? : 1110 612 1722
$local eq 'group' ? : 20 592 612
$local =~ /$particle_blocks/ ? : 592 0 592
806 = $local eq 'element' ? $self->particleElement($tree)
807 : $local eq 'group' ? $self->particleGroup($tree)
808 : $local =~ $particle_blocks ? $self->particleBlock($tree)
809 : error __x"unknown particle type '{name}' at {where}"
810 , name => $local, where => $tree->path, _class => 'schema';
811  
812 1722 ▶ defined $label
Branch: 1 branch
BranchTrueFalseTotal
defined $label or return () 1706 16 1722
813 or return ();
814  
815 1706 ▶ if(ref $process eq 'BLOCK')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $process eq "BLOCK") 627 1079 1706
816 627 { my $key = $self->keyRewrite($label);
817 627 my $multi = $self->blockLabel($local, $key);
818 627 return $self->makeBlockHandler($where, $label, $min, $max
819 , $process, $local, $multi);
820 }
821  
822 # only elements left
823 1079 my $required;
824 1079 my $key = $self->keyRewrite($label);
825 1079 ▶ $required = $self->makeRequired($where, $key, $process) if $min!=0;
Branch: 1 branch
BranchTrueFalseTotal
if $min != 0 871 208 1079
826  
827 1079 ▶ ($self->actsAs('READER') ? $label : $key) =>
Branch: 1 branch
BranchTrueFalseTotal
$self->actsAs('READER') ? : 587 492 1079
828 $self->makeElementHandler($where, $key, $min,$max, $required, $process);
829 }
830  
831 sub particleElement($)
832 1110 ▶{ my ($self, $tree) = @_;
Subroutine particleElement: called CC=4 SCAR=13.9
Pod undocumented
833  
834 1110 my $node = $tree->node;
835 1110 ▶ if(my $ref = $node->getAttribute('ref'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $node->getAttribute("ref")) 79 1031 1110
836 79 { my $where = $tree->path . "/$ref";
837 79 my $refname = $self->rel2abs($tree, $node, $ref);
838 79 ▶ return () if $self->blocked($where, ref => $refname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->blocked($where, "ref", $refname) 12 67 79
839  
840 67 ▶ my $def = $self->namespaces->find(element => $refname)
Branch: 1 branch
BranchTrueFalseTotal
my $def = $self->namespaces->find("element", $refname) or &error(&__x("cannot find ref element '{name}' at {where}", "name", $refname, "where", $where, "_class", "schema")) 67 0 67
841 or error __x"cannot find ref element '{name}' at {where}"
842 , name => $refname, where => $where, _class => 'schema';
843  
844 return $self->element($tree->descend($def->{node}
845 67 , $self->prefixed($refname, 1)));
846 }
847  
848 1031 my $name = $node->getAttribute('name');
849 1031 $self->element($tree->descend($node, $name));
850 }
851  
852 # blockLabel KIND, LABEL
853 # Particle blocks, like `sequence' and `choice', which have a maxOccurs
854 # (maximum occurrence) which is 2 of more, are represented by an ARRAY
855 # of HASHs. The label with such a block is derived from its first element.
856 # This function determines how.
857 # seq_address sequence get seq_ prepended
858 # cho_gender choices get cho_ before them
859 # all_money an all block can also be repreated in spec >1.1
860 # gr_people group refers to a block of above type, but
861 # that type is not reflected in the name
862  
863 50 my %block_abbrev = qw/sequence seq_ choice cho_ all all_ group gr_/;
864 sub blockLabel($$)
865 627 ▶{ my ($self, $kind, $label) = @_;
Subroutine blockLabel: called CC=2 SCAR=6.9
Pod undocumented
866 627 ▶ return $label if $kind eq 'element';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "element" 19 608 627
867  
868 608 $label =~ s/^(?:seq|cho|all|gr)_//;
869 608 $block_abbrev{$kind} . (unpack_type $label)[1];
870 }
871  
872 sub particleGroup($)
873 20 ▶{ my ($self, $tree) = @_;
Subroutine particleGroup: called CC=8 SCAR=21.9
Pod undocumented
874  
875 # attributes: id, maxOccurs, minOccurs, name, ref
876 # content: annotation?, (all|choice|sequence)?
877 # apparently, a group can not refer to a group... well..
878  
879 20 my $node = $tree->node;
880 20 ▶ my $ref = $node->getAttribute('ref')
Branch: 1 branch
BranchTrueFalseTotal
my $ref = $node->getAttribute("ref") or &error(&__x("group without ref at {where}", "where", $tree->path, "_class", "schema")) 20 0 20
881 or error __x"group without ref at {where}"
882 , where => $tree->path, _class => 'schema';
883  
884 20 my $where = $tree->path . '#' . $ref;
885  
886 20 my $typename = $self->rel2abs($where, $node, $ref);
887 20 ▶ if(my $blocked = $self->blocked($where, ref => $typename))
Branch: 1 branch
BranchTrueFalseTotal
if (my $blocked = $self->blocked($where, "ref", $typename)) 0 20 20
888 0 { return ($typename, $blocked);
889 }
890  
891 20 ▶ my $dest = $self->namespaces->find(group => $typename)
Branch: 1 branch
BranchTrueFalseTotal
my $dest = $self->namespaces->find("group", $typename) or &error(&__x("cannot find group `{name}' at {where}", "name", $typename, "where", $where, "_class", "schema")) 20 0 20
892 or error __x"cannot find group `{name}' at {where}", name => $typename, where => $where, _class => 'schema';
893  
894 20 my $group = $tree->descend($dest->{node}, $self->prefixed($typename, 1));
895 20 ▶ return () if $group->nrChildren==0;
Branch: 1 branch
BranchTrueFalseTotal
if $group->nrChildren == 0 0 20 20
896  
897 20 ▶ $group->nrChildren==1
Branch: 1 branch
BranchTrueFalseTotal
$group->nrChildren == 1 or &error(&__x("only one particle block expected in group `{name}' at {where}", "name", $typename, "where", $where, "_class", "schema")) 20 0 20
898 or error __x"only one particle block expected in group `{name}' at {where}", name => $typename, where => $where, _class => 'schema';
899  
900 20 my $local = $group->currentLocal;
901 20 ▶ $local =~ m/^(?:all|choice|sequence)$/
Branch: 1 branch
BranchTrueFalseTotal
$local =~ /^(?:all|choice|sequence)$/ or &error(&__x("illegal group member `{name}' at {where}", "name", $local, "where", $where, "_class", "schema")) 20 0 20
902 or error __x"illegal group member `{name}' at {where}", name => $local, where => $where, _class => 'schema';
903  
904 20 my ($blocklabel, $code) = $self->particleBlock($group->descend);
905 20 ▶ $code ? ($typename, $code) : ();
Branch: 1 branch
BranchTrueFalseTotal
$code ? : 18 2 20
906 }
907  
908 sub particleBlock($)
909 612 ▶{ my ($self, $tree) = @_;
Subroutine particleBlock: called CC=2 SCAR=6.9
Pod undocumented
910  
911 612 my $node = $tree->node;
912 612 my @pairs = map $self->particle($tree->descend($_)), $tree->childs;
913 612 ▶ @pairs or return ();
Branch: 1 branch
BranchTrueFalseTotal
@pairs or return () 608 4 612
914  
915 # label is name of first component, only needed when maxOcc > 1
916 608 my $label = $pairs[0];
917 608 my $blocktype = $node->localName;
918  
919 608 my $call = 'make'.ucfirst $blocktype;
920 608 ($label => $self->$call($tree->path, @pairs));
921 }
922  
923 sub xsiType($$$$$)
924 7 ▶{ my ($self, $tree, $node, $name, $type, $base) = @_;
Subroutine xsiType: called CC=5 SCAR=16.1
Pod undocumented
925  
926 7 my %alt = ($type => $base);
927  
928 7 foreach my $alttype (@{$self->{xsi_type}{$type}})
929 11 ▶ { next if $alttype eq $type;
Branch: 1 branch
BranchTrueFalseTotal
if $alttype eq $type 4 7 11
930  
931 7 my ($ns, $local) = unpack_type $alttype;
932 7 my $prefix = $node->lookupNamespacePrefix($ns);
933 7 ▶ defined $prefix
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix or $prefix = $self->_registerNSprefix(undef, $ns, 1) 7 0 7
934 or $prefix = $self->_registerNSprefix(undef, $ns, 1);
935  
936 7 ▶ my $type = length $prefix ? "$prefix:$local" : $local;
Branch: 1 branch
BranchTrueFalseTotal
length $prefix ? : 7 0 7
937  
938 # do not accidentally use the default namespace, when there
939 # may also be namespace-less types used.
940 7 my $doc = $node->ownerDocument;
941 7 my $altnode = $doc->createElement('element');
942 7 $altnode->setNamespace(SCHEMA2001, 'temp1234', 1);
943 7 $altnode->setNamespace($ns, $prefix);
944 7 $altnode->setAttribute(name => $name);
945 7 $altnode->setAttribute(type => $type);
946  
947 7 delete $self->{_created}{$altnode->unique_key}; # clean nesting cache
948 7 (undef, $alt{$alttype}) = $self->element($tree->descend($altnode));
949 }
950 7 $self->makeXsiTypeSwitch($tree->path, $name, $type, \%alt);
951 }
952  
953 sub substitutionGroup($$$$$)
954 21 ▶{ my ($self, $tree, $fullname, $label, $base, $sgs) = @_;
Subroutine substitutionGroup: called CC=5 SCAR=19.8
Pod undocumented
955  
956 21 ▶ if(Log::Report->needs('TRACE')) # dump table of substgroup alternatives
Branch: 1 branch
BranchTrueFalseTotal
if ("Log::Report"->needs("TRACE")) 0 21 21
957 0 { my $labelrw = $self->keyRewrite($label);
958 0 my @full = sort map $_->{full}, @$sgs;
959 0 my $longest = max map length, @full;
960 0 my @c = map sprintf("%-${longest}s %s",$_,$self->keyRewrite($_)), @full;
961 0 local $" = "\n ";
962 0 trace "substitutionGroup $fullname$\"BASE=$label ($labelrw)$\"@c";
963 }
964  
965 21 my @elems;
966 21 ▶ push @elems, $label => [$self->keyRewrite($label), $base] if $base;
Branch: 1 branch
BranchTrueFalseTotal
if $base 21 0 21
967  
968 21 foreach my $subst (@$sgs)
969 40 { my ($l, $d) = $self->element($tree->descend($subst->{node}), 1);
970 40 ▶ push @elems, $l => [$self->keyRewrite($l), $d] if defined $d;
Branch: 1 branch
BranchTrueFalseTotal
if defined $d 40 0 40
971 }
972  
973 21 $self->makeSubstgroup($tree->path.'#subst', $fullname, @elems);
974 }
975  
976 sub keyRewrite($;$)
977 2111 ▶{ my $self = shift;
Subroutine keyRewrite: called CC=16 SCAR=31.4
Pod undocumented
978 2111 ▶ my ($ns, $key) = @_==1 ? unpack_type($_[0]) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 1767 344 2111
979 2111 my $oldkey = $key;
980  
981 2111 foreach my $r ( @{$self->{rewrite}} )
982 115 ▶ { if(ref $r eq 'HASH')
Branch: 6 branches
BranchTrueFalseTotal
if (ref $r eq 'HASH') { } 14 101 115
elsif (ref $r eq 'CODE') { } 51 50 101
elsif ($r eq 'UNDERSCORES') { } 0 50 50
elsif ($r eq 'SIMPLIFIED') { } 21 29 50
elsif ($r eq 'PREFIXED') { } 29 0 29
elsif ($r =~ /^PREFIXED\(\s*(.*?)\s*\)$/) { } 0 0 0
983 14 { my $full = pack_type $ns, $key;
984 14 ▶ $key = $r->{$full} if defined $r->{$full};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{$full} 4 10 14
985 14 ▶ $key = $r->{$key} if defined $r->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{$key} 0 14 14
986 }
987 elsif(ref $r eq 'CODE')
988 51 { $key = $r->($ns, $key);
989 }
990 elsif($r eq 'UNDERSCORES')
991 0 { $key =~ s/-/_/g;
992 }
993 elsif($r eq 'SIMPLIFIED')
994 21 { $key =~ s/-/_/g;
995 21 $key =~ s/\W//g;
996 21 $key = lc $key;
997 }
998 elsif($r eq 'PREFIXED')
999 29 { my $p = $self->{prefixes};
1000 29 ▶ my $prefix = $p->{$ns} ? $p->{$ns}{prefix} : '';
Branch: 1 branch
BranchTrueFalseTotal
$p->{$ns} ? : 25 4 29
1001 29 ▶ $key = $prefix . '_' . $key if $prefix ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $prefix ne "" 17 12 29
1002 }
1003 elsif($r =~ m/^PREFIXED\(\s*(.*?)\s*\)$/)
1004 0 { my @l = split /\s*\,\s*/, $1;
1005 0 my $p = $self->{prefixes};
1006 0 ▶ my $prefix = $p->{$ns} ? $p->{$ns}{prefix} : '';
Branch: 1 branch
BranchTrueFalseTotal
$p->{$ns} ? : 0 0 0
1007 0 ▶ $key = $prefix . '_' . $key if grep {$prefix eq $_} @l;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$prefix eq $_;} @l 0 0 0
1008 }
1009 else
1010 0 { error __x"key rewrite `{got}' not understood", got => $r;
1011 }
1012 }
1013  
1014 2111 ▶ trace "rewrote type @_ to $key"
Branch: 1 branch
BranchTrueFalseTotal
if $key ne $oldkey 69 2042 2111
1015 if $key ne $oldkey;
1016  
1017 2111 $key;
1018 }
1019  
1020 sub prefixed($;$)
1021 1004 ▶{ my ($self, $qname, $hide_use) = @_;
Subroutine prefixed: called CC=5 SCAR=16.1
Pod undocumented
1022 # hide_use = do not cause inclusion in output prefix table
1023  
1024 1004 my ($ns, $local) = unpack_type $qname;
1025 1004 ▶ defined $ns or return $qname;
Branch: 1 branch
BranchTrueFalseTotal
defined $ns or return $qname 1004 0 1004
1026  
1027 1004 ▶ my $pn = $self->{prefixes}{$ns} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $pn = $self->{"prefixes"}{$ns} or return 269 735 1004
1028 269 ▶ $pn->{used}++ unless $hide_use;
Branch: 1 branch
BranchTrueFalseTotal
unless $hide_use 138 131 269
1029 269 ▶ length $pn->{prefix} ? "$pn->{prefix}:$local" : $local;
Branch: 1 branch
BranchTrueFalseTotal
length $pn->{'prefix'} ? : 233 36 269
1030 }
1031  
1032 sub prefixForNamespace($)
1033 0 ▶{ my ($self, $ns) = @_;
Subroutine prefixForNamespace: not called CC=2 SCAR=17.9
Pod undocumented
1034 0 ▶ my $def = $self->{prefixes}{$ns} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $def = $self->{"prefixes"}{$ns} or return 0 0 0
1035 0 $def->{prefix};
1036 }
1037  
1038 sub attribute($)
1039 261 ▶{ my ($self, $tree) = @_;
Subroutine attribute: called CC=29 SCAR=34.9
Pod undocumented
1040  
1041 # attributes: default, fixed, form, id, name, ref, type, use
1042 # content: annotation?, simpleType?
1043  
1044 261 my $node = $tree->node;
1045 261 my $parent = $node->parentNode;
1046 261 ▶ my $is_global= $parent && $parent->localname eq 'schema';
Condition66%2/3
$parent && $parent->localname eq 'schema'
!ll&&!rl&&r
024813
MC/DC50%1/2
$parent && $parent->localname eq 'schema'
$parent $parent->localname eq 'schema'
Truth table66%2/3
A && B
A= $parentB= $parent->localname eq 'schema'
ABresult
0X0
100
111
1047 261 my $where = $tree->path;
1048  
1049 261 my $context = $self->{_context};
1050  
1051 261 ▶ if(my $refattr = $node->getAttribute('ref'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $refattr = $node->getAttribute("ref")) 5 256 261
1052 {
1053 5 my $refname = $self->rel2abs($tree, $node, $refattr);
1054 5 ▶ return () if $self->blocked($where, ref => $refname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->blocked($where, "ref", $refname) 0 5 5
1055  
1056 5 ▶ my $def = $self->namespaces->find(attribute => $refname)
Branch: 1 branch
BranchTrueFalseTotal
my $def = $self->namespaces->find("attribute", $refname) or &error(&__x("cannot find attribute {name} at {where}", "name", $refname, "where", $where, "_class", "schema")) 5 0 5
1057 or error __x"cannot find attribute {name} at {where}"
1058 , name => $refname, where => $where, _class => 'schema';
1059  
1060 5 local $self->{_context} = $def;
1061 5 return $self->attribute($tree->descend($def->{node}));
1062 }
1063  
1064 # Not a ref to attribute
1065 256 ▶ my $name = $node->getAttribute('name')
Branch: 1 branch
BranchTrueFalseTotal
my $name = $node->getAttribute("name") or &error(&__x("attribute without name at {where}", "where", $where)) 256 0 256
1066 or error __x"attribute without name at {where}", where => $where;
1067 256 $where .= '/@'.$name;
1068 256 $self->assertType($where, name => NCName => $name);
1069  
1070 256 my ($qual, $ns, $fullname);
1071 256 ▶ if($is_global)
Branch: 1 branch
BranchTrueFalseTotal
if ($is_global) { } 13 243 256
1072 13 ▶ { $ns = $node->getAttribute('targetNamespace')
Condition33%1/3
$node->getAttribute('targetNamespace') || $parent->getAttribute('targetNamespace')
l!l&&r!l&&!r
0130
MC/DC0%0/2
$node->getAttribute('targetNamespace') || $parent->getAttribute('targetNamespace')
$node->getAttribute('targetNamespace') $parent->getAttribute('targetNamespace')
Truth table33%1/3
A || B
A= $node->getAttribute('targetNamespace')B= $parent->getAttribute('targetNamespace')
ABresult
1X1
011
000
1073 || $parent->getAttribute('targetNamespace');
1074 13 $fullname= pack_type $ns, $name;
1075 13 my $def = $self->namespaces->find(attribute => $fullname);
1076 13 $context = $self->nsContext($def);
1077 13 $qual = $context->{qual_top};
1078 }
1079 else
1080 243 { $qual = $context->{qual_attr};
1081 243 $ns = $context->{tns};
1082 243 $fullname= pack_type $ns, $name;
1083 }
1084 256 ▶ local $self->{_context} = $context if $is_global;
Branch: 1 branch
BranchTrueFalseTotal
if $is_global 13 243 256
1085  
1086 256 ▶ if(my $form = $node->getAttribute('form'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $form = $node->getAttribute("form")) 0 256 256
1087 0 ▶ { $qual
Branch: 2 branches
BranchTrueFalseTotal
$form eq 'qualified' ? : 0 0 0
$form eq 'unqualified' ? : 0 0 0
1088 = $form eq 'qualified' ? 1
1089 : $form eq 'unqualified' ? 0
1090 : error __x"form must be (un)qualified, not `{form}' at {where}"
1091 , form => $form, where => $where, _class => 'schema';
1092 }
1093  
1094 # no default prefixes for attributes
1095 #warn "#", $self->prefixForNamespace($ns), "#";
1096 # error __x"attribute namespace {ns} cannot be the default namespace"
1097 # , ns => $ns
1098 # if $qual && $ns && $self->prefixForNamespace($ns) eq '';
1099  
1100 256 my ($type, $typeattr);
1101 256 ▶ if($tree->nrChildren==1)
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->nrChildren == 1) { } 7 249 256
1102 7 ▶ { $tree->currentLocal eq 'simpleType'
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentLocal eq "simpleType" or &error(&__x("attribute child can only be `simpleType', not `{found}' at {where}", "found", $tree->currentLocal, "where", $where, "_class", "schema")) 7 0 7
1103 or error __x"attribute child can only be `simpleType', not `{found}' at {where}"
1104 , found => $tree->currentLocal, where => $where
1105 , _class => 'schema';
1106  
1107 7 $type = $self->simpleType($tree->descend);
1108 }
1109 else
1110 249 ▶ { $name = $node->getAttribute('name')
Branch: 1 branch
BranchTrueFalseTotal
$name = $node->getAttribute("name") or &error(&__x("attribute without name or ref at {where}", "where", $where, "_class", "schema")) 249 0 249
1111 or error __x"attribute without name or ref at {where}"
1112 , where => $where, _class => 'schema';
1113  
1114 249 $typeattr = $node->getAttribute('type');
1115 }
1116  
1117 256 ▶ unless($type)
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 249 7 256
1118 249 ▶ { my $typename = defined $typeattr
Branch: 1 branch
BranchTrueFalseTotal
defined $typeattr ? : 246 3 249
1119 ? $self->rel2abs($where, $node, $typeattr)
1120 : $self->anyType($node);
1121  
1122 249 ▶ $type = $self->blocked($where, simpleType => $typename)
Condition66%2/3
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
l!l&&r!l&&!r
22470
MC/DC0%0/2
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
$self->blocked($where, 'simpleType', $typename) $self->typeByName($where, $tree, $typename)
Truth table66%2/3
A || B
A= $self->blocked($where, 'simpleType', $typename)B= $self->typeByName($where, $tree, $typename)
ABresult
1X1
011
000
1123 || $self->typeByName($where, $tree, $typename);
1124 }
1125  
1126 my $st = $type->{st}
1127 256 ▶ or error __x"attribute not based in simple value type at {where}"
Branch: 1 branch
BranchTrueFalseTotal
my $st = $type->{"st"} or &error(&__x("attribute not based in simple value type at {where}", "where", $where, "_class", "schema")) 256 0 256
1128 , where => $where, _class => 'schema';
1129  
1130 256 ▶ my $trans = $qual ? 'makeTagQualified' : 'makeTagUnqualified';
Branch: 1 branch
BranchTrueFalseTotal
$qual ? : 8 248 256
1131 256 ▶ my $qns = $qual ? $context->{tns} : '';
Branch: 1 branch
BranchTrueFalseTotal
$qual ? : 8 248 256
1132 256 my $tag = $self->$trans($where, $node, $name, $qns);
1133  
1134 256 ▶ my $use = $node->getAttribute('use') || '';
Condition100%2/2
$node->getAttribute('use') || ''
l!l
47209
MC/DC100%1/1
$node->getAttribute('use') || ''
$node->getAttribute('use')
Truth table100%2/2
A
A= $node->getAttribute('use')
Aresult
11
00
1135 256 ▶ $use =~ m/^(?:optional|required|prohibited|)$/
Branch: 1 branch
BranchTrueFalseTotal
$use =~ /^(?:optional|required|prohibited|)$/ or &error(&__x("attribute use is required, optional or prohibited (not '{use}') at {where}", "use", $use, "where", $where, "_class", "schema")) 256 0 256
1136 or error __x"attribute use is required, optional or prohibited (not '{use}') at {where}"
1137 , use => $use, where => $where, _class => 'schema';
1138  
1139 256 my $default = $node->getAttributeNode('default');
1140 256 my $fixed = $node->getAttributeNode('fixed');
1141  
1142 256 ▶ my $generate
Branch: 4 branches
BranchTrueFalseTotal
defined $default ? : 14 242 256
defined $fixed ? : 11 231 242
$use eq 'required' ? : 29 202 231
$use eq 'prohibited' ? : 6 196 202
1143 = defined $default ? 'makeAttributeDefault'
1144 : defined $fixed ? 'makeAttributeFixed'
1145 : $use eq 'required' ? 'makeAttributeRequired'
1146 : $use eq 'prohibited'? 'makeAttributeProhibited'
1147 : 'makeAttribute';
1148  
1149 256 ▶ my $value = defined $default ? $default : $fixed;
Branch: 1 branch
BranchTrueFalseTotal
defined $default ? : 14 242 256
1150 256 my $label = $self->keyRewrite($qns, $name);
1151 256 my $do = $self->$generate($where, $qns, $tag, $label, $st, $value);
1152 256 ▶ defined $do ? ($label => $do) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $do ? : 256 0 256
1153 }
1154  
1155 sub attributeGroup($)
1156 6 ▶{ my ($self, $tree) = @_;
Subroutine attributeGroup: called CC=4 SCAR=14.2
Pod undocumented
1157  
1158 # attributes: id, ref = QName
1159 # content: annotation?
1160  
1161 6 my $node = $tree->node;
1162 6 my $where = $tree->path;
1163 6 ▶ my $ref = $node->getAttribute('ref')
Branch: 1 branch
BranchTrueFalseTotal
my $ref = $node->getAttribute("ref") or &error(&__x("attributeGroup use without ref at {where}", "where", $tree->path, "_class", "schema")) 6 0 6
1164 or error __x"attributeGroup use without ref at {where}"
1165 , where => $tree->path, _class => 'schema';
1166  
1167 6 my $typename = $self->rel2abs($where, $node, $ref);
1168 6 ▶ return () if $self->blocked($where, ref => $typename);
Branch: 1 branch
BranchTrueFalseTotal
if $self->blocked($where, "ref", $typename) 0 6 6
1169  
1170 6 ▶ my $def = $self->namespaces->find(attributeGroup => $typename)
Branch: 1 branch
BranchTrueFalseTotal
my $def = $self->namespaces->find("attributeGroup", $typename) or &error(&__x("cannot find attributeGroup {name} at {where}", "name", $typename, "where", $where, "_class", "schema")) 6 0 6
1171 or error __x"cannot find attributeGroup {name} at {where}"
1172 , name => $typename, where => $where, _class => 'schema';
1173  
1174 6 local $self->{tns} = $def->{ns};
1175 6 $self->attributeList($tree->descend($def->{node}));
1176 }
1177  
1178 # Don't known how to handle notQName
1179 sub anyAttribute($)
1180 10 ▶{ my ($self, $tree) = @_;
Subroutine anyAttribute: called CC=6 SCAR=18.6
Pod undocumented
1181  
1182 # attributes: id
1183 # , namespace = ##any|##other| List of (anyURI|##targetNamespace|##local)
1184 # , notNamespace = List of (anyURI|##targetNamespace|##local)
1185 # ignored attributes
1186 # , notQName = List of QName
1187 # , processContents = lax|skip|strict
1188 # content: annotation?
1189  
1190 10 my $node = $tree->node;
1191 10 my $where = $tree->path . '@any';
1192  
1193 10 my $handler = $self->{any_attribute};
1194 10 ▶ my $namespace = $node->getAttribute('namespace') || '##any';
Condition50%1/2
$node->getAttribute('namespace') || '##any'
l!l
100
MC/DC0%0/1
$node->getAttribute('namespace') || '##any'
$node->getAttribute('namespace')
Truth table50%1/2
A
A= $node->getAttribute('namespace')
Aresult
11
00
1195 10 my $not_ns = $node->getAttribute('notNamespace');
1196 10 ▶ my $process = $node->getAttribute('processContents') || 'strict';
Condition50%1/2
$node->getAttribute('processContents') || 'strict'
l!l
100
MC/DC0%0/1
$node->getAttribute('processContents') || 'strict'
$node->getAttribute('processContents')
Truth table50%1/2
A
A= $node->getAttribute('processContents')
Aresult
11
00
1197  
1198 10 ▶ warn "HELP: please explain me how to handle notQName"
Branch: 1 branch
BranchTrueFalseTotal
if $^W and $node->getAttribute("notQName") 0 10 10
Condition33%1/3
$^W and $node->getAttribute("notQName")
!ll&&!rl&&r
1000
MC/DC0%0/2
$^W and $node->getAttribute("notQName")
$^W $node->getAttribute("notQName")
Truth table33%1/3
A and B
A= $^WB= $node->getAttribute("notQName")
ABresult
0X0
100
111
1199 if $^W && $node->getAttribute('notQName');
1200  
1201 10 my ($yes, $no) = $self->translateNsLimits($namespace, $not_ns);
1202 10 my $do = $self->makeAnyAttribute($where, $handler, $yes, $no, $process);
1203 10 ▶ defined $do ? $do : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $do ? : 9 1 10
1204 }
1205  
1206 sub anyElement($$$)
1207 10 ▶{ my ($self, $tree, $min, $max) = @_;
Subroutine anyElement: called CC=5 SCAR=17.0
Pod undocumented
1208  
1209 # attributes: id, maxOccurs, minOccurs,
1210 # , namespace = ##any|##other| List of (anyURI|##targetNamespace|##local)
1211 # , notNamespace = List of (anyURI|##targetNamespace|##local)
1212 # ignored attributes
1213 # , notQName = List of QName
1214 # , processContents = lax|skip|strict
1215 # content: annotation?
1216  
1217 10 my $node = $tree->node;
1218 10 my $where = $tree->path . '#any';
1219 10 my $handler = $self->{any_element};
1220  
1221 10 ▶ my $namespace = $node->getAttribute('namespace') || '##any';
Condition50%1/2
$node->getAttribute('namespace') || '##any'
l!l
100
MC/DC0%0/1
$node->getAttribute('namespace') || '##any'
$node->getAttribute('namespace')
Truth table50%1/2
A
A= $node->getAttribute('namespace')
Aresult
11
00
1222 10 my $not_ns = $node->getAttribute('notNamespace');
1223 10 ▶ my $process = $node->getAttribute('processContents') || 'strict';
Condition50%1/2
$node->getAttribute('processContents') || 'strict'
l!l
100
MC/DC0%0/1
$node->getAttribute('processContents') || 'strict'
$node->getAttribute('processContents')
Truth table50%1/2
A
A= $node->getAttribute('processContents')
Aresult
11
00
1224  
1225 10 ▶ info "HELP: please explain me how to handle notQName"
Branch: 1 branch
BranchTrueFalseTotal
if $^W and $node->getAttribute("notQName") 0 10 10
Condition33%1/3
$^W and $node->getAttribute("notQName")
!ll&&!rl&&r
1000
MC/DC0%0/2
$^W and $node->getAttribute("notQName")
$^W $node->getAttribute("notQName")
Truth table33%1/3
A and B
A= $^WB= $node->getAttribute("notQName")
ABresult
0X0
100
111
1226 if $^W && $node->getAttribute('notQName');
1227  
1228 10 my ($yes, $no) = $self->translateNsLimits($namespace, $not_ns);
1229 10 (any => $self->makeAnyElement($where, $handler, $yes, $no
1230 , $process, $min, $max));
1231 }
1232  
1233 sub translateNsLimits($$)
1234 20 ▶{ my ($self, $include, $exclude) = @_;
Subroutine translateNsLimits: called CC=10 SCAR=23.3
Pod undocumented
1235  
1236 # namespace = ##any|##other| List of (anyURI|##targetNamespace|##local)
1237 # notNamespace = List of (anyURI |##targetNamespace|##local)
1238 # handling of ##local ignored: only full namespaces are supported for now
1239  
1240 20 ▶ return (undef, []) if $include eq '##any';
Branch: 1 branch
BranchTrueFalseTotal
if $include eq "##any" 8 12 20
1241  
1242 12 my $tns = $self->{_context}{tns};
1243 12 ▶ return (undef, [$tns]) if $include eq '##other';
Branch: 1 branch
BranchTrueFalseTotal
if $include eq "##other" 4 8 12
1244  
1245 8 my @return;
1246 8 foreach my $list ($include, $exclude)
1247 16 { my @list;
1248 16 ▶ if(defined $list && length $list)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $list and length $list) 8 8 16
Condition66%2/3
defined $list and length $list
!ll&&!rl&&r
808
MC/DC50%1/2
defined $list and length $list
defined $list length $list
Truth table66%2/3
A and B
A= defined $listB= length $list
ABresult
0X0
100
111
1249 8 { foreach my $uri (split " ", $list)
1250 8 ▶ { push @list
Branch: 2 branches
BranchTrueFalseTotal
$uri eq '##targetNamespace' ? : 8 0 8
$uri eq '##local' ? : 0 0 0
1251 , $uri eq '##targetNamespace' ? $tns
1252 : $uri eq '##local' ? ()
1253 : $uri;
1254 }
1255 }
1256 16 ▶ push @return, @list ? \@list : undef;
Branch: 1 branch
BranchTrueFalseTotal
@list ? : 8 8 16
1257 }
1258  
1259 8 @return;
1260 }
1261  
1262 sub complexType($)
1263 606 ▶{ my ($self, $tree) = @_;
Subroutine complexType: called CC=9 SCAR=22.0
Pod undocumented
1264  
1265 # abstract, block, final, id, mixed, name, defaultAttributesApply
1266 # Full content:
1267 # annotation?
1268 # , ( simpleContent
1269 # | complexContent
1270 # | ( (group|all|choice|sequence)?
1271 # , (attribute|attributeGroup)*
1272 # , anyAttribute?
1273 # )
1274 # )
1275 # , (assert | report)*
1276  
1277 606 my $node = $tree->node;
1278 606 ▶ my $mixed = $self->isTrue($node->getAttribute('mixed') || 'false');
Condition100%2/2
$node->getAttribute('mixed') || 'false'
l!l
9597
MC/DC100%1/1
$node->getAttribute('mixed') || 'false'
$node->getAttribute('mixed')
Truth table100%2/2
A
A= $node->getAttribute('mixed')
Aresult
11
00
1279 undef $mixed
1280 606 ▶ if $self->{mixed_elements} eq 'STRUCTURAL';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"mixed_elements"} eq "STRUCTURAL" 1 605 606
1281  
1282 606 ▶ my $first = $tree->firstChild
Branch: 1 branch
BranchTrueFalseTotal
my $first = $tree->firstChild or return {"elems", [], "mixed", $mixed} 582 24 606
1283 or return {elems => [], mixed => $mixed};
1284  
1285 582 my $name = $first->localName;
1286 582 ▶ return $self->complexBody($tree, $mixed)
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /$particle_blocks/ or $name =~ /$attribute_defs/ 526 56 582
Condition100%3/3
$name =~ /$particle_blocks/ or $name =~ /$attribute_defs/
l!l&&r!l&&!r
4943256
MC/DC100%2/2
$name =~ /$particle_blocks/ or $name =~ /$attribute_defs/
$name =~ /$particle_blocks/ $name =~ /$attribute_defs/
Truth table100%3/3
A or B
A= $name =~ /$particle_blocks/B= $name =~ /$attribute_defs/
ABresult
1X1
011
000
1287 if $name =~ $particle_blocks || $name =~ $attribute_defs;
1288  
1289 56 ▶ $tree->nrChildren==1
Branch: 1 branch
BranchTrueFalseTotal
$tree->nrChildren == 1 or &error(&__x("expected is single simpleContent or complexContent at {where}", "where", $tree->path, "_class", "schema")) 56 0 56
1290 or error __x"expected is single simpleContent or complexContent at {where}"
1291 , where => $tree->path, _class => 'schema';
1292  
1293 56 ▶ return $self->simpleContent($tree->descend($first))
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "simpleContent" 22 34 56
1294 if $name eq 'simpleContent';
1295  
1296 34 ▶ return $self->complexContent($tree->descend($first), $mixed)
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "complexContent" 33 1 34
1297 if $name eq 'complexContent';
1298  
1299 1 error __x"complexType contains particles, simpleContent or complexContent, not `{name}' at {where}"
1300 , name => $name, where => $tree->path, _class => 'schema';
1301 }
1302  
1303 sub complexBody($$)
1304 558 ▶{ my ($self, $tree, $mixed) = @_;
Subroutine complexBody: called CC=4 SCAR=14.0
Pod undocumented
1305  
1306 558 ▶ $tree->currentChild
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentChild or return () 558 0 558
1307 or return ();
1308  
1309 # partial
1310 # (group|all|choice|sequence)?
1311 # , ((attribute|attributeGroup)*
1312 # , anyAttribute?
1313  
1314 558 my @elems;
1315 558 ▶ if($tree->currentLocal =~ $particle_blocks)
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->currentLocal =~ /$particle_blocks/) 526 32 558
1316 526 { push @elems, $self->particle($tree->descend); # unless $mixed;
1317 526 $tree->nextChild;
1318 }
1319  
1320 558 my @attrs = $self->attributeList($tree);
1321  
1322 558 ▶ defined $tree->currentChild
Branch: 1 branch
BranchTrueFalseTotal
defined $tree->currentChild and &error(&__x("trailing non-attribute `{name}' at {where}", "name", $tree->currentChild->localName, "where", $tree->path, "_class", "schema")) 0 558 558
1323 and error __x"trailing non-attribute `{name}' at {where}"
1324 , name => $tree->currentChild->localName, where => $tree->path
1325 , _class => 'schema';
1326  
1327 558 {elems => \@elems, mixed => $mixed, @attrs};
1328 }
1329  
1330 sub attributeList($)
1331 586 ▶{ my ($self, $tree) = @_;
Subroutine attributeList: called CC=5 SCAR=16.1
Pod undocumented
1332  
1333 # partial content
1334 # ((attribute|attributeGroup)*
1335 # , anyAttribute?
1336  
1337 586 my $where = $tree->path;
1338  
1339 586 my (@attrs, @any);
1340 586 ▶ for(my $attr = $tree->currentChild; defined $attr; $attr = $tree->nextChild)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr) 264 576 840
1341 264 { my $name = $attr->localName;
1342 264 ▶ if($name eq 'attribute')
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'attribute') { } 248 16 264
elsif ($name eq 'attributeGroup') { } 6 10 16
1343 248 { push @attrs, $self->attribute($tree->descend);
1344 }
1345 elsif($name eq 'attributeGroup')
1346 6 { my %group = $self->attributeGroup($tree->descend);
1347 6 push @attrs, @{$group{attrs}};
1348 6 push @any, @{$group{attrs_any}};
1349 }
1350 10 else { last }
1351 }
1352  
1353 # officially only one: don't believe that
1354 586 ▶ while($tree->currentLocal eq 'anyAttribute')
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->currentLocal eq "anyAttribute") 10 586 596
1355 10 { push @any, $self->anyAttribute($tree->descend);
1356 10 $tree->nextChild;
1357 }
1358  
1359 586 (attrs => \@attrs, attrs_any => \@any);
1360 }
1361  
1362 sub simpleContent($)
1363 22 ▶{ my ($self, $tree) = @_;
Subroutine simpleContent: called CC=4 SCAR=14.5
Pod undocumented
1364  
1365 # attributes: id
1366 # content: annotation?, (restriction | extension)
1367  
1368 22 ▶ $tree->nrChildren==1
Branch: 1 branch
BranchTrueFalseTotal
$tree->nrChildren == 1 or &error(&__x("need one simpleContent child at {where}", "where", $tree->path, "_class", "schema")) 22 0 22
1369 or error __x"need one simpleContent child at {where}", where => $tree->path, _class => 'schema';
1370  
1371 22 my $name = $tree->currentLocal;
1372 22 ▶ return $self->simpleContentExtension($tree->descend)
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "extension" 14 8 22
1373 if $name eq 'extension';
1374  
1375 8 ▶ return $self->simpleContentRestriction($tree->descend)
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "restriction" 8 0 8
1376 if $name eq 'restriction';
1377  
1378 0 error __x"simpleContent needs extension or restriction, not `{name}' at {where}"
1379 , name => $name, where => $tree->path, _class => 'schema';
1380 }
1381  
1382 sub simpleContentExtension($)
1383 14 ▶{ my ($self, $tree) = @_;
Subroutine simpleContentExtension: called CC=5 SCAR=17.0
Pod undocumented
1384  
1385 # attributes: id, base = QName
1386 # content: annotation?
1387 # , (attribute | attributeGroup)*
1388 # , anyAttribute?
1389 # , (assert | report)*
1390  
1391 14 my $node = $tree->node;
1392 14 my $where = $tree->path . '#sext';
1393  
1394 14 my $base = $node->getAttribute('base');
1395 14 ▶ my $typename = defined $base ? $self->rel2abs($where, $node, $base) : $self->anyType($node);
Branch: 1 branch
BranchTrueFalseTotal
defined $base ? : 14 0 14
1396  
1397 14 ▶ my $basetype = $self->blocked($where, simpleType => $typename)
Condition33%1/3
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
l!l&&r!l&&!r
0140
MC/DC0%0/2
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
$self->blocked($where, 'simpleType', $typename) $self->typeByName($where, $tree, $typename)
Truth table33%1/3
A || B
A= $self->blocked($where, 'simpleType', $typename)B= $self->typeByName($where, $tree, $typename)
ABresult
1X1
011
000
1398 || $self->typeByName($where, $tree, $typename);
1399 defined $basetype->{st}
1400 14 ▶ or error __x"base of simpleContent not simple at {where}", where => $where, _class => 'schema';
Branch: 1 branch
BranchTrueFalseTotal
defined $basetype->{"st"} or &error(&__x("base of simpleContent not simple at {where}", "where", $where, "_class", "schema")) 14 0 14
1401
1402 14 $self->extendAttrs($basetype, {$self->attributeList($tree)});
1403  
1404 14 ▶ $tree->currentChild
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentChild and &error(&__x("elements left at tail at {where}", "where", $tree->path, "_class", "schema")) 0 14 14
1405 and error __x"elements left at tail at {where}", where => $tree->path, _class => 'schema';
1406  
1407 14 $basetype;
1408 }
1409  
1410 sub simpleContentRestriction($$)
1411 8 ▶{ my ($self, $tree) = @_;
Subroutine simpleContentRestriction: called CC=7 SCAR=20.4
Pod undocumented
1412  
1413 # attributes id, base = QName
1414 # content: annotation?
1415 # , (simpleType?, facet*)?
1416 # , (attribute | attributeGroup)*, anyAttribute?
1417 # , (assert | report)*
1418  
1419 8 my $node = $tree->node;
1420 8 my $where = $tree->path . '#cres';
1421  
1422 8 my ($type, $typename);
1423 8 ▶ my $first = $tree->currentLocal || '';
Condition50%1/2
$tree->currentLocal || ''
l!l
80
MC/DC0%0/1
$tree->currentLocal || ''
$tree->currentLocal
Truth table50%1/2
A
A= $tree->currentLocal
Aresult
11
00
1424 8 ▶ if($first eq 'simpleType')
Branch: 2 branches
BranchTrueFalseTotal
if ($first eq 'simpleType') { } 4 4 8
elsif (my $basename = $node->getAttribute('base')) { } 4 0 4
1425 4 { $type = $self->simpleType($tree->descend);
1426 4 $tree->nextChild;
1427 }
1428 elsif(my $basename = $node->getAttribute('base'))
1429 4 { $typename = $self->rel2abs($where, $node, $basename);
1430 4 ▶ $type = $self->blocked($where, simpleType => $type)
Condition33%1/3
$self->blocked($where, 'simpleType', $type) || $self->typeByName($where, $tree, $typename)
l!l&&r!l&&!r
040
MC/DC0%0/2
$self->blocked($where, 'simpleType', $type) || $self->typeByName($where, $tree, $typename)
$self->blocked($where, 'simpleType', $type) $self->typeByName($where, $tree, $typename)
Truth table33%1/3
A || B
A= $self->blocked($where, 'simpleType', $type)B= $self->typeByName($where, $tree, $typename)
ABresult
1X1
011
000
1431 || $self->typeByName($where, $tree, $typename);
1432 }
1433 else
1434 0 { error __x"no base in complex-restriction, so simpleType required at {where}"
1435 , where => $where, _class => 'schema';
1436 }
1437  
1438 my $st = $type->{st}
1439 8 ▶ or error __x"not a simpleType in simpleContent/restriction at {where}"
Branch: 1 branch
BranchTrueFalseTotal
my $st = $type->{"st"} or &error(&__x("not a simpleType in simpleContent/restriction at {where}", "where", $where, "_class", "schema")) 8 0 8
1440 , where => $where, _class => 'schema';
1441  
1442 8 $type->{st} = $self->applySimpleFacets($tree, $st, 0, $typename);
1443  
1444 8 $self->extendAttrs($type, {$self->attributeList($tree)});
1445  
1446 8 ▶ $tree->currentChild
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentChild and &error(&__x("elements left at tail at {where}", "where", $where, "_class", "schema")) 0 8 8
1447 and error __x"elements left at tail at {where}"
1448 , where => $where, _class => 'schema';
1449  
1450 8 $type;
1451 }
1452  
1453 sub complexContent($$)
1454 33 ▶{ my ($self, $tree, $mixed) = @_;
Subroutine complexContent: called CC=13 SCAR=27.0
Pod undocumented
1455  
1456 # attributes: id, mixed = boolean
1457 # content: annotation?, (restriction | extension)
1458  
1459 33 my $node = $tree->node;
1460 33 ▶ if(my $m = $node->getAttribute('mixed'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $m = $node->getAttribute("mixed")) 0 33 33
1461 { $mixed = $self->isTrue($m)
1462 0 ▶ if $self->{mixed_elements} ne 'STRUCTURAL';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"mixed_elements"} ne "STRUCTURAL" 0 0 0
1463 }
1464  
1465 33 ▶ $tree->nrChildren == 1
Branch: 1 branch
BranchTrueFalseTotal
$tree->nrChildren == 1 or &error(&__x("only one complexContent child expected at {where}", "where", $tree->path, "_class", "schema")) 33 0 33
1466 or error __x"only one complexContent child expected at {where}"
1467 , where => $tree->path, _class => 'schema';
1468  
1469 33 my $name = $tree->currentLocal;
1470 33 ▶ error __x"complexContent needs extension or restriction, not `{name}' at {where}"
Branch: 1 branch
BranchTrueFalseTotal
if $name ne "extension" and $name ne "restriction" 1 32 33
Condition100%3/3
$name ne "extension" and $name ne "restriction"
!ll&&!rl&&r
2841
MC/DC100%2/2
$name ne "extension" and $name ne "restriction"
$name ne "extension" $name ne "restriction"
Truth table100%3/3
A and B
A= $name ne "extension"B= $name ne "restriction"
ABresult
0X0
100
111
1471 , name => $name, where => $tree->path, _class => 'schema'
1472 if $name ne 'extension' && $name ne 'restriction';
1473  
1474 32 $tree = $tree->descend;
1475 32 $node = $tree->node;
1476 32 ▶ my $base = $node->getAttribute('base') || $self->anyType($node);
Condition33%1/3
$node->getAttribute('base') || $self->anyType($node)
l!l&&r!l&&!r
3200
MC/DC0%0/2
$node->getAttribute('base') || $self->anyType($node)
$node->getAttribute('base') $self->anyType($node)
Truth table33%1/3
A || B
A= $node->getAttribute('base')B= $self->anyType($node)
ABresult
1X1
011
000
1477 32 my $type = {};
1478 32 my $where = $tree->path . '#cce';
1479  
1480 32 ▶ if($base !~ m/\banyType$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($base =~ /\banyType$/) 32 0 32
1481 32 { my $typename = $self->rel2abs($where, $node, $base);
1482 32 ▶ if($type = $self->blocked($where, complexType => $typename))
Branch: 1 branch
BranchTrueFalseTotal
if ($type = $self->blocked($where, 'complexType', $typename)) { } 4 28 32
1483 { # blocked base type
1484 }
1485 else
1486 28 ▶ { my $typedef = $self->namespaces->find(complexType => $typename)
Branch: 1 branch
BranchTrueFalseTotal
my $typedef = $self->namespaces->find("complexType", $typename) or &error(&__x("unknown base type '{type}' at {where}", "type", $typename, "where", $tree->path, "_class", "schema")) 28 0 28
1487 or error __x"unknown base type '{type}' at {where}"
1488 , type => $typename, where => $tree->path, _class => 'schema';
1489  
1490 28 local $self->{_context} = $self->nsContext($typedef);
1491 28 $type = $self->complexType($tree->descend($typedef->{node}));
1492 }
1493 }
1494  
1495 32 my $own = $self->complexBody($tree, $mixed);
1496 32 $self->extendAttrs($type, $own);
1497  
1498 32 ▶ if($name eq 'extension')
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'extension') { } 28 4 32
1499 28 ▶ { push @{$type->{elems}}, @{$own->{elems} || []};
Condition50%1/2
$own->{'elems'} || []
l!l
280
MC/DC0%0/1
$own->{'elems'} || []
$own->{'elems'}
Truth table50%1/2
A
A= $own->{'elems'}
Aresult
11
00
1500 }
1501 else # restriction
1502 4 { $type->{elems} = $own->{elems};
1503 }
1504  
1505 32 ▶ $type->{mixed} ||= $own->{mixed};
Condition33%1/3
$type->{"mixed"} ||= $own->{"mixed"}
l!l&&r!l&&!r
0032
MC/DC0%0/2
$type->{"mixed"} ||= $own->{"mixed"}
$type->{"mixed"} $own->{"mixed"}
Truth table33%1/3
A ||= B
A= $type->{"mixed"}B= $own->{"mixed"}
ABresult
1X1
011
000
1506 32 $type;
1507 }
1508  
1509 #
1510 # Helper routines
1511 #
1512  
1513 # print $self->rel2abs($path, $node, '{ns}type') -> '{ns}type'
1514 # print $self->rel2abs($path, $node, 'prefix:type') -> '{ns-of-prefix}type'
1515  
1516 sub rel2abs($$$)
1517 2251 ▶{ my ($self, $where, $node, $type) = @_;
Subroutine rel2abs: called CC=6 SCAR=18.2
Pod undocumented
1518 2251 ▶ return $type if substr($type, 0, 1) eq '{';
Branch: 1 branch
BranchTrueFalseTotal
if substr($type, 0, 1) eq "{" 0 2251 2251
1519  
1520 2251 ▶ my ($prefix, $local) = $type =~ m/^(.+?)\:(.*)/ ? ($1, $2) : ('', $type);
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /^(.+?)\:(.*)/ ? : 631 1620 2251
1521 2251 my $uri = $node->lookupNamespaceURI($prefix);
1522 2251 ▶ $self->_registerNSprefix($prefix, $uri, 0) if $uri;
Branch: 1 branch
BranchTrueFalseTotal
if $uri 2247 4 2251
1523  
1524 2251 ▶ error __x"No namespace for prefix `{prefix}' in `{type}' at {where}"
Branch: 1 branch
BranchTrueFalseTotal
if length $prefix and not defined $uri 0 2251 2251
Condition66%2/3
length $prefix and not defined $uri
!ll&&!rl&&r
16206310
MC/DC0%0/2
length $prefix and not defined $uri
length $prefix not defined $uri
Truth table66%2/3
A and not(B)
A= length $prefixB= not defined $uri
ABresult
0X0
100
111
1525 , prefix => $prefix, type => $type, where => $where, _class => 'schema'
1526 if length $prefix && !defined $uri;
1527  
1528 2251 pack_type $uri, $local;
1529 }
1530  
1531 sub _registerNSprefix($$$)
1532 2489 ▶{ my ($self, $prefix, $uri, $used) = @_;
Subroutine _registerNSprefix: called CC=6 SCAR=18.0
1533 2489 my $table = $self->{prefixes};
1534  
1535 2489 ▶ if(my $u = $table->{$uri}) # namespace already has a prefix
Branch: 1 branch
BranchTrueFalseTotal
if (my $u = $table->{$uri}) 1334 1155 2489
1536 1334 { $u->{used} += $used;
1537 1334 return $u->{prefix};
1538 }
1539  
1540 1155 my %prefs = map +($_->{prefix} => 1), values %$table;
1541 1155 my $take;
1542 1155 ▶ if(defined $prefix && !$prefs{$prefix}) { $take = $prefix }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $prefix and not $prefs{$prefix}) { } 735 420 1155
elsif (not $prefs{''}) { } 0 420 420
Condition66%2/3
defined $prefix and not $prefs{$prefix}
!ll&&!rl&&r
0420735
MC/DC50%1/2
defined $prefix and not $prefs{$prefix}
defined $prefix not $prefs{$prefix}
Truth table66%2/3
A and not(B)
A= defined $prefixB= not $prefs{$prefix}
ABresult
0X0
100
111
1543 0 elsif(!$prefs{''}) { $take = '' }
1544 else
1545 { # prefix already in use; create a new x\d+ prefix
1546 420 my $count = 0;
1547 420 ▶ $count++ while exists $prefs{"x$count"};
Branch: 1 branch
BranchTrueFalseTotal
exists $prefs{"x$count"} and do { ++$count } 5 420 425
1548 420 $take = 'x'.$count;
1549 }
1550 1155 $table->{$uri} = {prefix => $take, uri => $uri, used => $used};
1551 1155 $take;
1552 }
1553  
1554 sub anyType($)
1555 15 ▶{ my ($self, $node) = @_;
Subroutine anyType: called CC=1 SCAR=0.0
Pod undocumented
1556 15 pack_type $node->namespaceURI, 'anyType';
1557 }
1558  
1559 sub findHooks($$$)
1560 1886 ▶{ my ($self, $path, $type, $node) = @_;
Subroutine findHooks: called CC=28 SCAR=35.0
Pod undocumented
1561 # where is before, replace, after
1562  
1563 1886 my %hooks;
1564 1886 foreach my $hook (@{$self->{hooks}})
1565 61 { my $match;
1566  
1567 $match++
1568 if !$hook->{path} && !$hook->{id}
1569 61 ▶ && !$hook->{type} && !$hook->{extends};
Branch: 1 branch
BranchTrueFalseTotal
unless $hook->{"path"} or $hook->{"id"} or $hook->{"type"} or $hook->{"extends"} 0 61 61
Condition66%6/9
$hook->{"path"} or $hook->{"id"} or $hook->{"type"} or $hook->{"extends"}
l!l&&r!l&&!r
6100
$hook->{"path"} or $hook->{"id"} or $hook->{"type"}
l!l&&r!l&&!r
29320
$hook->{"path"} or $hook->{"id"}
l!l&&r!l&&!r
82132
MC/DC0%0/4
$hook->{"path"} or $hook->{"id"} or $hook->{"type"} or $hook->{"extends"}
$hook->{"path"} $hook->{"id"} $hook->{"type"} $hook->{"extends"}
Truth table60%3/5
A or B or C or D
A= $hook->{"path"}B= $hook->{"id"}C= $hook->{"type"}D= $hook->{"extends"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1570  
1571 61 ▶ if(!$match && $hook->{path})
Branch: 1 branch
BranchTrueFalseTotal
if (not $match and $hook->{"path"}) 8 53 61
Condition66%2/3
not $match and $hook->{"path"}
!ll&&!rl&&r
0538
MC/DC50%1/2
not $match and $hook->{"path"}
not $match $hook->{"path"}
Truth table66%2/3
not(A) and B
A= not $matchB= $hook->{"path"}
ABresult
0X0
100
111
1572 8 { my $p = $hook->{path};
1573 $match++
1574 8 ▶ if first {ref $_ eq 'Regexp' ? $path =~ $_ : $path eq $_}
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'Regexp' ? : 8 0 8
1575 8 ▶ ref $p eq 'ARRAY' ? @$p : $p;
Branch: 2 branches
BranchTrueFalseTotal
if &first(sub { ref $_ eq "Regexp" ? $path =~ /$_/ : $path eq $_; } , ref $p eq "ARRAY" ? @$p : $p) 2 6 8
ref $p eq 'ARRAY' ? : 0 8 8
1576 }
1577  
1578 61 ▶ my $id = !$match && $hook->{id} && $node->getAttribute('id');
Condition100%6/6
!$match && $hook->{'id'} && $node->getAttribute('id')
!ll&&!rl&&r
341215
not $match and $hook->{"id"}
!ll&&!rl&&r
23227
MC/DC100%3/3
!$match && $hook->{'id'} && $node->getAttribute('id')
not $match $hook->{"id"} $node->getAttribute('id')
Truth table100%4/4
not(A) and B && C
A= not $matchB= $hook->{"id"}C= $node->getAttribute('id')
ABCresult
0XX0
10X0
1100
1111
1579 61 ▶ if($id)
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 15 46 61
1580 15 { my $i = $hook->{id};
1581 $match++
1582 15 ▶ if first {ref $_ eq 'Regexp' ? $id =~ $_ : $id eq $_}
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'Regexp' ? : 0 15 15
1583 15 ▶ ref $i eq 'ARRAY' ? @$i : $i;
Branch: 2 branches
BranchTrueFalseTotal
if &first(sub { ref $_ eq "Regexp" ? $id =~ /$_/ : $id eq $_; } , ref $i eq "ARRAY" ? @$i : $i) 8 7 15
ref $i eq 'ARRAY' ? : 0 15 15
1584 }
1585  
1586 61 ▶ if(!$match && defined $type && $hook->{type})
Branch: 1 branch
BranchTrueFalseTotal
if (not $match and defined $type and $hook->{"type"}) 36 25 61
Condition83%5/6
not $match and defined $type and $hook->{"type"}
!ll&&!rl&&r
101536
not $match and defined $type
!ll&&!rl&&r
10051
MC/DC66%2/3
not $match and defined $type and $hook->{"type"}
not $match defined $type $hook->{"type"}
Truth table75%3/4
not(A) and B and C
A= not $matchB= defined $typeC= $hook->{"type"}
ABCresult
0XX0
10X0
1100
1111
1587 36 { my $t = $hook->{type};
1588 36 my ($ns, $local) = unpack_type $type;
1589 $match++
1590 36 ▶ if first {ref $_ eq 'Regexp' ? $type =~ $_
Subroutine __ANON__: called CC=3 SCAR=11.2
Branch: 2 branches
BranchTrueFalseTotal
ref $_ eq 'Regexp' ? : 0 36 36
substr($_, 0, 1) eq '{' ? : 32 4 36
1591 : substr($_,0,1) eq '{' ? $type eq $_
1592 : $local eq $_
1593 36 ▶ } ref $t eq 'ARRAY' ? @$t : $t;
Branch: 2 branches
BranchTrueFalseTotal
if &first(sub { ref $_ eq "Regexp" ? $type =~ /$_/ : (substr($_, 0, 1) eq "{" ? $type eq $_ : $local eq $_); } , ref $t eq "ARRAY" ? @$t : $t) 13 23 36
ref $t eq 'ARRAY' ? : 0 36 36
1594 }
1595  
1596 61 ▶ if(!$match && defined $type && $hook->{extends})
Branch: 1 branch
BranchTrueFalseTotal
if (not $match and defined $type and $hook->{"extends"}) 0 61 61
Condition66%4/6
not $match and defined $type and $hook->{"extends"}
!ll&&!rl&&r
23380
not $match and defined $type
!ll&&!rl&&r
23038
MC/DC0%0/3
not $match and defined $type and $hook->{"extends"}
not $match defined $type $hook->{"extends"}
Truth table50%2/4
not(A) and B and C
A= not $matchB= defined $typeC= $hook->{"extends"}
ABCresult
0XX0
10X0
1100
1111
1597 0 ▶ { $match++ if $self->{nss}->doesExtend($type, $hook->{extends});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"nss"}->doesExtend($type, $hook->{"extends"}) 0 0 0
1598 }
1599  
1600 61 ▶ $match or next;
Branch: 1 branch
BranchTrueFalseTotal
$match or next 23 38 61
1601  
1602 23 foreach my $where ( qw/before replace after/ )
1603 69 ▶ { my $w = $hook->{$where} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $w = $hook->{$where} or next 29 40 69
1604 29 ▶ push @{$hooks{$where}}, ref $w eq 'ARRAY' ? @$w : $w;
Branch: 1 branch
BranchTrueFalseTotal
ref $w eq 'ARRAY' ? : 4 25 29
1605 }
1606 }
1607  
1608 1886 @hooks{ qw/before replace after/ };
1609 }
1610  
1611 # Namespace blocks, in most cases because the schema refers to an
1612 # older version of itself, which is deprecated.
1613 # performance is important, because it is called increadably often.
1614  
1615 sub decodeBlocked($)
1616 779 ▶{ my ($self, $what) = @_;
Subroutine decodeBlocked: called CC=7 SCAR=25.7
Pod undocumented
1617 779 ▶ defined $what or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $what or return 779 0 779
1618 779 my @blocked; # code-refs called with ($type, $ns, $local, $path)
1619 779 ▶ foreach my $w (ref $what eq 'ARRAY' ? @$what : $what)
Branch: 1 branch
BranchTrueFalseTotal
ref $what eq 'ARRAY' ? : 779 0 779
1620 { push @blocked,
1621 86 ▶ !ref $w ? sub { $_[0] eq $w || $_[1] eq $w }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq $w or $_[1] eq $w 0 86 86
1622 : ref $w eq 'HASH'
1623 0 ▶ ? sub { defined $w->{$_[0]} ? $w->{$_[0]} : $w->{$_[1]} }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $$w{$_[0]} ? : 0 0 0
1624 30 ▶ : ref $what eq 'CODE' ? $w
Branch: 3 branches
BranchTrueFalseTotal
!ref($w) ? : 30 0 30
ref $w eq 'HASH' ? : 0 0 0
ref $what eq 'CODE' ? : 0 0 0
1625 : error __x"blocking rule with {what} not supported", what => $w;
1626 }
1627 779 \@blocked;
1628 }
1629  
1630 sub blocked($$$)
1631 2145 ▶{ my ($self, $path, $class, $type) = @_;
Subroutine blocked: called CC=5 SCAR=16.1
Pod undocumented
1632 # $class = simpleType, complexType, or ref
1633 2145 ▶ @{$self->{blocked_nss}} or return ();
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{"blocked_nss"};} or return () 86 2059 2145
1634  
1635 86 my ($ns, $local) = unpack_type $type;
1636 86 my $is_blocked;
1637 86 foreach my $blocked ( @{$self->{blocked_nss}} )
1638 86 { $is_blocked = $blocked->($type, $ns, $local, $path);
1639 86 ▶ last if defined $is_blocked;
Branch: 1 branch
BranchTrueFalseTotal
if defined $is_blocked 86 0 86
1640 }
1641 86 ▶ $is_blocked or return;
Branch: 1 branch
BranchTrueFalseTotal
$is_blocked or return 38 48 86
1642  
1643 38 trace "$type of $class is blocked";
1644 38 $self->makeBlocked($path, $class, $type);
1645 }
1646  
1647 sub addTypeAttribute($$)
1648 0 ▶{ my ($self, $type, $call) = @_;
Subroutine addTypeAttribute: not called CC=1 SCAR=6.9
Pod undocumented
1649 0 $call;
1650 }
1651  
1652 #------------
1653  
1654 50 1;
« Compile.pm ↑ Summary Compile/Schema.pm »