lib/XML/Compile/Translate/Reader.pm

filter: Statementstmt 88.8% 611 / 688 Branchbran 70.1% 387 / 552 Conditioncond 61.6% 124 / 201 MC/DCmcdc 39.5% 47 / 119 Subroutinesub 90.1% 137 / 152 Podpod 0.0% 0 / 39 totaltotal 74.5% 1306 / 1751 CC 364 SCAR 21.5
CC
364
Cov
78%
__ANON__
72.0
__ANON__
42.0
__ANON__
34.1
CRAP 8.6
« lib/XML/Compile/Schema/Specs.pm ↑ Summary blib/lib/XML/Compile/Schema/BuiltInTypes.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::Reader;
10 44 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 44 $VERSION = '1.60';
12  
13 44 ▶use base 'XML::Compile::Translate';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 44 ▶no warnings 'once', 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 44 ▶use Log::Report 'xml-compile';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 44 ▶use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 44 ▶use Scalar::Util qw/weaken blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 44 ▶use XML::Compile::Util qw/pack_type odd_elements type_of_node SCHEMA2001i/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 44 ▶use XML::Compile::Iterator ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27  
28 # Each action implementation returns a code reference, which will be
29 # used to do the run-time work. The mechanism of `closures' is used to
30 # keep the important information. Be sure that you understand closures
31 # before you attempt to change anything.
32  
33 # The returned reader subroutines will always be called
34 # my @pairs = $reader->($tree);
35  
36 # Some error messages are labeled with 'misfit' which is used to indicate
37 # that the structure of found data is not conforming the needs. For optional
38 # blocks, these errors are caught and un-done.
39  
40 1317 ▶sub actsAs($) {$_[1] eq 'READER'}
Subroutine actsAs: called CC=1 SCAR=0.0
Pod undocumented
41 917 ▶sub makeTagUnqualified(@) {$_[3]} # ($self, $path, $node, $local, $ns)
Subroutine makeTagUnqualified: called CC=1 SCAR=0.0
Pod undocumented
42 118 ▶sub makeTagQualified(@) {$_[3]} # same params
Subroutine makeTagQualified: called CC=1 SCAR=0.0
Pod undocumented
43  
44 sub typemapToHooks($$)
45 378 ▶{ my ($self, $hooks, $typemap) = @_;
Subroutine typemapToHooks: called CC=8 SCAR=20.9
Pod undocumented
46 378 ▶ while(my($type, $action) = each %$typemap)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$typemap) 3 378 381
47 3 ▶ { defined $action or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $action or next 0 3 3
48 3 my $hook;
49 3 ▶ if(!ref $action)
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $action) { } 1 2 3
elsif (ref $action eq 'CODE') { } 1 1 2
50 1 { my $class = $action;
51 44 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶ keys %{$class.'::'}
Branch: 1 branch
BranchTrueFalseTotal
keys %{$class . '::';} or &error(&__x("class {pkg} for typemap {type} is not loaded", "pkg", $class, "type", $type)) 0 1 1
53 or error __x"class {pkg} for typemap {type} is not loaded"
54 , pkg => $class, type => $type;
55  
56 1 ▶ $class->can('fromXML')
Branch: 1 branch
BranchTrueFalseTotal
$class->can("fromXML") or &error(&__x("class {pkg} does not implement fromXML(), required for typemap {type}", "pkg", $class, "type", $type)) 0 1 1
57 or error __x"class {pkg} does not implement fromXML(), required for typemap {type}"
58 , pkg => $class, type => $type;
59  
60 1 trace "created reader hook for type $type to class $class";
61 1 ▶ $hook = sub { $class->fromXML($_[1], $type) };
Subroutine __ANON__: called CC=1 SCAR=0.0
62 }
63 elsif(ref $action eq 'CODE')
64 1 ▶ { $hook = sub { $action->(READER => $_[1], $type) };
Subroutine __ANON__: called CC=1 SCAR=0.0
65 1 trace "created reader hook for type $type to CODE";
66 }
67 else
68 1 { my $object = $action;
69 1 ▶ $object->can('fromXML')
Branch: 1 branch
BranchTrueFalseTotal
$object->can("fromXML") or &error(&__x("object of class {pkg} does not implement fromXML(), required for typemap {type}", "pkg", ref $object, "type", $type)) 0 1 1
70 or error __x"object of class {pkg} does not implement fromXML(), required for typemap {type}"
71 , pkg => ref($object), type => $type;
72  
73 1 trace "created reader hook for type $type to object";
74 1 ▶ $hook = sub {$object->fromXML($_[1], $type)};
Subroutine __ANON__: called CC=1 SCAR=0.0
75 }
76  
77 3 push @$hooks, +{action => 'READER', type => $type, after => $hook};
78 }
79 378 $hooks;
80 }
81  
82 sub makeElementWrapper
83 372 ▶{ my ($self, $path, $processor) = @_;
Subroutine makeElementWrapper: called CC=1 SCAR=0.3
Pod undocumented
84 # no copy of $_[0], because it may be a large string
85 379 ▶ sub { my $tree;
Subroutine __ANON__: called CC=6 SCAR=20.2
86 379 ▶ if(blessed $_[0] && $_[0]->isa('XML::LibXML::Iterator'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_[0]) and $_[0]->isa('XML::LibXML::Iterator')) { } 0 379 379
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa("XML::LibXML::Iterator")
!ll&&!rl&&r
37900
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa("XML::LibXML::Iterator")
builtin::blessed($_[0]) $_[0]->isa("XML::LibXML::Iterator")
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("XML::LibXML::Iterator")
ABresult
0X0
100
111
87 0 { $tree = $_[0];
88 }
89 else
90 379 ▶ { my $xml = XML::Compile->dataToXML($_[0])
Branch: 1 branch
BranchTrueFalseTotal
my $xml = "XML::Compile"->dataToXML($_[0]) or return () 1 378 379
91 or return ();
92 378 ▶ $xml = $xml->documentElement
Branch: 1 branch
BranchTrueFalseTotal
if $xml->isa("XML::LibXML::Document") 0 378 378
93 if $xml->isa('XML::LibXML::Document');
94 $tree = XML::Compile::Iterator->new($xml, 'top',
95 378 ▶ sub { $_[0]->isa('XML::LibXML::Element') } );
Subroutine __ANON__: called CC=1 SCAR=0.0
96 }
97  
98 378 my $data = ($processor->($tree))[-1];
99 314 ▶ unless(defined $data)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 0 314 314
100 0 { my $node = $tree->node;
101 0 error __x"data not recognized, found a `{type}' at {where}"
102 , type => type_of_node $node, where => $node->nodePath;
103 }
104 314 $data;
105 372 };
106 }
107  
108 sub makeAttributeWrapper
109 4 ▶{ my ($self, $path, $processor) = @_;
Subroutine makeAttributeWrapper: called CC=1 SCAR=0.6
Pod undocumented
110  
111 4 ▶ sub { my $attr = shift;
Subroutine __ANON__: called CC=4 SCAR=17.2
112 4 ▶ ref $attr && $attr->isa('XML::LibXML::Attr')
Branch: 1 branch
BranchTrueFalseTotal
ref $attr and $attr->isa("XML::LibXML::Attr") or &error(&__x("expects an attribute node, but got `{something}' at {path}", "something", ref $attr || $attr, "path", $path)) 0 4 4
Condition16%1/6
ref $attr and $attr->isa("XML::LibXML::Attr")
!ll&&!rl&&r
004
ref $attr || $attr
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $attr and $attr->isa("XML::LibXML::Attr")
ref $attr $attr->isa("XML::LibXML::Attr")
MC/DC0%0/2
ref $attr || $attr
ref $attr $attr
Truth table33%1/3
A and B
A= ref $attrB= $attr->isa("XML::LibXML::Attr")
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= ref $attrB= $attr
ABresult
1X1
011
000
113 or error __x"expects an attribute node, but got `{something}' at {path}"
114 , something => (ref $attr || $attr), path => $path;
115  
116 4 my $node = XML::LibXML::Element->new('dummy');
117 4 $node->addChild($attr);
118  
119 4 $processor->($node);
120 4 };
121 }
122  
123 sub makeWrapperNs # no namespaces in the HASH
124 62 ▶{ my ($self, $path, $processor, $index, $filter) = @_;
Subroutine makeWrapperNs: called CC=1 SCAR=0.0
Pod undocumented
125 62 $processor;
126 }
127  
128 #
129 ## Element
130 #
131  
132 sub makeSequence($@)
133 220 ▶{ my ($self, $path, @pairs) = @_;
Subroutine makeSequence: called CC=4 SCAR=13.9
Pod undocumented
134 220 ▶ if(@pairs==2)
Branch: 1 branch
BranchTrueFalseTotal
if (@pairs == 2) 86 134 220
135 86 { my ($take, $action) = @pairs;
136 my $code
137 = (ref $action eq 'BLOCK' || ref $action eq 'ANY')
138 6 ▶ ? sub { $action->($_[0]) }
Subroutine __ANON__: called CC=1 SCAR=0.0
139 86 ▶ : sub { $action->($_[0] && $_[0]->currentType eq $take ? $_[0]:undef)};
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 2 branches
BranchTrueFalseTotal
ref $action eq 'BLOCK' || ref $action eq 'ANY' ? : 6 80 86
$_[0] && $_[0]->currentType eq $take ? : 61 7 68
Condition66%4/6
ref $action eq "BLOCK" or ref $action eq "ANY"
l!l&&r!l&&!r
6080
$_[0] and $_[0]->currentType eq $take
!ll&&!rl&&r
0761
MC/DC50%1/2
ref $action eq "BLOCK" or ref $action eq "ANY"
ref $action eq "BLOCK" ref $action eq "ANY"
MC/DC50%1/2
$_[0] and $_[0]->currentType eq $take
$_[0] $_[0]->currentType eq $take
Truth table66%2/3
A or B
A= ref $action eq "BLOCK"B= ref $action eq "ANY"
ABresult
1X1
011
000
Truth table66%2/3
A and B
A= $_[0]B= $_[0]->currentType eq $take
ABresult
0X0
100
111
140 86 return bless $code, 'BLOCK';
141 }
142  
143 bless
144 148 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=6 SCAR=17.9
145 148 my @res;
146 148 my @do = @pairs;
147  
148 148 ▶ while(@do)
Branch: 1 branch
BranchTrueFalseTotal
if (@do) 333 132 465
149 333 { my ($take, $do) = (shift @do, shift @do);
150 333 ▶ push @res, ref $do eq 'BLOCK'
Branch: 1 branch
BranchTrueFalseTotal
ref $do eq 'BLOCK' || ref $do eq 'ANY' || defined $tree && $tree->currentType eq $take ? : 285 48 333
Condition100%9/9
ref $do eq "BLOCK" or ref $do eq "ANY" or defined $tree and $tree->currentType eq $take
l!l&&r!l&&!r
3225348
ref $do eq "BLOCK" or ref $do eq "ANY"
l!l&&r!l&&!r
275301
defined $tree and $tree->currentType eq $take
!ll&&!rl&&r
147253
MC/DC100%4/4
ref $do eq "BLOCK" or ref $do eq "ANY" or defined $tree and $tree->currentType eq $take
ref $do eq "BLOCK" ref $do eq "ANY" defined $tree $tree->currentType eq $take
Truth table100%5/5
A or B or C and D
A= ref $do eq "BLOCK"B= ref $do eq "ANY"C= defined $treeD= $tree->currentType eq $take
ABCDresult
1XXX1
01XX1
00111
000X0
00100
151 || ref $do eq 'ANY'
152 || (defined $tree && $tree->currentType eq $take)
153 ? $do->($tree) : $do->(undef);
154 }
155  
156 132 @res;
157 134 }, 'BLOCK';
158 }
159  
160 sub makeChoice($@)
161 40 ▶{ my ($self, $path, %do) = @_;
Subroutine makeChoice: called CC=7 SCAR=20.7
Pod undocumented
162 40 my @specials;
163 40 foreach my $el (keys %do)
164 { push @specials, delete $do{$el}
165 91 ▶ if ref $do{$el} eq 'BLOCK' || ref $do{$el} eq 'ANY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $do{$el} eq "BLOCK" or ref $do{$el} eq "ANY" 12 79 91
Condition66%2/3
ref $do{$el} eq "BLOCK" or ref $do{$el} eq "ANY"
l!l&&r!l&&!r
12079
MC/DC50%1/2
ref $do{$el} eq "BLOCK" or ref $do{$el} eq "ANY"
ref $do{$el} eq "BLOCK" ref $do{$el} eq "ANY"
Truth table66%2/3
A or B
A= ref $do{$el} eq "BLOCK"B= ref $do{$el} eq "ANY"
ABresult
1X1
011
000
166 }
167  
168 40 ▶ if(keys %do==1 && !@specials)
Branch: 1 branch
BranchTrueFalseTotal
if (keys %do == 1 and not @specials) 4 36 40
Condition100%3/3
keys %do == 1 and not @specials
!ll&&!rl&&r
3154
MC/DC100%2/2
keys %do == 1 and not @specials
keys %do == 1 not @specials
Truth table100%3/3
A and not(B)
A= keys %do == 1B= not @specials
ABresult
0X0
100
111
169 4 { my ($option, $action) = %do;
170 return bless
171 4 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=5 SCAR=16.8
172 4 ▶ my $type = defined $tree ? $tree->currentType : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tree ? : 4 0 4
173 4 ▶ return $action->($tree)
Branch: 1 branch
BranchTrueFalseTotal
if $type eq $option 3 1 4
174 if $type eq $option;
175  
176 1 ▶ try { $action->(undef) }; # minOccurs=0
Subroutine __ANON__: called CC=1 SCAR=0.0
177 1 ▶ $@ or return ();
Branch: 1 branch
BranchTrueFalseTotal
$@ or return () 0 1 1
178  
179 1 ▶ $type
Branch: 1 branch
BranchTrueFalseTotal
$type or &error(&__x("element `{tag}' expected for choice at {path}", "tag", $option, "path", $path, "_class", "misfit")) 1 0 1
180 or error __x"element `{tag}' expected for choice at {path}"
181 , tag => $option, path => $path, _class => 'misfit';
182  
183 0 error __x"single choice option `{option}' at `{type}' at {path}"
184 , option => $option, type => $type, path => $path
185 , _class => 'misfit';
186 4 }, 'BLOCK';
187 }
188  
189 @specials or return bless
190 37 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=7 SCAR=19.5
191 37 ▶ my $type = defined $tree ? $tree->currentType : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $tree ? : 37 0 37
192 37 ▶ my $elem = defined $type ? $do{$type} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $type ? : 37 0 37
193 37 ▶ return $elem->($tree) if $elem;
Branch: 1 branch
BranchTrueFalseTotal
if $elem 33 4 37
194  
195 # very silly situation: some people use a minOccurs within
196 # a choice, instead on choice itself. That always succeeds.
197 4 foreach my $some (values %do)
198 9 ▶ { try { $some->(undef) };
Subroutine __ANON__: called CC=1 SCAR=0.0
199 9 ▶ $@ or return ();
Branch: 1 branch
BranchTrueFalseTotal
$@ or return () 1 8 9
200 }
201  
202 $type
203 3 ▶ or error __x"no element left to pick choice at {path}"
Branch: 1 branch
BranchTrueFalseTotal
$type or &error(&__x("no element left to pick choice at {path}", "path", $path, "_class", "misfit")) 1 2 3
204 , path => $path, _class => 'misfit';
205  
206 2 trace "choose element from @{[sort keys %do]}";
207 2 error __x"no applicable choice for `{tag}' at {path}"
208 , tag => $type, path => $path, _class => 'misfit';
209 36 ▶ }, 'BLOCK';
Branch: 1 branch
BranchTrueFalseTotal
@specials or return bless(sub { my $tree = shift(); my $type = defined $tree ? $tree->currentType : undef; my $elem = defined $type ? $do{$type} : undef; return &$elem($tree) if $elem; foreach my $some (values %do) { &try(sub { &$some(undef); } ); $@ or return (); } ; $type or &error(&__x("no element left to pick choice at {path}", "path", $path, "_class", "misfit")); &trace("choose element from @{[sort(keys %do)];}"); &error(&__x("no applicable choice for `{tag}' at {path}", "tag", $type, "path", $path, "_class", "misfit")); } , "BLOCK") 26 10 36
210  
211 return bless
212 10 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=13 SCAR=35.3
213 10 ▶ my $type = defined $tree ? $tree->currentType : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $tree ? : 10 0 10
214 10 ▶ my $elem = defined $type ? $do{$type} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $type ? : 10 0 10
215 10 ▶ return $elem->($tree) if $elem;
Branch: 1 branch
BranchTrueFalseTotal
if $elem 4 6 10
216  
217 6 my @special_errors;
218 6 foreach (@specials)
219 8 ▶ { my @d = try { $_->($tree) };
Subroutine __ANON__: called CC=1 SCAR=0.0
220 8 ▶ return @d if !$@ && @d;
Branch: 1 branch
BranchTrueFalseTotal
if not $@ and @d 6 2 8
Condition66%2/3
not $@ and @d
!ll&&!rl&&r
206
MC/DC50%1/2
not $@ and @d
not $@ @d
Truth table66%2/3
not(A) and B
A= not $@B= @d
ABresult
0X0
100
111
221 2 ▶ push @special_errors, $@->wasFatal->message if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 2 0 2
222 }
223  
224 0 foreach my $some (values %do, @specials)
225 0 ▶ { try { $some->(undef) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
226 0 ▶ $@ or return ();
Branch: 1 branch
BranchTrueFalseTotal
$@ or return () 0 0 0
227 }
228  
229 $type
230 0 ▶ or error __x"choice needs more elements at {path}"
Branch: 1 branch
BranchTrueFalseTotal
$type or &error(&__x("choice needs more elements at {path}", "path", $path, "_class", "misfit")) 0 0 0
231 , path => $path, _class => 'misfit';
232  
233  
234 0 my @elems = sort keys %do;
235 0 ▶ trace "choose element from @elems or fix special at $path" if @elems;
Branch: 1 branch
BranchTrueFalseTotal
if @elems 0 0 0
236 0 trace "failed specials in choice: $_" for @special_errors;
237  
238 0 error __x"no applicable choice for `{tag}' at {path}"
239 , tag => $type, path => $path, _class => 'misfit';
240 10 }, 'BLOCK';
241 }
242  
243 sub makeAll($@)
244 30 ▶{ my ($self, $path, %pairs) = @_;
Subroutine makeAll: called CC=7 SCAR=19.5
Pod undocumented
245 30 my %specials;
246 30 foreach my $el (keys %pairs)
247 { $specials{$el} = delete $pairs{$el}
248 80 ▶ if ref $pairs{$el} eq 'BLOCK' || ref $pairs{$el} eq 'ANY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $pairs{$el} eq "BLOCK" or ref $pairs{$el} eq "ANY" 3 77 80
Condition66%2/3
ref $pairs{$el} eq "BLOCK" or ref $pairs{$el} eq "ANY"
l!l&&r!l&&!r
3077
MC/DC50%1/2
ref $pairs{$el} eq "BLOCK" or ref $pairs{$el} eq "ANY"
ref $pairs{$el} eq "BLOCK" ref $pairs{$el} eq "ANY"
Truth table66%2/3
A or B
A= ref $pairs{$el} eq "BLOCK"B= ref $pairs{$el} eq "ANY"
ABresult
1X1
011
000
249 }
250  
251 30 ▶ if(!%specials && keys %pairs==1)
Branch: 1 branch
BranchTrueFalseTotal
if (not %specials and keys %pairs == 1) 5 25 30
Condition100%3/3
not %specials and keys %pairs == 1
!ll&&!rl&&r
3225
MC/DC100%2/2
not %specials and keys %pairs == 1
not %specials keys %pairs == 1
Truth table100%3/3
not(A) and B
A= not %specialsB= keys %pairs == 1
ABresult
0X0
100
111
252 5 { my ($take, $do) = %pairs;
253 return bless
254 4 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=3 SCAR=11.1
255 4 ▶ $do->($tree && $tree->currentType eq $take ? $tree : undef);
Branch: 1 branch
BranchTrueFalseTotal
$tree && $tree->currentType eq $take ? : 3 1 4
Condition66%2/3
$tree and $tree->currentType eq $take
!ll&&!rl&&r
013
MC/DC50%1/2
$tree and $tree->currentType eq $take
$tree $tree->currentType eq $take
Truth table66%2/3
A and B
A= $treeB= $tree->currentType eq $take
ABresult
0X0
100
111
256 5 }, 'BLOCK';
257 }
258  
259 keys %specials or return bless
260 22 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=5 SCAR=16.1
261 22 my %do = %pairs;
262 22 my @res;
263 22 while(1)
264 67 ▶ { my $type = $tree && $tree->currentType or last;
Branch: 1 branch
BranchTrueFalseTotal
my $type = $tree && $tree->currentType or last 21 46 67
Condition66%2/3
$tree && $tree->currentType
!ll&&!rl&&r
02146
MC/DC50%1/2
$tree && $tree->currentType
$tree $tree->currentType
Truth table66%2/3
A && B
A= $treeB= $tree->currentType
ABresult
0X0
100
111
265 46 ▶ my $do = delete $do{$type} or last; # already seen?
Branch: 1 branch
BranchTrueFalseTotal
my $do = delete $do{$type} or last 1 45 46
266 45 push @res, $do->($tree);
267 }
268  
269 # saw all of all?
270 push @res, $_->(undef)
271 22 for values %do;
272  
273 9 @res;
274 25 ▶ }, 'BLOCK';
Branch: 1 branch
BranchTrueFalseTotal
keys %specials or return bless(sub { my $tree = shift(); my(%do) = %pairs; my @res; while (1) { my $type = $tree && $tree->currentType or last; my $do = delete $do{$type} or last; push @res, &$do($tree); } ; push @res, &$_(undef) foreach (values %do); @res; } , "BLOCK") 22 3 25
275  
276 # an 'all' block with nested structures or any is quite nasty. Don't
277 # forget that 'all' can have maxOccurs > 1 !
278 bless
279 3 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=10 SCAR=23.0
280 3 my %do = %pairs;
281 3 my %spseen;
282 my @res;
283 PARTICLE:
284 3 while(1)
285 11 ▶ { my $type = $tree->currentType or last;
Branch: 1 branch
BranchTrueFalseTotal
my $type = $tree->currentType or last 2 9 11
286 9 ▶ if(my $do = delete $do{$type})
Branch: 1 branch
BranchTrueFalseTotal
if (my $do = delete $do{$type}) 6 3 9
287 6 { push @res, $do->($tree);
288 6 next PARTICLE;
289 }
290  
291 3 foreach (keys %specials)
292 3 ▶ { next if $spseen{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $spseen{$_} 0 3 3
293 3 ▶ my @d = try { $specials{$_}->($tree) };
Subroutine __ANON__: called CC=1 SCAR=0.0
294 3 ▶ next if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 2 3
295  
296 2 $spseen{$_}++;
297 2 push @res, @d;
298 2 next PARTICLE;
299 }
300  
301 1 last;
302 }
303 3 ▶ @res or return ();
Branch: 1 branch
BranchTrueFalseTotal
@res or return () 0 3 3
304  
305 # saw all of all?
306 push @res, $_->(undef)
307 3 for values %do;
308  
309 push @res, $_->(undef)
310 3 ▶ for map {$spseen{$_} ? () : $specials{$_}} keys %specials;
Branch: 1 branch
BranchTrueFalseTotal
$spseen{$_} ? : 2 1 3
311  
312 2 @res;
313 3 }, 'BLOCK';
314 }
315  
316 sub makeBlockHandler
317 299 ▶{ my ($self, $path, $label, $min, $max, $process, $kind, $multi) = @_;
Subroutine makeBlockHandler: called CC=7 SCAR=20.7
Pod undocumented
318  
319 # flatten the HASH: when a block appears only once, there will
320 # not be an additional nesting in the output tree.
321 299 ▶ if($max ne 'unbounded' && $max==1)
Branch: 1 branch
BranchTrueFalseTotal
if ($max ne "unbounded" and $max == 1) 269 30 299
Condition100%3/3
$max ne "unbounded" and $max == 1
!ll&&!rl&&r
1911269
MC/DC100%2/2
$max ne "unbounded" and $max == 1
$max ne "unbounded" $max == 1
Truth table100%3/3
A and B
A= $max ne "unbounded"B= $max == 1
ABresult
0X0
100
111
322 {
323 269 ▶ return ($label => $process) if $min==1;
Branch: 1 branch
BranchTrueFalseTotal
if $min == 1 264 5 269
324  
325 my $code =
326 5 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=7 SCAR=19.8
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 0 5 5
327 5 ▶ my $starter = $tree->currentChild or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $starter = $tree->currentChild or return () 1 4 5
328 4 ▶ my @pairs = try { $process->($tree) };
Subroutine __ANON__: called CC=1 SCAR=0.0
329 4 ▶ if($@->wasFatal(class => 'misfit'))
Branch: 2 branches
BranchTrueFalseTotal
if ($@->wasFatal('class', 'misfit')) { } 2 2 4
elsif ($@) { } 0 2 2
330 2 { my $ending = $tree->currentChild;
331 2 ▶ $@->reportAll if !$ending || $ending!=$starter;
Branch: 1 branch
BranchTrueFalseTotal
if not $ending or $ending != $starter 1 1 2
Condition66%2/3
not $ending or $ending != $starter
l!l&&r!l&&!r
101
MC/DC50%1/2
not $ending or $ending != $starter
not $ending $ending != $starter
Truth table66%2/3
not(A) or B
A= not $endingB= $ending != $starter
ABresult
1X1
011
000
332 1 return ();
333 }
334 0 elsif($@) {$@->reportAll}
335 2 @pairs;
336 5 };
337 5 return ($label => bless($code, 'BLOCK'));
338 }
339  
340 30 ▶ if($max ne 'unbounded' && $min>=$max)
Branch: 1 branch
BranchTrueFalseTotal
if ($max ne "unbounded" and $min >= $max) 0 30 30
Condition66%2/3
$max ne "unbounded" and $min >= $max
!ll&&!rl&&r
19110
MC/DC0%0/2
$max ne "unbounded" and $min >= $max
$max ne "unbounded" $min >= $max
Truth table66%2/3
A and B
A= $max ne "unbounded"B= $min >= $max
ABresult
0X0
100
111
341 { my $code =
342 0 ▶ sub { my $tree = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
343 0 my @res;
344 0 ▶ while(@res < $min)
Branch: 1 branch
BranchTrueFalseTotal
if (@res < $min) 0 0 0
345 0 { my @pairs = $process->($tree);
346 0 push @res, {@pairs};
347 }
348 0 ($multi => \@res);
349 0 };
350 0 return ($label => bless($code, 'BLOCK'));
351 }
352  
353 30 ▶ if($min==0)
Branch: 1 branch
BranchTrueFalseTotal
if ($min == 0) 18 12 30
354 { my $code =
355 18 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=11 SCAR=24.4
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 0 18 18
356 18 my @res;
357 18 ▶ while($max eq 'unbounded' || @res < $max)
Branch: 1 branch
BranchTrueFalseTotal
if ($max eq "unbounded" or @res < $max) 46 1 47
Condition100%3/3
$max eq "unbounded" or @res < $max
l!l&&r!l&&!r
3791
MC/DC100%2/2
$max eq "unbounded" or @res < $max
$max eq "unbounded" @res < $max
Truth table100%3/3
A or B
A= $max eq "unbounded"B= @res < $max
ABresult
1X1
011
000
358 46 ▶ { my $starter = $tree->currentChild or last;
Branch: 1 branch
BranchTrueFalseTotal
my $starter = $tree->currentChild or last 11 35 46
359 35 ▶ my @pairs = try { $process->($tree) };
Subroutine __ANON__: called CC=1 SCAR=0.0
360 35 ▶ if($@->wasFatal(class => 'misfit'))
Branch: 2 branches
BranchTrueFalseTotal
if ($@->wasFatal('class', 'misfit')) { } 3 32 35
elsif ($@) { } 0 32 32
361 { # misfit error is ok, if nothing consumed
362 3 trace "misfit $label ($min..$max) ".$@->wasFatal->message;
363 3 my $ending = $tree->currentChild;
364 3 ▶ $@->reportAll if !$ending || $ending!=$starter;
Branch: 1 branch
BranchTrueFalseTotal
if not $ending or $ending != $starter 0 3 3
Condition33%1/3
not $ending or $ending != $starter
l!l&&r!l&&!r
003
MC/DC0%0/2
not $ending or $ending != $starter
not $ending $ending != $starter
Truth table33%1/3
not(A) or B
A= not $endingB= $ending != $starter
ABresult
1X1
011
000
365 3 last;
366 }
367 0 elsif($@) {$@->reportAll}
368  
369 32 ▶ @pairs or last;
Branch: 1 branch
BranchTrueFalseTotal
@pairs or last 3 29 32
370 29 push @res, {@pairs};
371 }
372  
373 18 ▶ @res ? ($multi => \@res) : ();
Branch: 1 branch
BranchTrueFalseTotal
@res ? : 14 4 18
374 18 };
375 18 return ($label => bless($code, 'BLOCK'));
376 }
377  
378 my $code =
379 10 ▶ sub { my $tree = shift or error __xn
Subroutine __ANON__: called CC=11 SCAR=27.8
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or &error(&__xn("block with `{name}' is required at least once at {path}", "block with `{name}' is required at least {_count} times at {path}", $min, "name", $label, "path", $path)) 0 10 10
380 "block with `{name}' is required at least once at {path}"
381 , "block with `{name}' is required at least {_count} times at {path}"
382 , $min, name => $label, path => $path;
383  
384 10 my @res;
385 10 ▶ while(@res < $min)
Branch: 1 branch
BranchTrueFalseTotal
if (@res < $min) 10 8 18
386 10 { my @pairs = $process->($tree);
387 8 push @res, {@pairs};
388 }
389 8 ▶ while($max eq 'unbounded' || @res < $max)
Branch: 1 branch
BranchTrueFalseTotal
if ($max eq "unbounded" or @res < $max) 18 2 20
Condition100%3/3
$max eq "unbounded" or @res < $max
l!l&&r!l&&!r
1352
MC/DC100%2/2
$max eq "unbounded" or @res < $max
$max eq "unbounded" @res < $max
Truth table100%3/3
A or B
A= $max eq "unbounded"B= @res < $max
ABresult
1X1
011
000
390 18 ▶ { my $starter = $tree->currentChild or last;
Branch: 1 branch
BranchTrueFalseTotal
my $starter = $tree->currentChild or last 6 12 18
391 12 ▶ my @pairs = try { $process->($tree) };
Subroutine __ANON__: called CC=1 SCAR=0.0
392 12 ▶ if($@->wasFatal(class => 'misfit'))
Branch: 2 branches
BranchTrueFalseTotal
if ($@->wasFatal('class', 'misfit')) { } 0 12 12
elsif ($@) { } 0 12 12
393 { # misfit error is ok, if nothing consumed
394 0 trace "misfit $label ($min..) ".$@->wasFatal->message;
395 0 my $ending = $tree->currentChild;
396 0 ▶ $@->reportAll if !$ending || $ending!=$starter;
Branch: 1 branch
BranchTrueFalseTotal
if not $ending or $ending != $starter 0 0 0
Condition0%0/3
not $ending or $ending != $starter
l!l&&r!l&&!r
000
MC/DC0%0/2
not $ending or $ending != $starter
not $ending $ending != $starter
Truth table0%0/3
not(A) or B
A= not $endingB= $ending != $starter
ABresult
1X1
011
000
397 0 last;
398 }
399 0 elsif($@) {$@->reportAll};
400  
401 12 ▶ @pairs or last;
Branch: 1 branch
BranchTrueFalseTotal
@pairs or last 0 12 12
402 12 push @res, {@pairs};
403 }
404 8 ($multi => \@res);
405 12 };
406  
407 12 ($label => bless($code, 'BLOCK'));
408 }
409  
410 sub makeElementHandler
411 522 ▶{ my ($self, $path, $label, $min, $max, $required, $optional) = @_;
Subroutine makeElementHandler: called CC=8 SCAR=20.9
Pod undocumented
412 522 ▶ $max eq "0" and return sub {}; # max can be "unbounded", hence strcmp
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$max eq 0 and return sub { } 1 521 522
413  
414 521 ▶ if($max ne 'unbounded' && $max==1)
Branch: 1 branch
BranchTrueFalseTotal
if ($max ne "unbounded" and $max == 1) 495 26 521
Condition100%3/3
$max ne "unbounded" and $max == 1
!ll&&!rl&&r
1214495
MC/DC100%2/2
$max ne "unbounded" and $max == 1
$max ne "unbounded" $max == 1
Truth table100%3/3
A and B
A= $max ne "unbounded"B= $max == 1
ABresult
0X0
100
111
415 { return $min==1
416 377 ▶ ? sub { my $tree = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
417 377 ▶ my @pairs = $required->(defined $tree ? $tree->descend :undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $tree ? : 335 42 377
418 339 ▶ $tree->nextChild if defined $tree;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tree 331 8 339
419 339 ($label => $pairs[1]);
420 }
421 83 ▶ : sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=4 SCAR=14.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 30 53 83
422 53 ▶ $tree->currentChild or return ();
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentChild or return () 0 53 53
423 53 my @pairs = $optional->($tree->descend);
424 52 $tree->nextChild;
425 52 ▶ @pairs or return ();
Branch: 1 branch
BranchTrueFalseTotal
@pairs or return () 0 52 52
426 52 ($label => $pairs[1]);
427 495 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$min == 1 ? : 424 71 495
428 }
429
430 26 ▶ if($max ne 'unbounded' && $min>=$max)
Branch: 1 branch
BranchTrueFalseTotal
if ($max ne "unbounded" and $min >= $max) 2 24 26
Condition100%3/3
$max ne "unbounded" and $min >= $max
!ll&&!rl&&r
12122
MC/DC100%2/2
$max ne "unbounded" and $min >= $max
$max ne "unbounded" $min >= $max
Truth table100%3/3
A and B
A= $max ne "unbounded"B= $min >= $max
ABresult
0X0
100
111
431 { return
432 2 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=5 SCAR=16.5
433 2 my @res;
434 2 ▶ while(@res < $min)
Branch: 1 branch
BranchTrueFalseTotal
if (@res < $min) 4 1 5
435 4 ▶ { my @pairs = $required->(defined $tree ? $tree->descend:undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $tree ? : 4 0 4
436 3 push @res, $pairs[1];
437 3 ▶ $tree->nextChild if defined $tree;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tree 3 0 3
438 }
439 1 ▶ @res ? ($label => \@res) : ();
Branch: 1 branch
BranchTrueFalseTotal
@res ? : 1 0 1
440 2 };
441 }
442  
443 24 ▶ if(!defined $required)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $required) 22 2 24
444 { return
445 22 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=7 SCAR=19.6
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 6 16 22
446 16 my @res;
447 16 ▶ while($max eq 'unbounded' || @res < $max)
Branch: 1 branch
BranchTrueFalseTotal
if ($max eq "unbounded" or @res < $max) 50 0 50
Condition66%2/3
$max eq "unbounded" or @res < $max
l!l&&r!l&&!r
24260
MC/DC0%0/2
$max eq "unbounded" or @res < $max
$max eq "unbounded" @res < $max
Truth table66%2/3
A or B
A= $max eq "unbounded"B= @res < $max
ABresult
1X1
011
000
448 50 ▶ { $tree->currentChild or last;
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentChild or last 10 40 50
449 40 my @pairs = $optional->($tree->descend);
450 40 ▶ @pairs or last;
Branch: 1 branch
BranchTrueFalseTotal
@pairs or last 6 34 40
451 34 push @res, $pairs[1];
452 34 $tree->nextChild;
453 }
454 16 ▶ @res ? ($label => \@res) : ();
Branch: 1 branch
BranchTrueFalseTotal
@res ? : 16 0 16
455 22 };
456 }
457  
458 2 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=9 SCAR=22.3
459 2 my @res;
460 2 ▶ while(@res < $min)
Branch: 1 branch
BranchTrueFalseTotal
if (@res < $min) 2 2 4
461 2 ▶ { my @pairs = $required->(defined $tree ? $tree->descend : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $tree ? : 2 0 2
462 2 push @res, $pairs[1];
463 2 ▶ $tree->nextChild if defined $tree;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tree 2 0 2
464 }
465 2 ▶ while(defined $tree && ($max eq 'unbounded' || @res < $max))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tree and $max eq "unbounded" || @res < $max) 2 1 3
Condition66%4/6
defined $tree and $max eq "unbounded" || @res < $max
!ll&&!rl&&r
012
$max eq "unbounded" or @res < $max
l!l&&r!l&&!r
021
MC/DC33%1/3
defined $tree and $max eq "unbounded" || @res < $max
defined $tree $max eq "unbounded" @res < $max
Truth table50%2/4
A and B or C
A= defined $treeB= $max eq "unbounded"C= @res < $max
ABCresult
0XX0
1000
11X1
1011
466 2 ▶ { $tree->currentChild or last;
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentChild or last 0 2 2
467 2 my @pairs = $optional->($tree->descend);
468 2 ▶ @pairs or last;
Branch: 1 branch
BranchTrueFalseTotal
@pairs or last 1 1 2
469 1 push @res, $pairs[1];
470 1 $tree->nextChild;
471 }
472 2 ($label => \@res);
473 2 };
474 }
475  
476 sub makeRequired
477 429 ▶{ my ($self, $path, $label, $do) = @_;
Subroutine makeRequired: called CC=2 SCAR=6.9
Pod undocumented
478  
479 my $req =
480 383 ▶ sub { my $tree = shift; # can be undef
Subroutine __ANON__: called CC=2 SCAR=6.9
481 383 my @pairs = $do->($tree);
482 @pairs
483 378 ▶ or error __x"data for element or block starting with `{tag}' missing at {path}"
Branch: 1 branch
BranchTrueFalseTotal
@pairs or &error(&__x("data for element or block starting with `{tag}' missing at {path}", "tag", $label, "path", $path, "_class", "misfit")) 34 344 378
484 , tag => $label, path => $path, _class => 'misfit';
485 344 @pairs;
486 429 };
487 429 ▶ ref $do eq 'BLOCK' ? bless($req, 'BLOCK') : $req;
Branch: 1 branch
BranchTrueFalseTotal
ref $do eq 'BLOCK' ? : 0 429 429
488 }
489  
490 sub makeElementHref
491 0 ▶{ my ($self, $path, $ns, $childname, $do) = @_;
Subroutine makeElementHref: not called CC=1 SCAR=6.9
Pod undocumented
492  
493 0 ▶ sub { my $tree = shift;
Subroutine __ANON__: not called CC=4 SCAR=30.0
494  
495 0 ▶ return ($childname => $tree->node)
Branch: 1 branch
BranchTrueFalseTotal
if defined $tree and $tree->nodeType eq $childname and $tree->node->hasAttribute("href") 0 0 0
Condition0%0/6
defined $tree and $tree->nodeType eq $childname and $tree->node->hasAttribute("href")
!ll&&!rl&&r
000
defined $tree and $tree->nodeType eq $childname
!ll&&!rl&&r
000
MC/DC0%0/3
defined $tree and $tree->nodeType eq $childname and $tree->node->hasAttribute("href")
defined $tree $tree->nodeType eq $childname $tree->node->hasAttribute("href")
Truth table0%0/4
A and B and C
A= defined $treeB= $tree->nodeType eq $childnameC= $tree->node->hasAttribute("href")
ABCresult
0XX0
10X0
1100
1111
496 if defined $tree
497 && $tree->nodeType eq $childname
498 && $tree->node->hasAttribute('href');
499  
500 0 $do->($tree);
501 0 };
502 }
503  
504 sub makeElement
505 882 ▶{ my ($self, $path, $ns, $childname, $do) = @_;
Subroutine makeElement: called CC=1 SCAR=0.0
Pod undocumented
506 839 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
507 839 ▶ my $value = defined $tree && $tree->nodeType eq $childname
Branch: 1 branch
BranchTrueFalseTotal
defined $tree && $tree->nodeType eq $childname ? : 798 41 839
Condition100%3/3
defined $tree and $tree->nodeType eq $childname
!ll&&!rl&&r
347798
MC/DC100%2/2
defined $tree and $tree->nodeType eq $childname
defined $tree $tree->nodeType eq $childname
Truth table100%3/3
A and B
A= defined $treeB= $tree->nodeType eq $childname
ABresult
0X0
100
111
508 ? $do->($tree) : $do->(undef);
509 770 ▶ defined $value ? ($childname => $value) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 730 40 770
510 882 };
511 }
512  
513 sub makeElementDefault
514 19 ▶{ my ($self, $path, $ns, $childname, $do, $default) = @_;
Subroutine makeElementDefault: called CC=4 SCAR=14.4
Pod undocumented
515  
516 19 my $mode = $self->{default_values};
517 $mode eq 'IGNORE'
518 and return sub
519 2 ▶ { my $tree = shift or return ();
Subroutine __ANON__: called CC=4 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 0 2 2
520 2 ▶ return () if $tree->nodeType ne $childname
Branch: 1 branch
BranchTrueFalseTotal
if $tree->nodeType ne $childname or $tree->node->textContent eq "" 0 2 2
Condition33%1/3
$tree->nodeType ne $childname or $tree->node->textContent eq ""
l!l&&r!l&&!r
002
MC/DC0%0/2
$tree->nodeType ne $childname or $tree->node->textContent eq ""
$tree->nodeType ne $childname $tree->node->textContent eq ""
Truth table33%1/3
A or B
A= $tree->nodeType ne $childnameB= $tree->node->textContent eq ""
ABresult
1X1
011
000
521 || $tree->node->textContent eq '';
522 2 $do->($tree);
523 19 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$mode eq "IGNORE" and return sub { my $tree = shift() or return (); return () if $tree->nodeType ne $childname or $tree->node->textContent eq ""; &$do($tree); } 2 17 19
524  
525 17 my $def = $do->($default);
526  
527 $mode eq 'EXTEND'
528 and return sub
529 15 ▶ { my $tree = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
530 15 ▶ return ($childname => $def)
Branch: 1 branch
BranchTrueFalseTotal
if not defined $tree or $tree->nodeType ne $childname or $tree->node->textContent eq "" 1 7 8
Condition83%5/6
not defined $tree or $tree->nodeType ne $childname or $tree->node->textContent eq ""
l!l&&r!l&&!r
717
not defined $tree or $tree->nodeType ne $childname
l!l&&r!l&&!r
708
MC/DC66%2/3
not defined $tree or $tree->nodeType ne $childname or $tree->node->textContent eq ""
not defined $tree $tree->nodeType ne $childname $tree->node->textContent eq ""
Truth table75%3/4
not(A) or B or C
A= not defined $treeB= $tree->nodeType ne $childnameC= $tree->node->textContent eq ""
ABCresult
1XX1
01X1
0011
0000
531 if !defined $tree
532 || $tree->nodeType ne $childname
533 || $tree->node->textContent eq '';
534  
535 7 $do->($tree);
536 17 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$mode eq "EXTEND" and return sub { my $tree = shift(); return $childname, $def if not defined $tree or $tree->nodeType ne $childname or $tree->node->textContent eq ""; &$do($tree); } 14 3 17
537  
538 $mode eq 'MINIMAL'
539 and return sub
540 3 ▶ { my $tree = shift or return ();
Subroutine __ANON__: called CC=6 SCAR=19.3
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 0 3 3
541 3 ▶ return () if $tree->nodeType ne $childname
Branch: 1 branch
BranchTrueFalseTotal
if $tree->nodeType ne $childname or $tree->node->textContent eq "" 0 3 3
Condition33%1/3
$tree->nodeType ne $childname or $tree->node->textContent eq ""
l!l&&r!l&&!r
003
MC/DC0%0/2
$tree->nodeType ne $childname or $tree->node->textContent eq ""
$tree->nodeType ne $childname $tree->node->textContent eq ""
Truth table33%1/3
A or B
A= $tree->nodeType ne $childnameB= $tree->node->textContent eq ""
ABresult
1X1
011
000
542 || $tree->node->textContent eq '';
543 3 my $v = $do->($tree);
544 3 ▶ undef $v if defined $v && $v eq $def;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v and $v eq $def 1 2 3
Condition66%2/3
defined $v and $v eq $def
!ll&&!rl&&r
021
MC/DC50%1/2
defined $v and $v eq $def
defined $v $v eq $def
Truth table66%2/3
A and B
A= defined $vB= $v eq $def
ABresult
0X0
100
111
545 3 ($childname => $v);
546 3 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$mode eq "MINIMAL" and return sub { my $tree = shift() or return (); return () if $tree->nodeType ne $childname or $tree->node->textContent eq ""; my $v = &$do($tree); undef $v if defined $v and $v eq $def; $childname, $v; } 3 0 3
547  
548 0 error __x"illegal default_values mode `{mode}'", mode => $mode;
549 }
550  
551 sub makeElementFixed
552 3 ▶{ my ($self, $path, $ns, $childname, $do, $fixed) = @_;
Subroutine makeElementFixed: called CC=1 SCAR=0.0
Pod undocumented
553 3 my ($tag, $fix) = $do->($fixed);
554  
555 3 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=5 SCAR=16.2
556 3 ▶ my ($label, $value)
Branch: 1 branch
BranchTrueFalseTotal
$tree && $tree->nodeType eq $childname ? : 2 1 3
Condition66%2/3
$tree and $tree->nodeType eq $childname
!ll&&!rl&&r
102
MC/DC50%1/2
$tree and $tree->nodeType eq $childname
$tree $tree->nodeType eq $childname
Truth table66%2/3
A and B
A= $treeB= $tree->nodeType eq $childname
ABresult
0X0
100
111
557 = $tree && $tree->nodeType eq $childname ? $do->($tree) : ();
558  
559 3 ▶ defined $value
Branch: 1 branch
BranchTrueFalseTotal
defined $value or return $tag, $fix 1 2 3
560 or return ($tag => $fix);
561  
562 2 ▶ $value eq $fix
Branch: 1 branch
BranchTrueFalseTotal
$value eq $fix or &error(&__x("element `{name}' must have fixed value `{fixed}', got `{value}' at {path}", "name", $childname, "fixed", $fix, "value", $value, "path", $path)) 0 2 2
563 or error __x"element `{name}' must have fixed value `{fixed}', got `{value}' at {path}"
564 , name => $childname, fixed => $fix, value => $value
565 , path => $path;
566  
567 2 ($label => $value);
568 3 };
569 }
570  
571 sub makeElementAbstract
572 9 ▶{ my ($self, $path, $ns, $childname, $do, $tag) = @_;
Subroutine makeElementAbstract: called CC=1 SCAR=0.0
Pod undocumented
573 3 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 1 2 3
574 2 ▶ $tree->nodeType eq $childname or return ();
Branch: 1 branch
BranchTrueFalseTotal
$tree->nodeType eq $childname or return () 0 2 2
575  
576 2 error __x"abstract element `{name}' used at {path}"
577 , name => $childname, path => $path;
578 9 };
579 }
580  
581 #
582 # complexType and complexType/ComplexContent
583 #
584  
585 # Be warned that the location reported in 'path' may not be the actual
586 # location, caused by the cashing of compiled schema components. The
587 # path you see is the first path where that element was encountered.
588 sub _not_processed($$)
589 4 ▶{ my ($child, $path) = @_;
Subroutine _not_processed: called CC=1 SCAR=0.0
590 4 error __x"element `{name}' not processed for {path} at {where}"
591 , name => type_of_node($child), path => $path
592 , _class => 'misfit', where => $child->nodePath;
593 }
594  
595 sub makeComplexElement
596 262 ▶{ my ($self, $path, $tag, $elems, $attrs, $attrs_any,undef,$is_nillable) = @_;
Subroutine makeComplexElement: called CC=5 SCAR=16.2
Pod undocumented
597 #my @e = @$elems; my @a = @$attrs;
598  
599 262 my @elems = odd_elements @$elems;
600 262 my @attrs = (odd_elements(@$attrs), @$attrs_any);
601  
602 $is_nillable and return
603 10 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=4 SCAR=14.1
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 0 10 10
604 10 my $node = $tree->node;
605 10 ▶ my %complex =
Branch: 1 branch
BranchTrueFalseTotal
$tree->nodeNil ? : 5 5 10
606 ( ($tree->nodeNil ? (_ => 'NIL') : (map $_->($tree), @elems))
607 , (map $_->($node), @attrs)
608 );
609  
610 10 ▶ _not_processed $tree->currentChild, $path
Branch: 1 branch
BranchTrueFalseTotal
if $tree->currentChild 0 10 10
611 if $tree->currentChild;
612  
613 10 ($tag => \%complex);
614 262 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$is_nillable and return sub { my $tree = shift() or return (); my $node = $tree->node; my(%complex) = ($tree->nodeNil ? ("_", "NIL") : map(&$_($tree), @elems), map(&$_($node), @attrs)); &_not_processed(scalar $tree->currentChild, $path) if $tree->currentChild; $tag, \%complex; } 6 256 262
615  
616 @elems > 1 || @attrs and return
617 61 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 1 60 61
618 60 my $node = $tree->node;
619 60 my %complex = ((map $_->($tree), @elems), (map $_->($node), @attrs));
620  
621 56 ▶ _not_processed $tree->currentChild, $path
Branch: 1 branch
BranchTrueFalseTotal
if $tree->currentChild 0 56 56
622 if $tree->currentChild;
623  
624 56 ($tag => \%complex);
625 256 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
@elems > 1 || @attrs and return sub { my $tree = shift() or return (); my $node = $tree->node; my(%complex) = (map(&$_($tree), @elems), map(&$_($node), @attrs)); &_not_processed(scalar $tree->currentChild, $path) if $tree->currentChild; $tag, \%complex; } 57 199 256
Condition100%3/3
@elems > 1 or @attrs
l!l&&r!l&&!r
651199
MC/DC100%2/2
@elems > 1 or @attrs
@elems > 1 @attrs
Truth table100%3/3
A or B
A= @elems > 1B= @attrs
ABresult
1X1
011
000
626  
627 @elems || return
628 8 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 0 8 8
629 8 ▶ _not_processed $tree->currentChild, $path
Branch: 1 branch
BranchTrueFalseTotal
if $tree->currentChild 0 8 8
630 if $tree->currentChild;
631  
632 8 ($tag => {});
633 199 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
@elems or return sub { my $tree = shift() or return (); &_not_processed(scalar $tree->currentChild, $path) if $tree->currentChild; $tag, {}; } 10 189 199
634  
635 189 my $el = shift @elems;
636 185 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 0 185 185
637 185 my %complex = $el->($tree);
638  
639 156 ▶ _not_processed $tree->currentChild, $path
Branch: 1 branch
BranchTrueFalseTotal
if $tree->currentChild 4 152 156
640 if $tree->currentChild;
641  
642 152 ($tag => \%complex);
643 189 };
644 }
645  
646 #
647 # complexType/simpleContent
648 #
649  
650 sub makeTaggedElement
651 10 ▶{ my ($self, $path, $tag, $st, $attrs, $attrs_any,undef,$is_nillable) = @_;
Subroutine makeTaggedElement: called CC=1 SCAR=0.1
Pod undocumented
652 10 my @attrs = (odd_elements(@$attrs), @$attrs_any);
653  
654 11 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=8 SCAR=22.1
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 0 11 11
655 11 ▶ my $simple = $is_nillable && ref $tree && $tree->nodeNil ? 'NIL' : $st->($tree);
Branch: 1 branch
BranchTrueFalseTotal
$is_nillable && ref $tree && $tree->nodeNil ? : 1 10 11
Condition66%4/6
$is_nillable and ref $tree and $tree->nodeNil
!ll&&!rl&&r
1001
$is_nillable and ref $tree
!ll&&!rl&&r
1001
MC/DC33%1/3
$is_nillable and ref $tree and $tree->nodeNil
$is_nillable ref $tree $tree->nodeNil
Truth table50%2/4
A and B and C
A= $is_nillableB= ref $treeC= $tree->nodeNil
ABCresult
0XX0
10X0
1100
1111
656 11 ▶ ref $tree or return ($tag => {_ => $simple});
Branch: 1 branch
BranchTrueFalseTotal
ref $tree or return $tag, {"_", $simple} 1 10 11
657 10 my $node = $tree->node;
658 10 my @pairs = map $_->($node), @attrs;
659 10 ▶ defined $simple || @pairs ? ($tag => {_ => $simple, @pairs}) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $simple || @pairs ? : 10 0 10
Condition33%1/3
defined $simple or @pairs
l!l&&r!l&&!r
1000
MC/DC0%0/2
defined $simple or @pairs
defined $simple @pairs
Truth table33%1/3
A or B
A= defined $simpleB= @pairs
ABresult
1X1
011
000
660 10 };
661 }
662  
663 #
664 # complexType mixed or complexContent mixed
665 #
666  
667 sub makeMixedElement
668 6 ▶{ my ($self, $path, $tag, $elems, $attrs, $attrs_any,undef,$is_nillable) = @_;
Subroutine makeMixedElement: called CC=9 SCAR=23.2
Pod undocumented
669 6 my @attrs = (odd_elements(@$attrs), @$attrs_any);
670 my $mixed = $self->{mixed_elements}
671 6 ▶ or panic "how to handle mixed?";
Branch: 1 branch
BranchTrueFalseTotal
my $mixed = $self->{"mixed_elements"} or &panic("how to handle mixed?") 0 6 6
672 6 ▶$is_nillable and panic "nillable mixed not yet supported";
Branch: 1 branch
BranchTrueFalseTotal
$is_nillable and &panic("nillable mixed not yet supported") 0 6 6
673  
674 ref $mixed eq 'CODE'
675 1 ▶ ? sub { my $tree = shift or return;
Subroutine __ANON__: called CC=4 SCAR=14.9
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return 0 1 1
676 1 ▶ my $node = $tree->node or return;
Branch: 1 branch
BranchTrueFalseTotal
my $node = $tree->node or return 0 1 1
677 1 my @v = $mixed->($path, $node);
678 1 ▶ @v ? ($tag => $v[0]) : ();
Branch: 1 branch
BranchTrueFalseTotal
@v ? : 1 0 1
679 }
680  
681 : $mixed eq 'XML_NODE'
682 1 ▶ ? sub {$_[0] ? ($tag => $_[0]->node) : () }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
683  
684 : $mixed eq 'ATTRIBUTES'
685 2 ▶ ? sub { my $tree = shift or return;
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return 0 2 2
686 2 my $node = $tree->node;
687 2 my @pairs = map $_->($node), @attrs;
688 2 ($tag => { _ => $node, @pairs
689 , _MIXED_ELEMENT_MODE => 'ATTRIBUTES'});
690 }
691 : $mixed eq 'TEXTUAL'
692 1 ▶ ? sub { my $tree = shift or return;
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return 0 1 1
693 1 my $node = $tree->node;
694 1 my @pairs = map $_->($node), @attrs;
695 1 ($tag => { _ => $node->textContent, @pairs
696 , _MIXED_ELEMENT_MODE => 'TEXTUAL'});
697 }
698 : $mixed eq 'XML_STRING'
699 1 ▶ ? sub { my $tree = shift or return;
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return 0 1 1
700 1 ▶ my $node = $tree->node or return;
Branch: 1 branch
BranchTrueFalseTotal
my $node = $tree->node or return 0 1 1
701 1 ($tag => $node->toString);
702 }
703 6 ▶ : $mixed eq 'STRUCTURAL'
Branch: 6 branches
BranchTrueFalseTotal
ref $mixed eq 'CODE' ? : 1 5 6
$mixed eq 'XML_NODE' ? : 1 4 5
$mixed eq 'ATTRIBUTES' ? : 2 2 4
$mixed eq 'TEXTUAL' ? : 1 1 2
$mixed eq 'XML_STRING' ? : 1 0 1
$mixed eq 'STRUCTURAL' ? : 0 0 0
704  
705 # this cannot be reached, because handled somewhere else
706 ? panic "mixed structural handled as normal element"
707  
708 : error __x"unknown mixed_elements value `{value}'", value => $mixed;
709 }
710  
711 #
712 # simpleType
713 #
714  
715 sub makeSimpleElement
716 635 ▶{ my ( $self, $path, $tag, $st, undef, undef, $comptype, $is_nillable) = @_;
Subroutine makeSimpleElement: called CC=2 SCAR=7.0
Pod undocumented
717  
718 $is_nillable
719 15 ▶ ? sub { my $tree = shift or return $st->(undef);
Subroutine __ANON__: called CC=5 SCAR=16.3
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return &$st(undef) 1 14 15
720 14 ▶ my $value = (ref $tree && $tree->nodeNil) ? 'NIL' : $st->($tree);
Branch: 1 branch
BranchTrueFalseTotal
ref $tree && $tree->nodeNil ? : 9 5 14
Condition66%2/3
ref $tree and $tree->nodeNil
!ll&&!rl&&r
059
MC/DC50%1/2
ref $tree and $tree->nodeNil
ref $tree $tree->nodeNil
Truth table66%2/3
A and B
A= ref $treeB= $tree->nodeNil
ABresult
0X0
100
111
721 14 ▶ defined $value ? ($tag => $value) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 14 0 14
722 }
723 577 ▶ : sub { my $value = $st->(@_);
Subroutine __ANON__: called CC=2 SCAR=6.9
724 545 ▶ defined $value ? ($tag => $value) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 507 38 545
725 635 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$is_nillable ? : 14 621 635
726  
727 }
728  
729 sub default_anytype_handler($$)
730 1 ▶{ my ($path, $node) = @_;
Subroutine default_anytype_handler: called CC=3 SCAR=11.4
Pod undocumented
731 1 ▶ ref $node or return $node;
Branch: 1 branch
BranchTrueFalseTotal
ref $node or return $node 0 1 1
732 1 ▶ (first{ UNIVERSAL::isa($_, 'XML::LibXML::Element') } $node->childNodes)
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { UNIVERSAL::isa($_, 'XML::LibXML::Element'); } , $node->childNodes) ? : 0 1 1
733 ? $node : $node->textContent;
734 }
735  
736 sub makeBuiltin
737 771 ▶{ my ($self, $path, $node, $type, $def, $check_values) = @_;
Subroutine makeBuiltin: called CC=8 SCAR=22.0
Pod undocumented
738  
739 771 ▶ if($type =~ m/}anyType$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /}anyType$/) 8 763 771
740 {
741 8 ▶ if(my $a = $self->{any_type})
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = $self->{'any_type'}) { } 1 7 8
742 { return sub {
743 1 ▶ my $node
Subroutine __ANON__: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] && UNIVERSAL::isa($_[0], 'XML::Compile::Iterator') ? : 1 0 1
Condition33%1/3
ref $_[0] and UNIVERSAL::isa($_[0], "XML::Compile::Iterator")
!ll&&!rl&&r
001
MC/DC0%0/2
ref $_[0] and UNIVERSAL::isa($_[0], "XML::Compile::Iterator")
ref $_[0] UNIVERSAL::isa($_[0], "XML::Compile::Iterator")
Truth table33%1/3
A and B
A= ref $_[0]B= UNIVERSAL::isa($_[0], "XML::Compile::Iterator")
ABresult
0X0
100
111
744 = ref $_[0] && UNIVERSAL::isa($_[0], 'XML::Compile::Iterator')
745 ? $_[0]->node : $_[0];
746 1 $a->( $path, $node, \&default_anytype_handler)};
747 }
748 else
749 { return sub
750 7 ▶ { ref $_[0] or return $_[0];
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] or return $_[0] 0 7 7
751 7 ▶ my $node = UNIVERSAL::isa($_[0], 'XML::Compile::Iterator')
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_[0], 'XML::Compile::Iterator') ? : 5 2 7
752 ? $_[0]->node : $_[0];
753 5 ▶ (first{ UNIVERSAL::isa($_, 'XML::LibXML::Element') }
Subroutine __ANON__: called CC=1 SCAR=0.0
754 7 ▶ $node->childNodes) ? $node : $node->textContent;
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { UNIVERSAL::isa($_, 'XML::LibXML::Element'); } , $node->childNodes) ? : 1 6 7
755 7 };
756 }
757 }
758  
759 763 ▶ my $check = $check_values ? $def->{check} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$check_values ? : 763 0 763
760 763 my $parse = $def->{parse};
761 763 ▶ my $err = $path eq $type
Branch: 1 branch
BranchTrueFalseTotal
$path eq $type ? : 1 762 763
762 ? N__"illegal value `{value}' for type {type}"
763 : N__"illegal value `{value}' for type {type} at {path}";
764  
765 $check
766 ? ( defined $parse
767 634 ▶ ? sub { my $value = ref $_[0] ? $_[0]->textContent : $_[0];
Subroutine __ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 563 71 634
768 634 ▶ defined $value or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $value or return undef 39 595 634
769 595 ▶ return $parse->($value, $_[1]||$_[0])
Branch: 1 branch
BranchTrueFalseTotal
if &$check($value) 586 9 595
Condition66%2/3
$_[1] || $_[0]
l!l&&r!l&&!r
185680
MC/DC0%0/2
$_[1] || $_[0]
$_[1] $_[0]
Truth table66%2/3
A || B
A= $_[1]B= $_[0]
ABresult
1X1
011
000
770 if $check->($value);
771 9 error __x$err, value => $value, type => $type, path => $path;
772 }
773 0 ▶ : sub { my $value = ref $_[0] ? $_[0]->textContent : $_[0];
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
774 0 ▶ defined $value or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $value or return undef 0 0 0
775 0 ▶ return $value if $check->($value);
Branch: 1 branch
BranchTrueFalseTotal
if &$check($value) 0 0 0
776 0 error __x$err, value => $value, type => $type, path => $path;
777 }
778 )
779  
780 : ( defined $parse
781 13 ▶ ? sub { my $value = ref $_[0] ? $_[0]->textContent : $_[0];
Subroutine __ANON__: called CC=4 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 7 6 13
782 13 ▶ defined $value or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $value or return undef 0 13 13
783 13 ▶ $parse->($value, $_[1]||$_[0]);
Condition66%2/3
$_[1] || $_[0]
l!l&&r!l&&!r
2110
MC/DC0%0/2
$_[1] || $_[0]
$_[1] $_[0]
Truth table66%2/3
A || B
A= $_[1]B= $_[0]
ABresult
1X1
011
000
784 }
785 52 ▶ : sub { ref $_[0] ? shift->textContent : $_[0] }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 46 6 52
786 763 ▶ );
Branch: 3 branches
BranchTrueFalseTotal
$check ? : 679 84 763
defined $parse ? : 679 0 679
defined $parse ? : 10 74 84
787 }
788  
789 sub makeList
790 12 ▶{ my ($self, $path, $st) = @_;
Subroutine makeList: called CC=1 SCAR=0.0
Pod undocumented
791 12 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=6 SCAR=18.3
792 12 ▶ defined $tree or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $tree or return undef 0 12 12
793 12 ▶ my $node
Branch: 2 branches
BranchTrueFalseTotal
UNIVERSAL::isa($tree, 'XML::LibXML::Node') ? : 0 12 12
ref $tree ? : 10 2 12
794 = UNIVERSAL::isa($tree, 'XML::LibXML::Node') ? $tree
795 : ref $tree ? $tree->node : undef;
796 12 ▶ my $v = ref $tree ? $tree->textContent : $tree;
Branch: 1 branch
BranchTrueFalseTotal
ref $tree ? : 10 2 12
797 12 my @v = grep defined, map $st->($_, $node), split " ", $v;
798 12 ▶ @v ? \@v : undef;
Branch: 1 branch
BranchTrueFalseTotal
@v ? : 12 0 12
799 12 };
800 }
801  
802 sub makeFacetsList
803 4 ▶{ my ($self, $path, $st, $info, $early, $late) = @_;
Subroutine makeFacetsList: called CC=2 SCAR=10.9
Pod undocumented
804 4 my @e = grep defined, @$early;
805 4 my @l = grep defined, @$late;
806  
807 # enumeration and pattern are probably rare
808 @e or return sub {
809 4 ▶ my $values = $st->(@_) or return;
Subroutine __ANON__: called CC=3 SCAR=11.2
Branch: 1 branch
BranchTrueFalseTotal
my $values = &$st(@_) or return 0 4 4
810 4 $_->($values) for @l;
811 3 $values;
812 4 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
@e or return sub { my $values = &$st(@_) or return; &$_($values) foreach (@l); $values; } 4 0 4
813  
814 0 ▶ sub { defined $_[0] or return undef;
Subroutine __ANON__: not called CC=6 SCAR=37.4
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] or return undef 0 0 0
815 0 ▶ my $list = ref $_[0] ? $_[0]->textContent : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
816 0 $_->($list) for @e;
817 0 ▶ my $values = $st->($_[0]) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $values = &$st($_[0]) or return 0 0 0
818 0 $_->($values) for @l;
819 0 $values;
820 0 };
821 }
822  
823 sub makeFacets
824 87 ▶{ my ($self, $path, $st, $info, $early, $late) = @_;
Subroutine makeFacets: called CC=4 SCAR=13.9
Pod undocumented
825 87 ▶ @$early || @$late or return $st;
Branch: 1 branch
BranchTrueFalseTotal
@$early or @$late or return $st 1 86 87
Condition100%3/3
@$early or @$late
l!l&&r!l&&!r
14721
MC/DC100%2/2
@$early or @$late
@$early @$late
Truth table100%3/3
A or B
A= @$earlyB= @$late
ABresult
1X1
011
000
826  
827 86 ▶ unless(@$early)
Branch: 1 branch
BranchTrueFalseTotal
unless (@$early) 72 14 86
828 { return sub {
829 70 ▶ my $v = $st->(shift);
Subroutine __ANON__: called CC=3 SCAR=11.1
830 69 ▶ defined $v or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $v or return undef 0 69 69
831 69 $v = $_->($v) for @$late;
832 45 $v;
833 72 };
834 }
835  
836 sub {
837 12 ▶ my $v = shift;
Subroutine __ANON__: called CC=6 SCAR=18.5
838 12 ▶ if(@$early)
Branch: 1 branch
BranchTrueFalseTotal
if (@$early) 12 0 12
839 12 ▶ { return if !defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 12 12
840 12 $v = $_->($v) for @$early;
841 }
842 9 $v = $st->($v);
843 9 ▶ defined $v or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $v or return undef 0 9 9
844 9 $v = $_->($v) for @$late;
845 9 $v;
846 14 };
847 }
848  
849 sub makeUnion
850 12 ▶{ my ($self, $path, @types) = @_;
Subroutine makeUnion: called CC=1 SCAR=0.0
Pod undocumented
851 12 ▶ sub { my $tree = shift or return undef;
Subroutine __ANON__: called CC=5 SCAR=16.2
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return undef 0 12 12
852 12 ▶ for(@types) { my $v = try { $_->($tree) }; $@ or return $v }
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$@ or return $v 10 12 22
853 2 my $text = $tree->textContent;
854  
855 2 ▶ substr $text, 20, -5, '...' if length($text) > 50;
Branch: 1 branch
BranchTrueFalseTotal
if length $text > 50 0 2 2
856 2 error __x"no match for `{text}' in union at {path}"
857 , text => $text, path => $path;
858 12 };
859 }
860  
861 # Attributes
862  
863 sub makeAttributeRequired
864 12 ▶{ my ($self, $path, $ns, $tag, $label, $do) = @_;
Subroutine makeAttributeRequired: called CC=1 SCAR=0.0
Pod undocumented
865 12 ▶ sub { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=4 SCAR=14.1
866 12 ▶ defined $node
Branch: 1 branch
BranchTrueFalseTotal
defined $node or &error(&__x("attribute `{name}' is required at {path}", "name", $tag, "path", $path)) 1 11 12
867 or error __x"attribute `{name}' is required at {path}"
868 , name => $tag, path => $path;
869  
870 11 ▶ defined $node or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $node or return () 0 11 11
871 11 my $value = $do->($node);
872 11 ▶ defined $value ? ($label => $value) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 11 0 11
873 12 };
874 }
875  
876 sub makeAttributeProhibited
877 3 ▶{ my ($self, $path, $ns, $tag, $label, $do) = @_;
Subroutine makeAttributeProhibited: called CC=1 SCAR=0.0
Pod undocumented
878 3 ▶ sub { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=2 SCAR=7.0
879 3 ▶ defined $node or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $node or return () 2 1 3
880 1 error __x"attribute `{name}' is prohibited at {path}"
881 , name => $tag, path => $path;
882 0 ();
883 3 };
884 }
885  
886 sub makeAttribute
887 93 ▶{ my ($self, $path, $ns, $tag, $label, $do) = @_;
Subroutine makeAttribute: called CC=1 SCAR=0.0
Pod undocumented
888 92 ▶ sub { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=3 SCAR=11.0
889 92 ▶ defined $node or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $node or return () 22 70 92
890 70 my $val = $do->($node);
891 68 ▶ defined $val ? ($label => $val) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 68 0 68
892 93 };
893 }
894  
895 sub makeAttributeDefault
896 7 ▶{ my ($self, $path, $ns, $tag, $label, $do, $default) = @_;
Subroutine makeAttributeDefault: called CC=4 SCAR=13.9
Pod undocumented
897  
898 7 my $mode = $self->{default_values};
899 $mode eq 'IGNORE'
900 and return sub
901 3 ▶ { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=2 SCAR=6.9
902 7 ▶ defined $node ? ($label => $do->($node)) : () };
Branch: 2 branches
BranchTrueFalseTotal
$mode eq "IGNORE" and return sub { my $node = $_[0]->getAttributeNodeNS($ns, $tag); defined $node ? ($label, &$do($node)) : (); } 2 5 7
defined $node ? : 2 1 3
903  
904 5 my $def = $do->($default);
905  
906 $mode eq 'EXTEND'
907 and return sub
908 4 ▶ { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=2 SCAR=6.9
909 4 ▶ ($label => ($node ? $do->($node) : $def))
Branch: 1 branch
BranchTrueFalseTotal
$node ? : 2 2 4
910 5 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$mode eq "EXTEND" and return sub { my $node = $_[0]->getAttributeNodeNS($ns, $tag); $label, $node ? &$do($node) : $def; } 3 2 5
911  
912 $mode eq 'MINIMAL'
913 and return sub
914 3 ▶ { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=4 SCAR=13.9
915 3 ▶ my $v = $node ? $do->($node) : $def;
Branch: 1 branch
BranchTrueFalseTotal
$node ? : 2 1 3
916 3 ▶ !defined $v || $v eq $def ? () : ($label => $v);
Branch: 1 branch
BranchTrueFalseTotal
!defined($v) || $v eq $def ? : 2 1 3
Condition66%2/3
not defined $v or $v eq $def
l!l&&r!l&&!r
021
MC/DC50%1/2
not defined $v or $v eq $def
not defined $v $v eq $def
Truth table66%2/3
not(A) or B
A= not defined $vB= $v eq $def
ABresult
1X1
011
000
917 2 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$mode eq "MINIMAL" and return sub { my $node = $_[0]->getAttributeNodeNS($ns, $tag); my $v = $node ? &$do($node) : $def; !defined($v) || $v eq $def ? () : ($label, $v); } 2 0 2
918  
919 0 error __x"illegal default_values mode `{mode}'", mode => $mode;
920 }
921  
922 sub makeAttributeFixed
923 5 ▶{ my ($self, $path, $ns, $tag, $label, $do, $fixed) = @_;
Subroutine makeAttributeFixed: called CC=1 SCAR=0.0
Pod undocumented
924 5 my $def = $do->($fixed);
925  
926 5 ▶ sub { my $node = $_[0]->getAttributeNodeNS($ns, $tag)
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
my $node = $_[0]->getAttributeNodeNS($ns, $tag) or return $label, $def 1 4 5
927 or return ($label => $def);
928  
929 4 my $value = $do->($node);
930 4 ▶ defined $value && $value eq $def
Branch: 1 branch
BranchTrueFalseTotal
defined $value and $value eq $def or &error(&__x("value of attribute `{tag}' is fixed to `{fixed}', not `{value}' at {path}", "tag", $tag, "fixed", $def, "value", $value, "path", $path)) 1 3 4
Condition66%2/3
defined $value and $value eq $def
!ll&&!rl&&r
013
MC/DC50%1/2
defined $value and $value eq $def
defined $value $value eq $def
Truth table66%2/3
A and B
A= defined $valueB= $value eq $def
ABresult
0X0
100
111
931 or error __x"value of attribute `{tag}' is fixed to `{fixed}', not `{value}' at {path}"
932 , tag => $tag, fixed => $def, value => $value, path => $path;
933  
934 3 ($label => $def);
935 5 };
936 }
937  
938 # SubstitutionGroups
939  
940 sub makeSubstgroup
941 9 ▶{ my ($self, $path, $base, %do) = @_;
Subroutine makeSubstgroup: called CC=2 SCAR=7.2
Pod undocumented
942 9 ▶ keys %do or return bless sub { () }, 'BLOCK';
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
keys %do or return bless(sub { (); } , "BLOCK") 0 9 9
943  
944 bless
945 14 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=5 SCAR=16.5
946 14 ▶ my $type = ($tree ? $tree->currentType : undef)
Branch: 2 branches
BranchTrueFalseTotal
my $type = $tree ? $tree->currentType : undef or &error(&__x("no data for substitution group {type} at {path}", "type", $base, "path", $path, "class", "misfit")) 0 14 14
$tree ? : 14 0 14
947 or error __x"no data for substitution group {type} at {path}"
948 , type => $base, path => $path, class => 'misfit';
949  
950 14 ▶ my $do = $do{$type} or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $do = $do{$type} or return () 3 11 14
951 11 my @subst = $do->[1]($tree->descend);
952 10 ▶ @subst or return ();
Branch: 1 branch
BranchTrueFalseTotal
@subst or return () 0 10 10
953  
954 10 $tree->nextChild;
955 10 ($do->[0] => $subst[1]); # key-rewrite
956 9 }, 'BLOCK';
957 }
958  
959 # anyAttribute
960  
961 sub makeAnyAttribute
962 5 ▶{ my ($self, $path, $handler, $yes, $no, $process) = @_;
Subroutine makeAnyAttribute: called CC=6 SCAR=17.9
Pod undocumented
963 5 ▶ return () unless defined $handler;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $handler 1 4 5
964  
965 4 ▶ my %yes = map +($_ => 1), @{$yes || []};
Branch: 1 branch
BranchTrueFalseTotal
$yes or [] 3 1 4
966 4 ▶ my %no = map +($_ => 1), @{$no || []};
Branch: 1 branch
BranchTrueFalseTotal
$no or [] 1 3 4
967  
968 # Takes all, before filtering
969 my $all =
970 4 ▶ sub { my @result;
Subroutine __ANON__: called CC=9 SCAR=22.0
971 4 foreach my $attr ($_[0]->attributes)
972 16 ▶ { $attr->isa('XML::LibXML::Attr') or next;
Branch: 1 branch
BranchTrueFalseTotal
$attr->isa("XML::LibXML::Attr") or next 8 8 16
973 8 ▶ my $ns = $attr->namespaceURI || $_[0]->namespaceURI || '';
Condition60%3/5
$attr->namespaceURI || $_[0]->namespaceURI || ''
l!l
80
$attr->namespaceURI or $_[0]->namespaceURI
l!l&&r!l&&!r
440
MC/DC0%0/2
$attr->namespaceURI || $_[0]->namespaceURI || ''
$attr->namespaceURI $_[0]->namespaceURI
Truth table66%2/3
A or B
A= $attr->namespaceURIB= $_[0]->namespaceURI
ABresult
1X1
011
000
974 8 ▶ next if keys %yes && !$yes{$ns};
Branch: 1 branch
BranchTrueFalseTotal
if keys %yes and not $yes{$ns} 1 7 8
Condition100%3/3
keys %yes and not $yes{$ns}
!ll&&!rl&&r
611
MC/DC100%2/2
keys %yes and not $yes{$ns}
keys %yes not $yes{$ns}
Truth table100%3/3
A and not(B)
A= keys %yesB= not $yes{$ns}
ABresult
0X0
100
111
975 7 ▶ next if keys %no && $no{$ns};
Branch: 1 branch
BranchTrueFalseTotal
if keys %no and $no{$ns} 1 6 7
Condition100%3/3
keys %no and $no{$ns}
!ll&&!rl&&r
511
MC/DC100%2/2
keys %no and $no{$ns}
keys %no $no{$ns}
Truth table100%3/3
A and B
A= keys %noB= $no{$ns}
ABresult
0X0
100
111
976  
977 6 push @result, pack_type($ns, $attr->localName) => $attr;
978 }
979 4 @result;
980 4 };
981  
982 4 weaken $self;
983  
984 # Create filter if requested
985 my $run = $handler eq 'TAKE_ALL' ? $all
986 : ref $handler ne 'CODE'
987 ? error(__x"any_attribute handler `{got}' not understood", got => $handler)
988 1 ▶ : sub { my @attrs = $all->(@_);
Subroutine __ANON__: called CC=3 SCAR=11.0
989 1 my @result;
990 1 ▶ while(@attrs)
Branch: 1 branch
BranchTrueFalseTotal
if (@attrs) 2 1 3
991 2 { my ($type, $data) = (shift @attrs, shift @attrs);
992 2 my ($label, $out) = $handler->($type, $data, $path, $self);
993 2 ▶ push @result, $label, $out if defined $label;
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 1 1 2
994 }
995 1 @result;
996 4 ▶ };
Branch: 2 branches
BranchTrueFalseTotal
$handler eq 'TAKE_ALL' ? : 3 1 4
ref $handler ne 'CODE' ? : 0 1 1
997  
998 4 bless $run, 'ANY';
999 }
1000  
1001 # anyElement
1002  
1003 sub makeAnyElement
1004 5 ▶{ my ($self, $path, $handler, $yes, $no, $process, $min, $max) = @_;
Subroutine makeAnyElement: called CC=9 SCAR=28.8
Pod undocumented
1005 5 ▶ $handler ||= 'SKIP_ALL';
Condition100%2/2
$handler ||= "SKIP_ALL"
l!l
41
MC/DC100%1/1
$handler ||= "SKIP_ALL"
$handler
Truth table100%2/2
A
A= $handler
Aresult
11
00
1006  
1007 5 ▶ my %yes = map +($_ => 1), @{$yes || []};
Branch: 1 branch
BranchTrueFalseTotal
$yes or [] 3 2 5
1008 5 ▶ my %no = map +($_ => 1), @{$no || []};
Branch: 1 branch
BranchTrueFalseTotal
$no or [] 2 3 5
1009  
1010 # Takes all, before filtering
1011 my $any = ($max eq 'unbounded' || $max > 1)
1012 ? sub
1013 5 ▶ { my $tree = shift or return ();
Subroutine __ANON__: called CC=11 SCAR=25.4
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 0 5 5
1014 5 my $count = 0;
1015 5 my %result;
1016 5 ▶ while( (my $child = $tree->currentChild)
Branch: 1 branch
BranchTrueFalseTotal
if (my $child = $tree->currentChild and $max eq "unbounded" || $count < $max) 2 5 7
Condition50%3/6
my $child = $tree->currentChild and $max eq "unbounded" || $count < $max
!ll&&!rl&&r
520
$max eq "unbounded" or $count < $max
l!l&&r!l&&!r
200
MC/DC0%0/3
my $child = $tree->currentChild and $max eq "unbounded" || $count < $max
my $child = $tree->currentChild $max eq "unbounded" $count < $max
Truth table25%1/4
A and B or C
A= my $child = $tree->currentChildB= $max eq "unbounded"C= $count < $max
ABCresult
0XX0
1000
11X1
1011
1017 && ($max eq 'unbounded' || $count < $max))
1018 2 ▶ { my $ns = $child->namespaceURI || '';
Condition50%1/2
$child->namespaceURI || ''
l!l
20
MC/DC0%0/1
$child->namespaceURI || ''
$child->namespaceURI
Truth table50%1/2
A
A= $child->namespaceURI
Aresult
11
00
1019 2 ▶ $yes{$ns} or last if keys %yes;
Branch: 1 branch
BranchTrueFalseTotal
if keys %yes 1 1 2
Condition60%3/5
keys %yes && ($yes{$ns} || (last))
!ll&&!rl&&r
110
$yes{$ns} or last
l!l
10
MC/DC0%0/2
keys %yes && ($yes{$ns} || (last))
keys %yes $yes{$ns}
Truth table33%1/3
A && B
A= keys %yesB= $yes{$ns}
ABresult
0X0
100
111
1020 2 ▶ $no{$ns} and last if keys %no;
Branch: 1 branch
BranchTrueFalseTotal
if keys %no 1 1 2
Condition60%3/5
keys %no && ($no{$ns} && (last))
!ll&&!rl&&r
110
$no{$ns} and last
!ll
10
MC/DC0%0/2
keys %no && ($no{$ns} && (last))
keys %no $no{$ns}
Truth table66%2/3
A && B
A= keys %noB= $no{$ns}
ABresult
0X0
100
111
1021  
1022 2 my $k = pack_type $ns, $child->localName;
1023 2 push @{$result{$k}}, $child;
1024 2 $count++;
1025 2 $tree->nextChild;
1026 }
1027  
1028 5 ▶ $count >= $min
Branch: 1 branch
BranchTrueFalseTotal
$count >= $min or &error(&__x("too few any elements, requires {min} and got {found}", "min", $min, "found", $count)) 0 5 5
1029 or error __x"too few any elements, requires {min} and got {found}"
1030 , min => $min, found => $count;
1031  
1032 5 %result;
1033 }
1034 : sub
1035 0 ▶ { my $tree = shift or return ();
Subroutine __ANON__: not called CC=8 SCAR=42.8
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 0 0 0
1036 0 ▶ my $child = $tree->currentChild or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $child = $tree->currentChild or return () 0 0 0
1037 0 ▶ my $ns = $child->namespaceURI || '';
Condition0%0/2
$child->namespaceURI || ''
l!l
00
MC/DC0%0/1
$child->namespaceURI || ''
$child->namespaceURI
Truth table0%0/2
A
A= $child->namespaceURI
Aresult
11
00
1038  
1039 0 ▶ (!keys %yes || $yes{$ns}) && !(keys %no && $no{$ns})
Branch: 1 branch
BranchTrueFalseTotal
!keys(%yes) || $yes{$ns} and not keys %no && $no{$ns} or return () 0 0 0
Condition0%0/9
!keys(%yes) || $yes{$ns} and not keys %no && $no{$ns}
!ll&&!rl&&r
000
not keys %yes or $yes{$ns}
l!l&&r!l&&!r
000
keys %no && $no{$ns}
!ll&&!rl&&r
000
MC/DC0%0/4
!keys(%yes) || $yes{$ns} and not keys %no && $no{$ns}
not keys %yes $yes{$ns} keys %no $no{$ns}
Truth table0%0/7
not(A) or B and not(C && D)
A= not keys %yesB= $yes{$ns}C= keys %noD= $no{$ns}
ABCDresult
00XX0
1X110
01110
1X0X1
1X101
010X1
01101
1040 or return ();
1041  
1042 0 $tree->nextChild;
1043 0 (type_of_node($child), $child);
1044 5 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$max eq 'unbounded' || $max > 1 ? : 5 0 5
Condition33%1/3
$max eq "unbounded" or $max > 1
l!l&&r!l&&!r
500
MC/DC0%0/2
$max eq "unbounded" or $max > 1
$max eq "unbounded" $max > 1
Truth table33%1/3
A or B
A= $max eq "unbounded"B= $max > 1
ABresult
1X1
011
000
1045
1046 5 bless $any, 'ANY';
1047  
1048 # I would like to weaken here, but "ANY" needs the whole compiler structure
1049 # intact: someone has to catch it.
1050 # weaken $self;
1051  
1052 # Create filter if requested
1053 my $run
1054 = $handler eq 'TAKE_ALL' ? $any
1055 1 ▶ : $handler eq 'SKIP_ALL' ? sub { $any->(@_); () }
Subroutine __ANON__: called CC=1 SCAR=0.0
1056 : ref $handler ne 'CODE'
1057 ? error(__x"any_element handler `{got}' not understood", got => $handler)
1058 0 ▶ : sub { my @elems = $any->(@_);
Subroutine __ANON__: not called CC=3 SCAR=24.8
1059 0 my @result;
1060 0 ▶ while(@elems)
Branch: 1 branch
BranchTrueFalseTotal
if (@elems) 0 0 0
1061 0 { my ($type, $data) = (shift @elems, shift @elems);
1062 0 my ($label, $out) = $handler->($type, $data, $path, $self);
1063 0 ▶ push @result, $label, $out if defined $label;
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 0 0 0
1064 }
1065 0 @result;
1066 5 ▶ };
Branch: 3 branches
BranchTrueFalseTotal
$handler eq 'TAKE_ALL' ? : 4 1 5
$handler eq 'SKIP_ALL' ? : 1 0 1
ref $handler ne 'CODE' ? : 0 0 0
1067  
1068 5 bless $run, 'ANY';
1069 }
1070  
1071 # xsi:type handling
1072  
1073 sub makeXsiTypeSwitch($$$$)
1074 3 ▶{ my ($self, $where, $elem, $default_type, $types) = @_;
Subroutine makeXsiTypeSwitch: called CC=1 SCAR=0.1
Pod undocumented
1075  
1076 sub {
1077 7 ▶ my $tree = shift or return;
Subroutine __ANON__: called CC=9 SCAR=23.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return 0 7 7
1078 7 ▶ my $node = $tree->node or return;
Branch: 1 branch
BranchTrueFalseTotal
my $node = $tree->node or return 0 7 7
1079 7 my $type = $node->getAttributeNS(SCHEMA2001i, 'type');
1080 7 my ($alt, $code);
1081 7 ▶ if($type)
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 6 1 7
1082 6 ▶ { my ($pre, $local) = $type =~ /(.*?)\:(.*)/ ? ($1, $2) : ('',$type);
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /(.*?)\:(.*)/ ? : 0 6 6
1083 6 $alt = pack_type $node->lookupNamespaceURI($pre), $local;
1084 6 ▶ $code = $types->{$alt}
Branch: 1 branch
BranchTrueFalseTotal
$code = $types->{$alt} or &error(&__x("specified xsi:type list for `{default}' does not contain `{got}'", "default", $default_type, "got", $type)) 0 6 6
1085 or error __x"specified xsi:type list for `{default}' does not contain `{got}'"
1086 , default => $default_type, got => $type;
1087 }
1088 else
1089 1 { ($alt, $code) = ($default_type, $types->{$default_type});
1090 }
1091  
1092 7 my ($t, $d) = $code->($tree);
1093 7 ▶ defined $t or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $t or return () 1 6 7
1094  
1095 6 ▶ $d = { _ => $d } if ref $d ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $d ne "HASH" 0 6 6
1096 6 ▶ $d->{XSI_TYPE} ||= $alt;
Condition33%1/3
$d->{"XSI_TYPE"} ||= $alt
l!l&&r!l&&!r
060
MC/DC0%0/2
$d->{"XSI_TYPE"} ||= $alt
$d->{"XSI_TYPE"} $alt
Truth table33%1/3
A ||= B
A= $d->{"XSI_TYPE"}B= $alt
ABresult
1X1
011
000
1097 6 ($t, $d);
1098 3 };
1099 }
1100  
1101 # any kind of hook
1102  
1103 sub makeHook($$$$$$$)
1104 11 ▶{ my ($self, $path, $r, $tag, $before, $replace, $after, $fulltype) = @_;
Subroutine makeHook: called CC=9 SCAR=22.7
Pod undocumented
1105 11 ▶ return $r unless $before || $replace || $after;
Branch: 1 branch
BranchTrueFalseTotal
unless $before or $replace or $after 0 11 11
Condition83%5/6
$before or $replace or $after
l!l&&r!l&&!r
470
$before or $replace
l!l&&r!l&&!r
317
MC/DC0%0/3
$before or $replace or $after
$before $replace $after
Truth table75%3/4
A or B or C
A= $beforeB= $replaceC= $after
ABCresult
1XX1
01X1
0011
0000
1106  
1107 1 ▶ return sub { ($_[0]->node->localName => 'SKIPPED') }
Subroutine __ANON__: called CC=1 SCAR=0.0
1108 11 ▶ if $replace && grep $_ eq 'SKIP', @$replace;
Branch: 1 branch
BranchTrueFalseTotal
if $replace and grep(($_ eq "SKIP"), @$replace) 1 10 11
Condition66%2/3
$replace and grep(($_ eq "SKIP"), @$replace)
!ll&&!rl&&r
1001
MC/DC50%1/2
$replace and grep(($_ eq "SKIP"), @$replace)
$replace grep(($_ eq "SKIP"), @$replace)
Truth table66%2/3
A and B
A= $replaceB= grep(($_ eq "SKIP"), @$replace)
ABresult
0X0
100
111
1109  
1110 10 ▶ my @replace = $replace ? map $self->_decodeReplace($path,$_),@$replace : ();
Branch: 1 branch
BranchTrueFalseTotal
$replace ? : 0 10 10
1111 10 ▶ my @before = $before ? map $self->_decodeBefore($path,$_), @$before : ();
Branch: 1 branch
BranchTrueFalseTotal
$before ? : 3 7 10
1112 10 ▶ my @after = $after ? map $self->_decodeAfter($path,$_), @$after : ();
Branch: 1 branch
BranchTrueFalseTotal
$after ? : 10 0 10
1113  
1114 10 weaken $self;
1115  
1116 sub
1117 10 ▶ { my $tree = shift or return ();
Subroutine __ANON__: called CC=9 SCAR=23.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 0 10 10
1118 10 my $xml = $tree->node;
1119 10 foreach (@before)
1120 3 { $xml = $_->($xml, $path, $fulltype);
1121 3 ▶ defined $xml or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $xml or return () 0 3 3
1122 }
1123  
1124 10 ▶ my $process = sub { $r->($tree->descend($xml)) };
Subroutine __ANON__: called CC=1 SCAR=0.0
1125 10 ▶ my @h = @replace
Branch: 1 branch
BranchTrueFalseTotal
@replace ? : 0 10 10
1126 ? map $_->($xml, $self, $path, $tag, $process, $fulltype), @replace
1127 : $process->();
1128  
1129 10 ▶ @h or return ();
Branch: 1 branch
BranchTrueFalseTotal
@h or return () 0 10 10
1130 10 ▶ my $h = @h==1 ? $h[0] : $h[1]; # detect simpleType
Branch: 1 branch
BranchTrueFalseTotal
@h == 1 ? : 0 10 10
1131 10 foreach my $after (@after)
1132 13 { $h = $after->($xml, $h, $path, $fulltype);
1133 13 ▶ defined $h or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $h or return () 0 13 13
1134 }
1135 10 ($tag => $h);
1136 10 };
1137 }
1138  
1139 sub _decodeBefore($$)
1140 3 ▶{ my ($self, $path, $call) = @_;
Subroutine _decodeBefore: called CC=3 SCAR=17.3
1141 3 ▶ return $call if ref $call eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $call eq "CODE" 3 0 3
1142  
1143 0 ▶ $call eq 'PRINT_PATH' ? sub {print "$_[1]\n"; $_[0] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1144 0 ▶ : error __x"labeled before hook `{call}' undefined for READER", call=>$call;
Branch: 1 branch
BranchTrueFalseTotal
$call eq 'PRINT_PATH' ? : 0 0 0
1145 }
1146  
1147 sub _decodeReplace($$)
1148 0 ▶{ my ($self, $path, $call) = @_;
Subroutine _decodeReplace: not called CC=3 SCAR=24.8
1149 0 ▶ return $call if ref $call eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $call eq "CODE" 0 0 0
1150  
1151 0 ▶ $call eq 'XML_NODE' ? sub { ($_[3] => $_[0]) } # don't parse XML
Subroutine __ANON__: not called CC=1 SCAR=6.9
1152 0 ▶ : error __x"labeled replace hook `{call}' undefined for READER",call=>$call;
Branch: 1 branch
BranchTrueFalseTotal
$call eq 'XML_NODE' ? : 0 0 0
1153 }
1154  
1155 my %after =
1156 1 ▶ ( PRINT_PATH => sub {print "$_[2]\n"; $_[1] }
Subroutine __ANON__: called CC=1 SCAR=0.0
1157 0 ▶ , INCLUDE_PATH => sub { my $h = $_[1];
Subroutine __ANON__: not called CC=2 SCAR=17.9
1158 0 ▶ $h = { _ => $h } if ref $h ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $h ne "HASH" 0 0 0
1159 0 $h->{_PATH} = $_[0];
1160 0 $h;
1161 }
1162 1 ▶ , XML_NODE => sub { my $h = $_[1];
Subroutine __ANON__: called CC=2 SCAR=7.0
1163 1 ▶ $h = { _ => $h } if ref $h ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $h ne "HASH" 1 0 1
1164 1 $h->{_XML_NODE} = $_[0];
1165 1 $h;
1166 }
1167 2 ▶ , ELEMENT_ORDER => sub { my ($xml, $h) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
1168 2 ▶ $h = { _ => $h } if ref $h ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $h ne "HASH" 0 2 2
1169 2 my @order = map type_of_node($_)
1170 , grep $_->isa('XML::LibXML::Element'), $xml->childNodes;
1171 2 $h->{_ELEMENT_ORDER} = \@order;
1172 2 $h;
1173 }
1174 2 ▶ , ATTRIBUTE_ORDER => sub { my ($xml, $h) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
1175 2 ▶ $h = { _ => $h } if ref $h ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $h ne "HASH" 0 2 2
1176 2 my @order = map $_->nodeName, $xml->attributes;
1177 2 $h->{_ATTRIBUTE_ORDER} = \@order;
1178 2 $h;
1179 }
1180 0 ▶ , NODE_TYPE => sub { my ($xml, $h) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
1181 0 ▶ $h = { _ => $h } if ref $h ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $h ne "HASH" 0 0 0
1182 0 $h->{_NODE_TYPE} = type_of_node $xml;
1183 0 $h;
1184 }
1185 44 );
1186  
1187 sub _decodeAfter($$)
1188 13 ▶{ my ($self, $path, $call) = @_;
Subroutine _decodeAfter: called CC=3 SCAR=11.0
1189 13 ▶ return $call if ref $call eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $call eq "CODE" 7 6 13
1190  
1191 # The 'after' can be called on a single. In that case, turn it into
1192 # a HASH for additional information.
1193 6 ▶ my $dec = $after{$call}
Branch: 1 branch
BranchTrueFalseTotal
my $dec = $after{$call} or &error(&__x("labeled after hook `{call}' undefined for READER", "call", $call)) 0 6 6
1194 or error __x"labeled after hook `{call}' undefined for READER"
1195 , call=> $call;
1196  
1197 6 $dec;
1198 }
1199  
1200 sub makeBlocked($$$)
1201 19 ▶{ my ($self, $where, $class, $type) = @_;
Subroutine makeBlocked: called CC=6 SCAR=18.7
Pod undocumented
1202 19 ▶ my $err_type = $self->prefixed($type) || $type;
Condition33%1/3
$self->prefixed($type) || $type
l!l&&r!l&&!r
1900
MC/DC0%0/2
$self->prefixed($type) || $type
$self->prefixed($type) $type
Truth table33%1/3
A || B
A= $self->prefixed($type)B= $type
ABresult
1X1
011
000
1203  
1204 # errors are produced in class=misfit to allow other choices to succeed.
1205 $class eq 'anyType'
1206 5 ▶ ? { st => sub { error __x"use of `{type}' blocked at {where}"
Subroutine __ANON__: called CC=1 SCAR=0.0
1207 , type => $err_type, where => $where, _class => 'misfit';
1208 }}
1209 : $class eq 'simpleType'
1210 2 ▶ ? { st => sub { error __x"use of {class} `{type}' blocked at {where}"
Subroutine __ANON__: called CC=1 SCAR=0.0
1211 , class => $class, type => $err_type, where => $where
1212 , _class => 'misfit';
1213 }}
1214 : $class eq 'complexType'
1215 ? { elems => [] }
1216 : $class eq 'ref'
1217 0 ▶ ? { st => sub { error __x"use of referenced `{type}' blocked at {where}"
Subroutine __ANON__: not called CC=1 SCAR=6.9
1218 , type => $err_type, where => $where, _class => 'misfit';
1219 }}
1220 19 ▶ : panic "blocking of $class for $type not implemented";
Branch: 4 branches
BranchTrueFalseTotal
$class eq 'anyType' ? : 9 10 19
$class eq 'simpleType' ? : 2 8 10
$class eq 'complexType' ? : 2 6 8
$class eq 'ref' ? : 6 0 6
1221 }
1222  
1223 #-----------------------------------
1224  
1225  
1226 44 1;
« lib/XML/Compile/Schema/Specs.pm ↑ Summary blib/lib/XML/Compile/Schema/BuiltInTypes.pm »