lib/XML/Compile/Translate.pm

filter: Statementstmt 93.6% 683 / 729 Branchbran 71.4% 386 / 540 Conditioncond 70.5% 144 / 204 MC/DCmcdc 40.0% 48 / 120 Subroutinesub 93.9% 62 / 66 Podpod 6.5% 3 / 46 totaltotal 77.7% 1326 / 1705 CC 358 SCAR 30.3
CC
358
Cov
82%
element
59.8
attribute
37.8
findHooks
33.2
CRAP 20.7
« lib/XML/Compile.pm ↑ Summary lib/XML/Compile/Schema.pm »
1 # Copyrights 2006-2018 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.02.
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 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 50 $VERSION = '1.61';
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
28 50 ▶ unpack_id/;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 755 ▶{ my ($baseclass, $trans) = (shift, shift);
Subroutine new: called CC=3 SCAR=11.3
Pod documented
51 755 ▶ my $class = $translators{$trans}
Branch: 1 branch
BranchTrueFalseTotal
my $class = $translators{$trans} or &error(&__x("translator back-end {name} not defined", "name", $trans)) 0 755 755
52 or error __x"translator back-end {name} not defined", name => $trans;
53  
54 755 eval "require $class";
55 755 ▶ fault $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 755 755
56  
57 755 (bless {}, $class)->init( {@_} );
58 }
59  
60 sub init($)
61 755 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=3 SCAR=11.4
Pod undocumented
62 755 ▶ $self->{nss} = $args->{nss} or panic "no namespace tables";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"nss"} = $args->{"nss"} or &panic("no namespace tables") 0 755 755
63 755 ▶ $self->{prefixes} = $args->{prefixes} || {};
Condition50%1/2
$args->{'prefixes'} || {}
l!l
0755
MC/DC0%0/1
$args->{'prefixes'} || {}
$args->{'prefixes'}
Truth table50%1/2
A
A= $args->{'prefixes'}
Aresult
11
00
64 755 $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 755 ▶{ my ($self, $item, %args) = @_;
Subroutine compile: called CC=10 SCAR=24.3
Pod documented
84 755 @$self{keys %args} = values %args; # dirty. Always all the same fields
85  
86 755 ▶ my $path = $self->prefixed($item, 1) || $item;
Condition66%2/3
$self->prefixed($item, 1) || $item
l!l&&r!l&&!r
447110
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 755 ▶ ref $item
Branch: 1 branch
BranchTrueFalseTotal
ref $item and &panic("expecting an item as point to start at $path") 0 755 755
88 and panic "expecting an item as point to start at $path";
89  
90 755 ▶ my $hooks = $self->{hooks} ||= [];
Condition100%2/2
$self->{"hooks"} ||= []
l!l
73619
MC/DC100%1/1
$self->{"hooks"} ||= []
$self->{"hooks"}
Truth table100%2/2
A
A= $self->{"hooks"}
Aresult
11
00
91 755 ▶ my $typemap = $self->{typemap} ||= {};
Condition100%2/2
$self->{"typemap"} ||= {}
l!l
73916
MC/DC100%1/1
$self->{"typemap"} ||= {}
$self->{"typemap"}
Truth table100%2/2
A
A= $self->{"typemap"}
Aresult
11
00
92 755 $self->typemapToHooks($hooks, $typemap);
93  
94 $self->{blocked_nss}
95 755 = $self->decodeBlocked(delete $self->{block_namespace});
96  
97 755 my $nsp = $self->namespaces;
98 755 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)) 0 9 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 755 ▶ if(my $def = $self->namespaces->findID($item))
Branch: 1 branch
BranchTrueFalseTotal
if (my $def = $self->namespaces->findID($item)) 0 755 755
105 0 { my $node = $def->{node};
106 0 my $name = $node->localName;
107 0 $item = $def->{full};
108 }
109  
110 755 delete $self->{_created};
111 755 my $produce = $self->topLevel($path, $item, 1);
112 753 delete $self->{_created};
113  
114 my $in = $self->{include_namespaces}
115 753 ▶ or return $produce;
Branch: 1 branch
BranchTrueFalseTotal
my $in = $self->{"include_namespaces"} or return $produce 632 121 753
116  
117 121 $self->makeWrapperNs($path, $produce, $self->{prefixes}, $in);
118 }
119  
120 sub assertType($$$$)
121 2118 ▶{ my ($self, $where, $field, $type, $value) = @_;
Subroutine assertType: called CC=3 SCAR=13.5
Pod undocumented
122 2118 my $checker = $builtin_types{$type}{check};
123 2118 ▶ unless(defined $checker)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $checker) 0 2118 2118
124 0 { mistake "useless assert for type $type";
125 0 return;
126 }
127  
128 2118 ▶ return if $checker->($value);
Branch: 1 branch
BranchTrueFalseTotal
if &$checker($value) 2118 0 2118
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} || []});
Branch: 2 branches
BranchTrueFalseTotal
$in->{"attrs"} or [] 24 30 54
$add->{"attrs"} or [] 0 54 54
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 2436 ▶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" 2436 0 2436
162  
163 # Find the namespace use details of a certain top-level element or
164 # attribute.
165 sub nsContext($)
166 1999 ▶{ my ($self, $def) = @_;
Subroutine nsContext: called CC=16 SCAR=30.2
Pod undocumented
167 1999 ▶ $def or return {};
Branch: 1 branch
BranchTrueFalseTotal
$def or return {} 0 1999 1999
168  
169 1999 my $tns = $def->{ns};
170  
171 # top elements are to be qualified unless there is no targetNamespace
172 1999 ▶ my %context = (tns => $tns, qual_top => ($tns ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
$tns ? : 1979 20 1999
173  
174 1999 my $el_qual = $def->{efd} eq 'qualified';
175 1999 ▶ if(exists $self->{elements_qualified})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"elements_qualified"}) 1761 238 1999
176 1761 ▶ { my $qual = $self->{elements_qualified} || 0;
Condition50%1/2
$self->{'elements_qualified'} || 0
l!l
17610
MC/DC0%0/1
$self->{'elements_qualified'} || 0
$self->{'elements_qualified'}
Truth table50%1/2
A
A= $self->{'elements_qualified'}
Aresult
11
00
177 1761 ▶ if($qual eq 'TOP')
Branch: 1 branch
BranchTrueFalseTotal
if ($qual eq 'TOP') { } 0 1761 1761
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 1761 ▶ { $el_qual = $qual eq 'ALL' ? 1 : $qual eq 'NONE' ? 0 : $qual;
Branch: 2 branches
BranchTrueFalseTotal
$qual eq 'ALL' ? : 56 1705 1761
$qual eq 'NONE' ? : 1659 46 1705
183 }
184 1761 ▶ $context{qual_top} = 0 if $qual eq 'NONE';
Branch: 1 branch
BranchTrueFalseTotal
if $qual eq "NONE" 1659 102 1761
185 }
186 1999 $context{qual_elem} = $el_qual;
187  
188 1999 my $at_qual = $def->{afd} eq 'qualified';
189 1999 ▶ if(exists $self->{attributes_qualified})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"attributes_qualified"}) 22 1977 1999
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 1999 $context{qual_attr} = $at_qual;
199  
200 1999 \%context;
201 }
202  
203 4847 ▶sub namespaces() { $_[0]->{nss} }
Subroutine namespaces: called CC=1 SCAR=0.0
Pod undocumented
204  
205 sub topLevel($$;$)
206 755 ▶{ 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 755 );
214  
215 755 ▶ if($internal)
Branch: 1 branch
BranchTrueFalseTotal
if ($internal) 2 753 755
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 753 my $nss = $self->namespaces;
225 753 ▶ 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")) 0 753 753
$fullname eq $path ? : 0 0 0
Condition66%2/3
$nss->find('element', $fullname) || $nss->find('attribute', $fullname)
l!l&&r!l&&!r
74580
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 753 my $node = $top->{node};
234 753 my $schemans = $node->namespaceURI;
235 my $tree = XML::Compile::Iterator->new($node, $path, sub
236 8811 ▶ { my $n = shift;
Subroutine __ANON__: called CC=3 SCAR=11.1
237 8811 ▶ $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/ 3232 5579 8811
Condition66%2/3
$n->isa("XML::LibXML::Element") and $n->namespaceURI eq $schemans
!ll&&!rl&&r
557903232
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 753 });
241  
242 753 delete $self->{_nest}; # reset recursion administration
243  
244 753 local $self->{_context} = $self->nsContext($top);
245 753 my $name = $node->localName;
246 753 my $data;
247 753 ▶ if($name eq 'element')
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'element') { } 745 8 753
elsif ($name eq 'attribute') { } 8 0 8
248 745 { my ($label, $make) = $self->element($tree, $is_root);
249 743 ▶ $data = $self->makeElementWrapper($path, $make) if $make;
Branch: 1 branch
BranchTrueFalseTotal
if $make 743 0 743
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 751 $data;
262 }
263  
264 sub typeByName($$$)
265 1929 ▶{ my ($self, $where, $tree, $typename) = @_;
Subroutine typeByName: called CC=6 SCAR=18.1
Pod undocumented
266  
267 1929 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 1929 );
278  
279 1929 ▶ if($def)
Branch: 1 branch
BranchTrueFalseTotal
if ($def) 1573 356 1929
280 { # Is built-in
281 1573 my $st = $self->makeBuiltin($where, $node, $typename, $def, $self->{check_values});
282  
283 1573 return +{ st => $st, is_list => $def->{is_list} };
284 }
285  
286 #
287 # not a schema standard type
288 #
289 356 ▶ 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")) 0 356 356
Condition66%2/3
$self->namespaces->find('complexType', $typename) || $self->namespaces->find('simpleType', $typename)
l!l&&r!l&&!r
1911650
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 356 local $self->{_context} = $self->nsContext($top);
295 356 my $typeimpl = $tree->descend($top->{node});
296  
297 356 my $typedef = $top->{type};
298 356 ▶ $typedef eq 'simpleType' ? $self->simpleType($typeimpl)
Branch: 2 branches
BranchTrueFalseTotal
$typedef eq 'simpleType' ? : 165 191 356
$typedef eq 'complexType' ? : 191 0 191
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 340 ▶{ my ($self, $tree, $in_list) = @_;
Subroutine simpleType: called CC=5 SCAR=16.2
Pod undocumented
306  
307 340 ▶ $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")) 0 340 340
308 or error __x"simpleType must have exactly one child at {where}"
309 , where => $tree->path, _class => 'schema';
310  
311 340 my $child = $tree->firstChild;
312 340 my $name = $child->localName;
313 340 my $nest = $tree->descend($child);
314  
315 # Full content:
316 # annotation?
317 # , (restriction | list | union)
318  
319 340 ▶ my $type
Branch: 3 branches
BranchTrueFalseTotal
$name eq 'restriction' ? : 263 77 340
$name eq 'list' ? : 40 37 77
$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 340 delete @$type{'attrs','attrs_any'}; # spec says ignore attrs
327 340 $type;
328 }
329  
330 sub simpleList($)
331 40 ▶{ 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 40 my $per_item;
337 40 my $node = $tree->node;
338 40 my $where = $tree->path . '#list';
339  
340 40 ▶ if(my $type = $node->getAttribute('itemType'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $node->getAttribute('itemType')) { } 26 14 40
341 26 ▶ { $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")) 0 26 26
342 or error __x"list with both itemType and content at {where}"
343 , where => $where, _class => 'schema';
344  
345 26 my $typename = $self->rel2abs($where, $node, $type);
346 26 ▶ $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
0260
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 14 ▶ { $tree->nrChildren==1
Branch: 1 branch
BranchTrueFalseTotal
$tree->nrChildren == 1 or &error(&__x("list expects one simpleType child at {where}", "where", $where, "_class", "schema")) 0 14 14
351 or error __x"list expects one simpleType child at {where}"
352 , where => $where, _class => 'schema';
353  
354 14 ▶ $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")) 0 14 14
355 or error __x"list can only have a simpleType child at {where}"
356 , where => $where, _class => 'schema';
357  
358 14 $per_item = $self->simpleType($tree->descend, 1);
359 }
360  
361 my $st = $per_item->{st}
362 40 ▶ 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") 0 40 40
363  
364 40 $per_item->{st} = $self->makeList($where, $st);
365 40 $per_item->{is_list} = 1;
366 40 $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")) 0 43 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")) 0 39 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 263 ▶{ 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 263 my $node = $tree->node;
420 263 my $where = $tree->path . '#sres';
421  
422 263 my ($base, $typename);
423 263 ▶ if(my $basename = $node->getAttribute('base'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $basename = $node->getAttribute('base')) { } 263 0 263
424 263 { $typename = $self->rel2abs($where, $node, $basename);
425 263 ▶ $base = $self->blocked($where, simpleType => $typename)
Condition66%2/3
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
l!l&&r!l&&!r
22610
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 263 ▶ 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")) 0 263 263
450 , where => $where, _class => 'schema';
451  
452 my $do = $self->applySimpleFacets($tree, $st
453 263 ▶ , $in_list || $base->{is_list}, $typename);
Condition100%3/3
$in_list || $base->{'is_list'}
l!l&&r!l&&!r
149240
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 263 ▶ $tree->currentChild
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentChild and &error(&__x("elements left at tail at {where}", "where", $tree->path, "_class", "schema")) 0 263 263
456 and error __x"elements left at tail at {where}"
457 , where => $tree->path, _class => 'schema';
458  
459 263 +{ 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 271 ▶{ my ($self, $tree, $st, $is_list, $type) = @_;
Subroutine applySimpleFacets: called CC=19 SCAR=29.5
Pod undocumented
472 271 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 271 my $where = $tree->path . '#facet';
481 271 my (%facets, $is_qname);
482 271 ▶ for(my $child = $tree->currentChild; $child; $child = $tree->nextChild)
Branch: 1 branch
BranchTrueFalseTotal
if ($child) 266 263 529
483 266 { my $facet = $child->localName;
484 266 ▶ last if $facet =~ $attribute_defs;
Branch: 1 branch
BranchTrueFalseTotal
if $facet =~ /$attribute_defs/ 8 258 266
485  
486 258 my $value = $child->getAttribute('value');
487 258 ▶ defined $value
Branch: 1 branch
BranchTrueFalseTotal
defined $value or &error(&__x("no value for facet `{facet}' at {where}", "facet", $facet, "where", $where, "_class", "schema")) 0 258 258
488 or error __x"no value for facet `{facet}' at {where}"
489 , facet => $facet, where => $where, _class => 'schema';
490  
491 258 ▶ if($facet eq 'enumeration')
Branch: 3 branches
BranchTrueFalseTotal
if ($facet eq 'enumeration') { } 88 170 258
elsif ($facet eq 'pattern') { } 22 148 170
elsif (not exists $facets{$facet}) { } 148 0 148
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 22 elsif($facet eq 'pattern') { push @{$facets{pattern}}, $value }
507 148 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 271 ▶ if $self->{ignore_facets} || !keys %facets;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ignore_facets"} or not keys %facets 75 196 271
Condition66%2/3
$self->{"ignore_facets"} or not keys %facets
l!l&&r!l&&!r
075196
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 196 my %facets_info = %facets;
518  
519 #
520 # new facets overrule all of the base-class
521 #
522  
523 196 ▶ if(defined $facets{totalDigits} && defined $facets{fractionDigits})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $facets{"totalDigits"} and defined $facets{"fractionDigits"}) 3 193 196
Condition100%3/3
defined $facets{"totalDigits"} and defined $facets{"fractionDigits"}
!ll&&!rl&&r
167263
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 196 my (@early, @late);
530 196 ▶ my $action = $self->actsAs('WRITER') ? 'WRITER' : 'READER';
Branch: 1 branch
BranchTrueFalseTotal
$self->actsAs('WRITER') ? : 94 102 196
531 196 foreach my $facet (keys %facets)
532 { my $h = builtin_facet($where, $self, $facet
533 229 ▶ , $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 2 227 229
534  
535 227 ▶ if($facets_early{$facet})
Branch: 1 branch
BranchTrueFalseTotal
if ($facets_early{$facet}) { } 26 201 227
536 26 { push @early, $h }
537 201 else { push @late, $h }
538 }
539  
540 $is_list
541 196 ▶ ? $self->makeFacetsList($where, $st, \%facets_info, \@early, \@late)
Branch: 1 branch
BranchTrueFalseTotal
$is_list ? : 9 187 196
542 : $self->makeFacets($where, $st, \%facets_info, \@early, \@late);
543 }
544  
545 sub element($;$)
546 1864 ▶{ my ($self, $tree, $is_root) = @_;
Subroutine element: called CC=55 SCAR=40.9
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 1864 my $node = $tree->node;
556 1864 my $parent = $node->parentNode;
557 1864 ▶ my $is_global= $parent
Condition83%5/6
$parent && $parent->isa('XML::LibXML::Element') && $parent->localname eq 'schema'
!ll&&!rl&&r
71013844
$parent and $parent->isa("XML::LibXML::Element")
!ll&&!rl&&r
071857
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 1864 my $where = $tree->path;
562  
563 1864 ▶ 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")) 0 1864 1864
564 or error __x"element has no name nor ref at {where}"
565 , where => $where, _class => 'schema';
566 1864 $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 1864 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 1864 my $abstract = 0;
577 1864 my ($qual, $ns, $fullname);
578  
579 1864 ▶ if($is_global)
Branch: 1 branch
BranchTrueFalseTotal
if ($is_global) { } 844 1020 1864
580 844 ▶ { $ns = $node->getAttribute('targetNamespace')
Condition66%2/3
$node->getAttribute('targetNamespace') || $parent->getAttribute('targetNamespace')
l!l&&r!l&&!r
08368
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 844 $fullname= pack_type $ns, $name;
583 844 my $def = $self->namespaces->find(element => $fullname);
584 844 $context = $self->nsContext($def);
585 844 $qual = $context->{qual_top};
586  
587 # abstract elements are not to be used in messages.
588 844 ▶ $abstract = $self->{abstract_types} eq 'ACCEPT' ? 0 : $def->{abstract};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'abstract_types'} eq 'ACCEPT' ? : 0 844 844
589 }
590 else
591 1020 { $qual = $context->{qual_elem};
592 1020 ▶ $ns = $node->getAttribute('targetNamespace') || $context->{tns};
Condition66%2/3
$node->getAttribute('targetNamespace') || $context->{'tns'}
l!l&&r!l&&!r
010128
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 1020 $fullname = pack_type $ns, $name;
594 }
595  
596 1864 ▶ if(my $form = $node->getAttribute('form'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $form = $node->getAttribute("form")) 8 1856 1864
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 1864 ▶ local $self->{_context} = $context if $is_global;
Branch: 1 branch
BranchTrueFalseTotal
if $is_global 844 1020 1864
605 1864 ▶ my $nodetype = $qual ? $fullname : $name;
Branch: 1 branch
BranchTrueFalseTotal
$qual ? : 247 1617 1864
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 1864 my @sgs;
612 1864 ▶ @sgs = $self->namespaces->findSgMembers($node->localName, $fullname)
Branch: 1 branch
BranchTrueFalseTotal
unless $is_root 1083 781 1864
613 unless $is_root;
614  
615 # Handle re-usable fragments, fight against combinatorial explosions
616  
617 1864 my $nodeid = $node->unique_key; #$node->nodePath.'#'.$fullname;
618 1864 ▶ if(my $already = $self->{_created}{$nodeid})
Branch: 1 branch
BranchTrueFalseTotal
if (my $already = $self->{"_created"}{$nodeid}) 14 1850 1864
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 1850 ▶ if(exists $self->{_nest}{$nodeid})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_nest"}{$nodeid}) 12 1838 1850
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 1838 $self->{_nest}{$nodeid} = undef;
642  
643 # Construct XML tag to use
644  
645 1838 ▶ my $trans = $qual ? 'makeTagQualified' : 'makeTagUnqualified';
Branch: 1 branch
BranchTrueFalseTotal
$qual ? : 247 1591 1838
646 1838 my $tag = $self->$trans($where, $node, $name, $ns);
647  
648 # Construct type processor
649  
650 1838 my ($comptype, $comps);
651 1838 my $nr_childs = $tree->nrChildren;
652 1838 ▶ if(my $isa = $node->getAttribute('type'))
Branch: 3 branches
BranchTrueFalseTotal
if (my $isa = $node->getAttribute('type')) { } 1337 501 1838
elsif ($nr_childs == 0) { } 17 484 501
elsif ($nr_childs != 1) { } 0 484 484
653 { # explicitly names type
654 1337 ▶ $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")) 0 1337 1337
655 or error __x"no childs expected with attribute `type' at {where}"
656 , where => $where, _class => 'schema';
657  
658 1337 $comptype = $self->rel2abs($where, $node, $isa);
659 1337 ▶ $comps = $self->blocked($where, anyType => $comptype)
Condition66%2/3
$self->blocked($where, 'anyType', $comptype) || $self->typeByName($where, $tree, $comptype)
l!l&&r!l&&!r
1813190
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
660 || $self->typeByName($where, $tree, $comptype);
661 }
662 elsif($nr_childs==0)
663 { # default type for substGroups is type of base-class
664 17 my $base_node = $node;
665 17 local $self->{_context};
666 17 ▶ while(my $subst = $base_node->getAttribute('substitutionGroup'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $subst = $base_node->getAttribute("substitutionGroup")) 5 12 17
667 5 { my $subst_elem = $self->rel2abs($where, $base_node, $subst);
668 5 my $base_elem = $self->namespaces->find(element => $subst_elem);
669 5 $self->{_context} = $self->nsContext($base_elem);
670 5 $base_node = $base_elem->{node};
671 5 ▶ my $isa = $base_node->getAttribute('type')
Branch: 1 branch
BranchTrueFalseTotal
my $isa = $base_node->getAttribute("type") or next 0 5 5
672 or next;
673  
674 5 $comptype = $self->rel2abs($where, $base_node, $isa);
675 5 ▶ $comps = $self->blocked($where, complexType => $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
676 || $self->typeByName($where, $tree, $comptype);
677 5 last;
678 }
679 17 ▶ unless($comptype)
Branch: 1 branch
BranchTrueFalseTotal
unless ($comptype) 12 5 17
680 { # no type found, so anyType
681 12 $comptype = $self->anyType($node);
682 12 $comps = $self->typeByName($where, $tree, $comptype);
683 }
684 }
685 elsif($nr_childs!=1)
686 0 { error __x"expected is only one child node at {where}"
687 , where => $where, _class => 'schema';
688 }
689 else # nameless types
690 484 { my $child = $tree->firstChild;
691 484 my $local = $child->localname;
692 484 my $nest = $tree->descend($child);
693  
694 484 ▶ ($comps, $comptype)
Branch: 2 branches
BranchTrueFalseTotal
$local eq 'simpleType' ? : 111 373 484
$local eq 'complexType' ? : 373 0 373
695 = $local eq 'simpleType'
696 ? ($self->simpleType($nest, 0), 'unnamed simple')
697 : $local eq 'complexType'
698 ? ($self->complexType($nest), 'unnamed complex')
699 : error __x"illegal element child `{name}' at {where}"
700 , name => $local, where => $where, _class => 'schema';
701 }
702  
703 my ($st, $elems, $attrs, $attrs_any)
704 1836 = @$comps{ qw/st elems attrs attrs_any/ };
705 1836 ▶ $_ ||= [] for $elems, $attrs, $attrs_any;
Condition100%2/2
$_ ||= []
l!l
16123896
MC/DC100%1/1
$_ ||= []
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
706  
707 # Construct basic element handler
708  
709 1836 my $is_simple = defined $st;
710 1836 ▶ my $nillable = $self->isTrue($node->getAttribute('nillable') || 'false');
Condition100%2/2
$node->getAttribute('nillable') || 'false'
l!l
441792
MC/DC100%1/1
$node->getAttribute('nillable') || 'false'
$node->getAttribute('nillable')
Truth table100%2/2
A
A= $node->getAttribute('nillable')
Aresult
11
00
711  
712 my $elem_handler
713 1836 ▶ = $comps->{mixed} ? 'makeMixedElement'
Branch: 3 branches
BranchTrueFalseTotal
$comps->{'mixed'} ? : 8 1828 1836
!$is_simple ? : 532 1296 1828
@$attrs || @$attrs_any ? : 20 1276 1296
Condition66%2/3
@$attrs or @$attrs_any
l!l&&r!l&&!r
2001276
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
714 : ! $is_simple ? 'makeComplexElement' # other complexType
715 : (@$attrs || @$attrs_any) ? 'makeTaggedElement' # complex/simpleContent
716 : 'makeSimpleElement';
717  
718 1836 ▶ my $r = $self->$elem_handler
Condition66%2/3
$st || $elems
l!l&&r!l&&!r
12965400
MC/DC0%0/2
$st || $elems
$st $elems
Truth table66%2/3
A || B
A= $stB= $elems
ABresult
1X1
011
000
719 ( $where, $tag, ($st||$elems), $attrs, $attrs_any, $comptype, $nillable);
720  
721 # Add defaults and stuff
722 1836 my $default = $node->getAttributeNode('default');
723 1836 my $fixed = $node->getAttributeNode('fixed');
724  
725 1836 ▶ $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 1836 1836
Condition66%2/3
$default and $fixed
!ll&&!rl&&r
1799370
MC/DC0%0/2
$default and $fixed
$default $fixed
Truth table66%2/3
A and B
A= $defaultB= $fixed
ABresult
0X0
100
111
726 and error __x"element can not have default and fixed at {where}"
727 , where => $tree->path, _class => 'schema';
728  
729 1836 ▶ my $value
Branch: 2 branches
BranchTrueFalseTotal
$default ? : 37 1799 1836
$fixed ? : 7 1792 1799
730 = $default ? $default->textContent
731 : $fixed ? $fixed->textContent
732 : undef;
733  
734 1836 ▶ my $generate
Branch: 3 branches
BranchTrueFalseTotal
$abstract ? : 18 1818 1836
$default ? : 37 1781 1818
$fixed ? : 7 1774 1781
735 = $abstract ? 'makeElementAbstract'
736 : $default ? 'makeElementDefault'
737 : $fixed ? 'makeElementFixed'
738 : 'makeElement';
739  
740 1836 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 1836 ▶ if $self->{permit_href} && $self->actsAs('READER');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"permit_href"} and $self->actsAs("READER") 0 1836 1836
Condition33%1/3
$self->{"permit_href"} and $self->actsAs("READER")
!ll&&!rl&&r
183600
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 1836 my ($before, $replace, $after)
748 = $self->findHooks($where, $comptype, $node);
749  
750 1836 ▶ $do = $self->makeHook($where,$do,$tag,$before,$replace,$after,$comptype)
Branch: 1 branch
BranchTrueFalseTotal
if $before or $replace or $after 14 1813 1827
Condition100%6/6
$before or $replace or $after
l!l&&r!l&&!r
1491813
$before or $replace
l!l&&r!l&&!r
951822
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
751 if $before || $replace || $after;
752  
753 $do = $self->xsiType($tree, $node, $name, $comptype, $do)
754 1836 ▶ if $comptype && $self->{xsi_type}{$comptype};
Branch: 1 branch
BranchTrueFalseTotal
if $comptype and $self->{"xsi_type"}{$comptype} 7 1829 1836
Condition66%2/3
$comptype and $self->{"xsi_type"}{$comptype}
!ll&&!rl&&r
018297
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
755  
756 $do = $self->addTypeAttribute($comptype, $do)
757 1836 ▶ if $self->{xsi_type_everywhere} && $comptype !~ /^unnamed /;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"xsi_type_everywhere"} and not $comptype =~ /^unnamed / 1 1835 1836
Condition100%3/3
$self->{"xsi_type_everywhere"} and not $comptype =~ /^unnamed /
!ll&&!rl&&r
183411
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
758  
759 1836 $self->{_created}{$nodeid} = $do;
760  
761 1836 ▶ $do = $self->substitutionGroup($tree, $fullname, $nodetype, $do, \@sgs)
Branch: 1 branch
BranchTrueFalseTotal
if @sgs 19 1817 1836
762 if @sgs;
763  
764 # handle recursion
765 # this must look very silly to you... however, this is resolving
766 # recursive schemas: this way nested use of the same element
767 # definition will catch the code reference of the outer definition.
768 1836 $self->{_nest}{$nodeid} = $do;
769 1836 delete $self->{_nest}{$nodeid}; # clean the outer definition
770  
771 1836 ($nodetype, $do);
772 }
773  
774 sub particle($)
775 1692 ▶{ my ($self, $tree) = @_;
Subroutine particle: called CC=23 SCAR=31.4
Pod undocumented
776  
777 1692 my $node = $tree->node;
778 1692 my $local = $node->localName;
779 1692 my $where = $tree->path;
780  
781 1692 my $min = $node->getAttribute('minOccurs');
782 1692 my $max = $node->getAttribute('maxOccurs');
783  
784 1692 ▶ unless(defined $min)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $min) 1430 262 1692
785 1430 ▶ { $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 1404 1430
Condition100%9/9
$self->actsAs("WRITER") || $self->{"default_values"} ne "EXTEND" and $node->getAttribute("default") || $node->getAttribute("fixed")
!ll&&!rl&&r
77562926
$self->actsAs("WRITER") or $self->{"default_values"} ne "EXTEND"
l!l&&r!l&&!r
64312775
$node->getAttribute("default") or $node->getAttribute("fixed")
l!l&&r!l&&!r
224629
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
786 && ($node->getAttribute('default') || $node->getAttribute('fixed'))
787 ? 0 : 1;
788 }
789  
790 $min = 0 if $self->{interpret_nillable_as_optional}
791 1692 ▶ && $self->isTrue($node->getAttribute('nillable') || 'false');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"interpret_nillable_as_optional"} and $self->isTrue($node->getAttribute("nillable") || "false") 2 1690 1692
Condition100%5/5
$self->{"interpret_nillable_as_optional"} and $self->isTrue($node->getAttribute("nillable") || "false")
!ll&&!rl&&r
168462
$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
792  
793 # default attribute in writer means optional, but we want to see
794 # them in the reader, to see the value.
795
796 1692 ▶ defined $max or $max = 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $max or $max = 1 1552 140 1692
797 $max = 'unbounded'
798 1692 ▶ 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 1686 1692
Condition100%6/6
$max ne "unbounded" and $max > 1 and not $self->{"check_occurs"}
!ll&&!rl&&r
1625616
$max ne "unbounded" and $max > 1
!ll&&!rl&&r
71155467
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
799  
800 $min = 0
801 1692 ▶ if $max eq 'unbounded' && !$self->{check_occurs};
Branch: 1 branch
BranchTrueFalseTotal
if $max eq "unbounded" and not $self->{"check_occurs"} 8 1684 1692
Condition100%3/3
$max eq "unbounded" and not $self->{"check_occurs"}
!ll&&!rl&&r
1615698
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
802  
803 1692 ▶ return $self->anyElement($tree, $min, $max)
Branch: 1 branch
BranchTrueFalseTotal
if $local eq "any" 10 1682 1692
804 if $local eq 'any';
805  
806 1682 ▶ my ($label, $process)
Branch: 3 branches
BranchTrueFalseTotal
$local eq 'element' ? : 1088 594 1682
$local eq 'group' ? : 16 578 594
$local =~ /$particle_blocks/ ? : 578 0 578
807 = $local eq 'element' ? $self->particleElement($tree)
808 : $local eq 'group' ? $self->particleGroup($tree)
809 : $local =~ $particle_blocks ? $self->particleBlock($tree)
810 : error __x"unknown particle type '{name}' at {where}"
811 , name => $local, where => $tree->path, _class => 'schema';
812  
813 1682 ▶ defined $label
Branch: 1 branch
BranchTrueFalseTotal
defined $label or return () 12 1670 1682
814 or return ();
815  
816 1670 ▶ if(ref $process eq 'BLOCK')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $process eq "BLOCK") 611 1059 1670
817 611 { my $key = $self->keyRewrite($label);
818 611 my $multi = $self->blockLabel($local, $key);
819 611 return $self->makeBlockHandler($where, $label, $min, $max
820 , $process, $local, $multi);
821 }
822  
823 # only elements left
824 1059 my $required;
825 1059 my $key = $self->keyRewrite($label);
826 1059 ▶ $required = $self->makeRequired($where, $key, $process) if $min!=0;
Branch: 1 branch
BranchTrueFalseTotal
if $min != 0 851 208 1059
827  
828 1059 ▶ ($self->actsAs('READER') ? $label : $key) =>
Branch: 1 branch
BranchTrueFalseTotal
$self->actsAs('READER') ? : 577 482 1059
829 $self->makeElementHandler($where, $key, $min,$max, $required, $process);
830 }
831  
832 sub particleElement($)
833 1088 ▶{ my ($self, $tree) = @_;
Subroutine particleElement: called CC=4 SCAR=13.9
Pod undocumented
834  
835 1088 my $node = $tree->node;
836 1088 ▶ if(my $ref = $node->getAttribute('ref'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $node->getAttribute("ref")) 75 1013 1088
837 75 { my $where = $tree->path . "/$ref";
838 75 my $refname = $self->rel2abs($tree, $node, $ref);
839 75 ▶ return () if $self->blocked($where, ref => $refname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->blocked($where, "ref", $refname) 12 63 75
840  
841 63 ▶ 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")) 0 63 63
842 or error __x"cannot find ref element '{name}' at {where}"
843 , name => $refname, where => $where, _class => 'schema';
844  
845 return $self->element($tree->descend($def->{node}
846 63 , $self->prefixed($refname, 1)));
847 }
848  
849 1013 my $name = $node->getAttribute('name');
850 1013 $self->element($tree->descend($node, $name));
851 }
852  
853 # blockLabel KIND, LABEL
854 # Particle blocks, like `sequence' and `choice', which have a maxOccurs
855 # (maximum occurrence) which is 2 of more, are represented by an ARRAY
856 # of HASHs. The label with such a block is derived from its first element.
857 # This function determines how.
858 # seq_address sequence get seq_ prepended
859 # cho_gender choices get cho_ before them
860 # all_money an all block can also be repreated in spec >1.1
861 # gr_people group refers to a block of above type, but
862 # that type is not reflected in the name
863  
864 50 my %block_abbrev = qw/sequence seq_ choice cho_ all all_ group gr_/;
865 sub blockLabel($$)
866 611 ▶{ my ($self, $kind, $label) = @_;
Subroutine blockLabel: called CC=2 SCAR=6.9
Pod undocumented
867 611 ▶ return $label if $kind eq 'element';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "element" 17 594 611
868  
869 594 $label =~ s/^(?:seq|cho|all|gr)_//;
870 594 $block_abbrev{$kind} . (unpack_type $label)[1];
871 }
872  
873 sub particleGroup($)
874 16 ▶{ my ($self, $tree) = @_;
Subroutine particleGroup: called CC=7 SCAR=20.6
Pod undocumented
875  
876 # attributes: id, maxOccurs, minOccurs, name, ref
877 # content: annotation?, (all|choice|sequence)?
878 # apparently, a group can not refer to a group... well..
879  
880 16 my $node = $tree->node;
881 16 my $where = $tree->path . '#group';
882 16 ▶ my $ref = $node->getAttribute('ref')
Branch: 1 branch
BranchTrueFalseTotal
my $ref = $node->getAttribute("ref") or &error(&__x("group without ref at {where}", "where", $where, "_class", "schema")) 0 16 16
883 or error __x"group without ref at {where}"
884 , where => $where, _class => 'schema';
885  
886 16 my $typename = $self->rel2abs($where, $node, $ref);
887 16 ▶ if(my $blocked = $self->blocked($where, ref => $typename))
Branch: 1 branch
BranchTrueFalseTotal
if (my $blocked = $self->blocked($where, "ref", $typename)) 0 16 16
888 0 { return ($typename, $blocked);
889 }
890  
891 16 ▶ 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")) 0 16 16
892 or error __x"cannot find group `{name}' at {where}"
893 , name => $typename, where => $where, _class => 'schema';
894  
895 16 my $group = $tree->descend($dest->{node}, $self->prefixed($typename, 1));
896 16 ▶ return () if $group->nrChildren==0;
Branch: 1 branch
BranchTrueFalseTotal
if $group->nrChildren == 0 0 16 16
897  
898 16 ▶ $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")) 0 16 16
899 or error __x"only one particle block expected in group `{name}' at {where}"
900 , name => $typename, where => $where, _class => 'schema';
901  
902 16 my $local = $group->currentLocal;
903 16 ▶ $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")) 0 16 16
904 or error __x"illegal group member `{name}' at {where}"
905 , name => $local, where => $where, _class => 'schema';
906  
907 16 my ($blocklabel, $code) = $self->particleBlock($group->descend);
908 16 ($typename, $code);
909 }
910  
911 sub particleBlock($)
912 594 ▶{ my ($self, $tree) = @_;
Subroutine particleBlock: called CC=2 SCAR=7.0
Pod undocumented
913  
914 594 my $node = $tree->node;
915 594 my @pairs = map $self->particle($tree->descend($_)), $tree->childs;
916 594 ▶ @pairs or return ();
Branch: 1 branch
BranchTrueFalseTotal
@pairs or return () 0 594 594
917  
918 # label is name of first component, only needed when maxOcc > 1
919 594 my $label = $pairs[0];
920 594 my $blocktype = $node->localName;
921  
922 594 my $call = 'make'.ucfirst $blocktype;
923 594 ($label => $self->$call($tree->path, @pairs));
924 }
925  
926 sub xsiType($$$$$)
927 7 ▶{ my ($self, $tree, $node, $name, $type, $base) = @_;
Subroutine xsiType: called CC=5 SCAR=16.1
Pod undocumented
928  
929 7 my %alt = ($type => $base);
930  
931 7 foreach my $alttype (@{$self->{xsi_type}{$type}})
932 11 ▶ { next if $alttype eq $type;
Branch: 1 branch
BranchTrueFalseTotal
if $alttype eq $type 4 7 11
933  
934 7 my ($ns, $local) = unpack_type $alttype;
935 7 my $prefix = $node->lookupNamespacePrefix($ns);
936 7 ▶ defined $prefix
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix or $prefix = $self->_registerNSprefix(undef, $ns, 1) 0 7 7
937 or $prefix = $self->_registerNSprefix(undef, $ns, 1);
938  
939 7 ▶ my $type = length $prefix ? "$prefix:$local" : $local;
Branch: 1 branch
BranchTrueFalseTotal
length $prefix ? : 7 0 7
940  
941 # do not accidentally use the default namespace, when there
942 # may also be namespace-less types used.
943 7 my $doc = $node->ownerDocument;
944 7 my $altnode = $doc->createElement('element');
945 7 $altnode->setNamespace(SCHEMA2001, 'temp1234', 1);
946 7 $altnode->setNamespace($ns, $prefix);
947 7 $altnode->setAttribute(name => $name);
948 7 $altnode->setAttribute(type => $type);
949  
950 7 delete $self->{_created}{$altnode->unique_key}; # clean nesting cache
951 7 (undef, $alt{$alttype}) = $self->element($tree->descend($altnode));
952 }
953 7 $self->makeXsiTypeSwitch($tree->path, $name, $type, \%alt);
954 }
955  
956 sub substitutionGroup($$$$$)
957 19 ▶{ my ($self, $tree, $fullname, $label, $base, $sgs) = @_;
Subroutine substitutionGroup: called CC=5 SCAR=19.8
Pod undocumented
958  
959 19 ▶ if(Log::Report->needs('TRACE')) # dump table of substgroup alternatives
Branch: 1 branch
BranchTrueFalseTotal
if ("Log::Report"->needs("TRACE")) 0 19 19
960 0 { my $labelrw = $self->keyRewrite($label);
961 0 my @full = sort map $_->{full}, @$sgs;
962 0 my $longest = max map length, @full;
963 0 my @c = map sprintf("%-${longest}s %s",$_,$self->keyRewrite($_)), @full;
964 0 local $" = "\n ";
965 0 trace "substitutionGroup $fullname$\"BASE=$label ($labelrw)$\"@c";
966 }
967  
968 19 my @elems;
969 19 ▶ push @elems, $label => [$self->keyRewrite($label), $base] if $base;
Branch: 1 branch
BranchTrueFalseTotal
if $base 19 0 19
970  
971 19 foreach my $subst (@$sgs)
972 36 { my ($l, $d) = $self->element($tree->descend($subst->{node}), 1);
973 36 ▶ push @elems, $l => [$self->keyRewrite($l), $d] if defined $d;
Branch: 1 branch
BranchTrueFalseTotal
if defined $d 36 0 36
974 }
975  
976 19 $self->makeSubstgroup($tree->path.'#subst', $fullname, @elems);
977 }
978  
979 sub keyRewrite($;$)
980 2067 ▶{ my $self = shift;
Subroutine keyRewrite: called CC=16 SCAR=31.4
Pod undocumented
981 2067 ▶ my ($ns, $key) = @_==1 ? unpack_type($_[0]) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 1725 342 2067
982 2067 my $oldkey = $key;
983  
984 2067 foreach my $r ( @{$self->{rewrite}} )
985 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
986 14 { my $full = pack_type $ns, $key;
987 14 ▶ $key = $r->{$full} if defined $r->{$full};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{$full} 4 10 14
988 14 ▶ $key = $r->{$key} if defined $r->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{$key} 0 14 14
989 }
990 elsif(ref $r eq 'CODE')
991 51 { $key = $r->($ns, $key);
992 }
993 elsif($r eq 'UNDERSCORES')
994 0 { $key =~ s/-/_/g;
995 }
996 elsif($r eq 'SIMPLIFIED')
997 21 { $key =~ s/-/_/g;
998 21 $key =~ s/\W//g;
999 21 $key = lc $key;
1000 }
1001 elsif($r eq 'PREFIXED')
1002 29 { my $p = $self->{prefixes};
1003 29 ▶ my $prefix = $p->{$ns} ? $p->{$ns}{prefix} : '';
Branch: 1 branch
BranchTrueFalseTotal
$p->{$ns} ? : 25 4 29
1004 29 ▶ $key = $prefix . '_' . $key if $prefix ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $prefix ne "" 17 12 29
1005 }
1006 elsif($r =~ m/^PREFIXED\(\s*(.*?)\s*\)$/)
1007 0 { my @l = split /\s*\,\s*/, $1;
1008 0 my $p = $self->{prefixes};
1009 0 ▶ my $prefix = $p->{$ns} ? $p->{$ns}{prefix} : '';
Branch: 1 branch
BranchTrueFalseTotal
$p->{$ns} ? : 0 0 0
1010 0 ▶ $key = $prefix . '_' . $key if grep {$prefix eq $_} @l;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$prefix eq $_;} @l 0 0 0
1011 }
1012 else
1013 0 { error __x"key rewrite `{got}' not understood", got => $r;
1014 }
1015 }
1016  
1017 2067 ▶ trace "rewrote type @_ to $key"
Branch: 1 branch
BranchTrueFalseTotal
if $key ne $oldkey 69 1998 2067
1018 if $key ne $oldkey;
1019  
1020 2067 $key;
1021 }
1022  
1023 sub prefixed($;$)
1024 972 ▶{ my ($self, $qname, $hide) = @_;
Subroutine prefixed: called CC=5 SCAR=16.1
Pod undocumented
1025 972 my ($ns, $local) = unpack_type $qname;
1026 972 ▶ defined $ns or return $qname;
Branch: 1 branch
BranchTrueFalseTotal
defined $ns or return $qname 0 972 972
1027  
1028 972 ▶ my $pn = $self->{prefixes}{$ns} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $pn = $self->{"prefixes"}{$ns} or return 711 261 972
1029 261 ▶ $pn->{used}++ unless $hide ;
Branch: 1 branch
BranchTrueFalseTotal
unless $hide 138 123 261
1030 261 ▶ length $pn->{prefix} ? "$pn->{prefix}:$local" : $local;
Branch: 1 branch
BranchTrueFalseTotal
length $pn->{'prefix'} ? : 225 36 261
1031 }
1032  
1033 sub prefixForNamespace($)
1034 8 ▶{ my ($self, $ns) = @_;
Subroutine prefixForNamespace: called CC=2 SCAR=7.1
Pod undocumented
1035 8 ▶ my $def = $self->{prefixes}{$ns} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $def = $self->{"prefixes"}{$ns} or return 0 8 8
1036 8 $def->{prefix};
1037 }
1038  
1039 sub attribute($)
1040 259 ▶{ my ($self, $tree) = @_;
Subroutine attribute: called CC=32 SCAR=36.3
Pod undocumented
1041  
1042 # attributes: default, fixed, form, id, name, ref, type, use
1043 # content: annotation?, simpleType?
1044  
1045 259 my $node = $tree->node;
1046 259 my $parent = $node->parentNode;
1047 259 ▶ my $is_global= $parent && $parent->localname eq 'schema';
Condition66%2/3
$parent && $parent->localname eq 'schema'
!ll&&!rl&&r
024613
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
1048 259 my $where = $tree->path;
1049  
1050 259 my $context = $self->{_context};
1051  
1052 259 ▶ if(my $refattr = $node->getAttribute('ref'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $refattr = $node->getAttribute("ref")) 5 254 259
1053 {
1054 5 my $refname = $self->rel2abs($tree, $node, $refattr);
1055 5 ▶ return () if $self->blocked($where, ref => $refname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->blocked($where, "ref", $refname) 0 5 5
1056  
1057 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")) 0 5 5
1058 or error __x"cannot find attribute {name} at {where}"
1059 , name => $refname, where => $where, _class => 'schema';
1060  
1061 5 local $self->{_context} = $def;
1062 5 return $self->attribute($tree->descend($def->{node}));
1063 }
1064  
1065 # Not a ref to attribute
1066 254 ▶ my $name = $node->getAttribute('name')
Branch: 1 branch
BranchTrueFalseTotal
my $name = $node->getAttribute("name") or &error(&__x("attribute without name at {where}", "where", $where)) 0 254 254
1067 or error __x"attribute without name at {where}", where => $where;
1068 254 $where .= '/@'.$name;
1069 254 $self->assertType($where, name => NCName => $name);
1070  
1071 254 my ($qual, $ns, $fullname);
1072 254 ▶ if($is_global)
Branch: 1 branch
BranchTrueFalseTotal
if ($is_global) { } 13 241 254
1073 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
1074 || $parent->getAttribute('targetNamespace');
1075 13 $fullname= pack_type $ns, $name;
1076 13 my $def = $self->namespaces->find(attribute => $fullname);
1077 13 $context = $self->nsContext($def);
1078 13 $qual = $context->{qual_top};
1079 }
1080 else
1081 241 { $qual = $context->{qual_attr};
1082 241 $ns = $context->{tns};
1083 241 $fullname= pack_type $ns, $name;
1084 }
1085 254 ▶ local $self->{_context} = $context if $is_global;
Branch: 1 branch
BranchTrueFalseTotal
if $is_global 13 241 254
1086  
1087 254 ▶ if(my $form = $node->getAttribute('form'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $form = $node->getAttribute("form")) 0 254 254
1088 0 ▶ { $qual
Branch: 2 branches
BranchTrueFalseTotal
$form eq 'qualified' ? : 0 0 0
$form eq 'unqualified' ? : 0 0 0
1089 = $form eq 'qualified' ? 1
1090 : $form eq 'unqualified' ? 0
1091 : error __x"form must be (un)qualified, not `{form}' at {where}"
1092 , form => $form, where => $where, _class => 'schema';
1093 }
1094  
1095 # no default prefixes for attributes
1096 254 ▶ error __x"attribute namespace {ns} cannot be the default namespace"
Branch: 1 branch
BranchTrueFalseTotal
if $qual and $ns and $self->prefixForNamespace($ns) eq "" 0 254 254
Condition66%4/6
$qual and $ns and $self->prefixForNamespace($ns) eq ""
!ll&&!rl&&r
24680
$qual and $ns
!ll&&!rl&&r
24608
MC/DC0%0/3
$qual and $ns and $self->prefixForNamespace($ns) eq ""
$qual $ns $self->prefixForNamespace($ns) eq ""
Truth table50%2/4
A and B and C
A= $qualB= $nsC= $self->prefixForNamespace($ns) eq ""
ABCresult
0XX0
10X0
1100
1111
1097 , ns => $ns
1098 if $qual && $ns && $self->prefixForNamespace($ns) eq '';
1099
1100 254 my ($type, $typeattr);
1101 254 ▶ if($tree->nrChildren==1)
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->nrChildren == 1) { } 7 247 254
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")) 0 7 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 247 ▶ { $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")) 0 247 247
1111 or error __x"attribute without name or ref at {where}"
1112 , where => $where, _class => 'schema';
1113  
1114 247 $typeattr = $node->getAttribute('type');
1115 }
1116  
1117 254 ▶ unless($type)
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 247 7 254
1118 247 ▶ { my $typename = defined $typeattr
Branch: 1 branch
BranchTrueFalseTotal
defined $typeattr ? : 244 3 247
1119 ? $self->rel2abs($where, $node, $typeattr)
1120 : $self->anyType($node);
1121  
1122 247 ▶ $type = $self->blocked($where, simpleType => $typename)
Condition66%2/3
$self->blocked($where, 'simpleType', $typename) || $self->typeByName($where, $tree, $typename)
l!l&&r!l&&!r
22450
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 254 ▶ 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")) 0 254 254
1128 , where => $where, _class => 'schema';
1129  
1130 254 ▶ my $trans = $qual ? 'makeTagQualified' : 'makeTagUnqualified';
Branch: 1 branch
BranchTrueFalseTotal
$qual ? : 8 246 254
1131 254 ▶ my $qns = $qual ? $context->{tns} : '';
Branch: 1 branch
BranchTrueFalseTotal
$qual ? : 8 246 254
1132 254 my $tag = $self->$trans($where, $node, $name, $qns);
1133  
1134 254 ▶ my $use = $node->getAttribute('use') || '';
Condition100%2/2
$node->getAttribute('use') || ''
l!l
47207
MC/DC100%1/1
$node->getAttribute('use') || ''
$node->getAttribute('use')
Truth table100%2/2
A
A= $node->getAttribute('use')
Aresult
11
00
1135 254 ▶ $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")) 0 254 254
1136 or error __x"attribute use is required, optional or prohibited (not '{use}') at {where}"
1137 , use => $use, where => $where, _class => 'schema';
1138  
1139 254 my $default = $node->getAttributeNode('default');
1140 254 my $fixed = $node->getAttributeNode('fixed');
1141  
1142 254 ▶ my $generate
Branch: 4 branches
BranchTrueFalseTotal
defined $default ? : 14 240 254
defined $fixed ? : 11 229 240
$use eq 'required' ? : 29 200 229
$use eq 'prohibited' ? : 6 194 200
1143 = defined $default ? 'makeAttributeDefault'
1144 : defined $fixed ? 'makeAttributeFixed'
1145 : $use eq 'required' ? 'makeAttributeRequired'
1146 : $use eq 'prohibited'? 'makeAttributeProhibited'
1147 : 'makeAttribute';
1148  
1149 254 ▶ my $value = defined $default ? $default : $fixed;
Branch: 1 branch
BranchTrueFalseTotal
defined $default ? : 14 240 254
1150 254 my $label = $self->keyRewrite($qns, $name);
1151 254 my $do = $self->$generate($where, $qns, $tag, $label, $st, $value);
1152 254 ▶ defined $do ? ($label => $do) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $do ? : 254 0 254
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")) 0 6 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")) 0 6 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 592 ▶{ 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 592 my $node = $tree->node;
1278 592 ▶ my $mixed = $self->isTrue($node->getAttribute('mixed') || 'false');
Condition100%2/2
$node->getAttribute('mixed') || 'false'
l!l
9583
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 592 ▶ if $self->{mixed_elements} eq 'STRUCTURAL';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"mixed_elements"} eq "STRUCTURAL" 1 591 592
1281  
1282 592 ▶ my $first = $tree->firstChild
Branch: 1 branch
BranchTrueFalseTotal
my $first = $tree->firstChild or return {"elems", [], "mixed", $mixed} 24 568 592
1283 or return {elems => [], mixed => $mixed};
1284  
1285 568 my $name = $first->localName;
1286 568 ▶ return $self->complexBody($tree, $mixed)
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /$particle_blocks/ or $name =~ /$attribute_defs/ 512 56 568
Condition100%3/3
$name =~ /$particle_blocks/ or $name =~ /$attribute_defs/
l!l&&r!l&&!r
4803256
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")) 0 56 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 544 ▶{ my ($self, $tree, $mixed) = @_;
Subroutine complexBody: called CC=4 SCAR=14.0
Pod undocumented
1305  
1306 544 ▶ $tree->currentChild
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentChild or return () 0 544 544
1307 or return ();
1308  
1309 # partial
1310 # (group|all|choice|sequence)?
1311 # , ((attribute|attributeGroup)*
1312 # , anyAttribute?
1313  
1314 544 my @elems;
1315 544 ▶ if($tree->currentLocal =~ $particle_blocks)
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->currentLocal =~ /$particle_blocks/) 512 32 544
1316 512 { push @elems, $self->particle($tree->descend); # unless $mixed;
1317 512 $tree->nextChild;
1318 }
1319  
1320 544 my @attrs = $self->attributeList($tree);
1321  
1322 544 ▶ 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 544 544
1323 and error __x"trailing non-attribute `{name}' at {where}"
1324 , name => $tree->currentChild->localName, where => $tree->path
1325 , _class => 'schema';
1326  
1327 544 {elems => \@elems, mixed => $mixed, @attrs};
1328 }
1329  
1330 sub attributeList($)
1331 572 ▶{ my ($self, $tree) = @_;
Subroutine attributeList: called CC=5 SCAR=16.1
Pod undocumented
1332  
1333 # partial content
1334 # ((attribute|attributeGroup)*
1335 # , anyAttribute?
1336  
1337 572 my $where = $tree->path;
1338  
1339 572 my (@attrs, @any);
1340 572 ▶ for(my $attr = $tree->currentChild; defined $attr; $attr = $tree->nextChild)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr) 262 562 824
1341 262 { my $name = $attr->localName;
1342 262 ▶ if($name eq 'attribute')
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'attribute') { } 246 16 262
elsif ($name eq 'attributeGroup') { } 6 10 16
1343 246 { 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 572 ▶ while($tree->currentLocal eq 'anyAttribute')
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->currentLocal eq "anyAttribute") 10 572 582
1355 10 { push @any, $self->anyAttribute($tree->descend);
1356 10 $tree->nextChild;
1357 }
1358  
1359 572 (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")) 0 22 22
1369 or error __x"need one simpleContent child at {where}"
1370 , where => $tree->path, _class => 'schema';
1371  
1372 22 my $name = $tree->currentLocal;
1373 22 ▶ return $self->simpleContentExtension($tree->descend)
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "extension" 14 8 22
1374 if $name eq 'extension';
1375  
1376 8 ▶ return $self->simpleContentRestriction($tree->descend)
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "restriction" 8 0 8
1377 if $name eq 'restriction';
1378  
1379 0 error __x"simpleContent needs extension or restriction, not `{name}' at {where}"
1380 , name => $name, where => $tree->path, _class => 'schema';
1381 }
1382  
1383 sub simpleContentExtension($)
1384 14 ▶{ my ($self, $tree) = @_;
Subroutine simpleContentExtension: called CC=5 SCAR=17.0
Pod undocumented
1385  
1386 # attributes: id, base = QName
1387 # content: annotation?
1388 # , (attribute | attributeGroup)*
1389 # , anyAttribute?
1390 # , (assert | report)*
1391  
1392 14 my $node = $tree->node;
1393 14 my $where = $tree->path . '#sext';
1394  
1395 14 my $base = $node->getAttribute('base');
1396 14 ▶ my $typename = defined $base ? $self->rel2abs($where, $node, $base)
Branch: 1 branch
BranchTrueFalseTotal
defined $base ? : 14 0 14
1397 : $self->anyType($node);
1398  
1399 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
1400 || $self->typeByName($where, $tree, $typename);
1401 defined $basetype->{st}
1402 14 ▶ or error __x"base of simpleContent not simple at {where}"
Branch: 1 branch
BranchTrueFalseTotal
defined $basetype->{"st"} or &error(&__x("base of simpleContent not simple at {where}", "where", $where, "_class", "schema")) 0 14 14
1403 , where => $where, _class => 'schema';
1404
1405 14 $self->extendAttrs($basetype, {$self->attributeList($tree)});
1406  
1407 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
1408 and error __x"elements left at tail at {where}"
1409 , where => $tree->path, _class => 'schema';
1410  
1411 14 $basetype;
1412 }
1413  
1414 sub simpleContentRestriction($$)
1415 8 ▶{ my ($self, $tree) = @_;
Subroutine simpleContentRestriction: called CC=7 SCAR=20.4
Pod undocumented
1416  
1417 # attributes id, base = QName
1418 # content: annotation?
1419 # , (simpleType?, facet*)?
1420 # , (attribute | attributeGroup)*, anyAttribute?
1421 # , (assert | report)*
1422  
1423 8 my $node = $tree->node;
1424 8 my $where = $tree->path . '#cres';
1425  
1426 8 my ($type, $typename);
1427 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
1428 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
1429 4 { $type = $self->simpleType($tree->descend);
1430 4 $tree->nextChild;
1431 }
1432 elsif(my $basename = $node->getAttribute('base'))
1433 4 { $typename = $self->rel2abs($where, $node, $basename);
1434 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
1435 || $self->typeByName($where, $tree, $typename);
1436 }
1437 else
1438 0 { error __x"no base in complex-restriction, so simpleType required at {where}"
1439 , where => $where, _class => 'schema';
1440 }
1441  
1442 my $st = $type->{st}
1443 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")) 0 8 8
1444 , where => $where, _class => 'schema';
1445  
1446 8 $type->{st} = $self->applySimpleFacets($tree, $st, 0, $typename);
1447  
1448 8 $self->extendAttrs($type, {$self->attributeList($tree)});
1449  
1450 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
1451 and error __x"elements left at tail at {where}"
1452 , where => $where, _class => 'schema';
1453  
1454 8 $type;
1455 }
1456  
1457 sub complexContent($$)
1458 33 ▶{ my ($self, $tree, $mixed) = @_;
Subroutine complexContent: called CC=13 SCAR=27.0
Pod undocumented
1459  
1460 # attributes: id, mixed = boolean
1461 # content: annotation?, (restriction | extension)
1462  
1463 33 my $node = $tree->node;
1464 33 ▶ if(my $m = $node->getAttribute('mixed'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $m = $node->getAttribute("mixed")) 0 33 33
1465 { $mixed = $self->isTrue($m)
1466 0 ▶ if $self->{mixed_elements} ne 'STRUCTURAL';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"mixed_elements"} ne "STRUCTURAL" 0 0 0
1467 }
1468  
1469 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")) 0 33 33
1470 or error __x"only one complexContent child expected at {where}"
1471 , where => $tree->path, _class => 'schema';
1472  
1473 33 my $name = $tree->currentLocal;
1474 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
1475 , name => $name, where => $tree->path, _class => 'schema'
1476 if $name ne 'extension' && $name ne 'restriction';
1477  
1478 32 $tree = $tree->descend;
1479 32 $node = $tree->node;
1480 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
1481 32 my $type = {};
1482 32 my $where = $tree->path . '#cce';
1483  
1484 32 ▶ if($base !~ m/\banyType$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($base =~ /\banyType$/) 32 0 32
1485 32 { my $typename = $self->rel2abs($where, $node, $base);
1486 32 ▶ if($type = $self->blocked($where, complexType => $typename))
Branch: 1 branch
BranchTrueFalseTotal
if ($type = $self->blocked($where, 'complexType', $typename)) { } 4 28 32
1487 { # blocked base type
1488 }
1489 else
1490 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")) 0 28 28
1491 or error __x"unknown base type '{type}' at {where}"
1492 , type => $typename, where => $tree->path, _class => 'schema';
1493  
1494 28 local $self->{_context} = $self->nsContext($typedef);
1495 28 $type = $self->complexType($tree->descend($typedef->{node}));
1496 }
1497 }
1498  
1499 32 my $own = $self->complexBody($tree, $mixed);
1500 32 $self->extendAttrs($type, $own);
1501  
1502 32 ▶ if($name eq 'extension')
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'extension') { } 28 4 32
1503 28 ▶ { push @{$type->{elems}}, @{$own->{elems} || []};
Branch: 1 branch
BranchTrueFalseTotal
$own->{"elems"} or [] 0 28 28
1504 }
1505 else # restriction
1506 4 { $type->{elems} = $own->{elems};
1507 }
1508  
1509 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
1510 32 $type;
1511 }
1512  
1513 #
1514 # Helper routines
1515 #
1516  
1517 # print $self->rel2abs($path, $node, '{ns}type') -> '{ns}type'
1518 # print $self->rel2abs($path, $node, 'prefix:type') -> '{ns-of-prefix}type'
1519  
1520 sub rel2abs($$$)
1521 2075 ▶{ my ($self, $where, $node, $type) = @_;
Subroutine rel2abs: called CC=6 SCAR=18.2
Pod undocumented
1522 2075 ▶ return $type if substr($type, 0, 1) eq '{';
Branch: 1 branch
BranchTrueFalseTotal
if substr($type, 0, 1) eq "{" 0 2075 2075
1523  
1524 2075 ▶ my ($prefix, $local) = $type =~ m/^(.+?)\:(.*)/ ? ($1, $2) : ('', $type);
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /^(.+?)\:(.*)/ ? : 583 1492 2075
1525 2075 my $uri = $node->lookupNamespaceURI($prefix);
1526 2075 ▶ $self->_registerNSprefix($prefix, $uri, 0) if $uri;
Branch: 1 branch
BranchTrueFalseTotal
if $uri 2071 4 2075
1527  
1528 2075 ▶ error __x"No namespace for prefix `{prefix}' in `{type}' at {where}"
Branch: 1 branch
BranchTrueFalseTotal
if length $prefix and not defined $uri 0 2075 2075
Condition66%2/3
length $prefix and not defined $uri
!ll&&!rl&&r
14925830
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
1529 , prefix => $prefix, type => $type, where => $where, _class => 'schema'
1530 if length $prefix && !defined $uri;
1531  
1532 2075 pack_type $uri, $local;
1533 }
1534  
1535 sub _registerNSprefix($$$)
1536 2313 ▶{ my ($self, $prefix, $uri, $used) = @_;
Subroutine _registerNSprefix: called CC=6 SCAR=18.0
1537 2313 my $table = $self->{prefixes};
1538  
1539 2313 ▶ if(my $u = $table->{$uri}) # namespace already has a prefix
Branch: 1 branch
BranchTrueFalseTotal
if (my $u = $table->{$uri}) 1204 1109 2313
1540 1204 { $u->{used} += $used;
1541 1204 return $u->{prefix};
1542 }
1543  
1544 1109 my %prefs = map +($_->{prefix} => 1), values %$table;
1545 1109 my $take;
1546 1109 ▶ if(defined $prefix && !$prefs{$prefix}) { $take = $prefix }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $prefix and not $prefs{$prefix}) { } 700 409 1109
elsif (not $prefs{''}) { } 0 409 409
Condition66%2/3
defined $prefix and not $prefs{$prefix}
!ll&&!rl&&r
0409700
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
1547 0 elsif(!$prefs{''}) { $take = '' }
1548 else
1549 { # prefix already in use; create a new x\d+ prefix
1550 409 my $count = 0;
1551 409 ▶ $count++ while exists $prefs{"x$count"};
Branch: 1 branch
BranchTrueFalseTotal
exists $prefs{"x$count"} and do { ++$count } 5 409 414
1552 409 $take = 'x'.$count;
1553 }
1554 1109 $table->{$uri} = {prefix => $take, uri => $uri, used => $used};
1555 1109 $take;
1556 }
1557  
1558 sub anyType($)
1559 15 ▶{ my ($self, $node) = @_;
Subroutine anyType: called CC=1 SCAR=0.0
Pod undocumented
1560 15 pack_type $node->namespaceURI, 'anyType';
1561 }
1562  
1563 sub findHooks($$$)
1564 1836 ▶{ my ($self, $path, $type, $node) = @_;
Subroutine findHooks: called CC=28 SCAR=35.0
Pod undocumented
1565 # where is before, replace, after
1566  
1567 1836 my %hooks;
1568 1836 foreach my $hook (@{$self->{hooks}})
1569 61 { my $match;
1570  
1571 $match++
1572 if !$hook->{path} && !$hook->{id}
1573 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
1574  
1575 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
1576 8 { my $p = $hook->{path};
1577 $match++
1578 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
1579 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
1580 }
1581  
1582 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
1583 61 ▶ if($id)
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 15 46 61
1584 15 { my $i = $hook->{id};
1585 $match++
1586 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
1587 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
1588 }
1589  
1590 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
1591 36 { my $t = $hook->{type};
1592 36 my ($ns, $local) = unpack_type $type;
1593 $match++
1594 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
1595 : substr($_,0,1) eq '{' ? $type eq $_
1596 : $local eq $_
1597 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
1598 }
1599  
1600 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
1601 0 ▶ { $match++ if $self->{nss}->doesExtend($type, $hook->{extends});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"nss"}->doesExtend($type, $hook->{"extends"}) 0 0 0
1602 }
1603  
1604 61 ▶ $match or next;
Branch: 1 branch
BranchTrueFalseTotal
$match or next 38 23 61
1605  
1606 23 foreach my $where ( qw/before replace after/ )
1607 69 ▶ { my $w = $hook->{$where} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $w = $hook->{$where} or next 40 29 69
1608 29 ▶ push @{$hooks{$where}}, ref $w eq 'ARRAY' ? @$w : $w;
Branch: 1 branch
BranchTrueFalseTotal
ref $w eq 'ARRAY' ? : 4 25 29
1609 }
1610 }
1611  
1612 1836 @hooks{ qw/before replace after/ };
1613 }
1614  
1615 # Namespace blocks, in most cases because the schema refers to an
1616 # older version of itself, which is deprecated.
1617 # performance is important, because it is called increadably often.
1618  
1619 sub decodeBlocked($)
1620 755 ▶{ my ($self, $what) = @_;
Subroutine decodeBlocked: called CC=7 SCAR=25.7
Pod undocumented
1621 755 ▶ defined $what or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $what or return 0 755 755
1622 755 my @blocked; # code-refs called with ($type, $ns, $local, $path)
1623 755 ▶ foreach my $w (ref $what eq 'ARRAY' ? @$what : $what)
Branch: 1 branch
BranchTrueFalseTotal
ref $what eq 'ARRAY' ? : 755 0 755
1624 { push @blocked,
1625 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 86 0 86
1626 : ref $w eq 'HASH'
1627 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
1628 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
1629 : error __x"blocking rule with {what} not supported", what => $w;
1630 }
1631 755 \@blocked;
1632 }
1633  
1634 sub blocked($$$)
1635 2073 ▶{ my ($self, $path, $class, $type) = @_;
Subroutine blocked: called CC=5 SCAR=16.1
Pod undocumented
1636 # $class = simpleType, complexType, or ref
1637 2073 ▶ @{$self->{blocked_nss}} or return ();
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{"blocked_nss"};} or return () 1987 86 2073
1638  
1639 86 my ($ns, $local) = unpack_type $type;
1640 86 my $is_blocked;
1641 86 foreach my $blocked ( @{$self->{blocked_nss}} )
1642 86 { $is_blocked = $blocked->($type, $ns, $local, $path);
1643 86 ▶ last if defined $is_blocked;
Branch: 1 branch
BranchTrueFalseTotal
if defined $is_blocked 86 0 86
1644 }
1645 86 ▶ $is_blocked or return;
Branch: 1 branch
BranchTrueFalseTotal
$is_blocked or return 48 38 86
1646  
1647 38 trace "$type of $class is blocked";
1648 38 $self->makeBlocked($path, $class, $type);
1649 }
1650  
1651 sub addTypeAttribute($$)
1652 0 ▶{ my ($self, $type, $call) = @_;
Subroutine addTypeAttribute: not called CC=1 SCAR=6.9
Pod undocumented
1653 0 $call;
1654 }
1655  
1656 #------------
1657  
1658 50 1;
« lib/XML/Compile.pm ↑ Summary lib/XML/Compile/Schema.pm »