Compile/Translate/Reader.pm

filter: Statementstmt 89.7% 615 / 685 Branchbran 71.3% 378 / 530 Conditioncond 63.6% 142 / 223 MC/DCmcdc 43.0% 56 / 130 Subroutinesub 90.7% 137 / 151 Podpod 0.0% 0 / 39 totaltotal 75.5% 1328 / 1758 CC 364 SCAR 21.0
CC
364
Cov
79%
__ANON__
72.0
__ANON__
34.1
__ANON__
20.0
CRAP 8.1
« Compile/Schema/Specs.pm ↑ Summary Compile/Util.pm »
1 # Copyrights 2006-2024 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of distribution XML-Compile. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package XML::Compile::Translate::Reader;{
10 45 our $VERSION = '1.64';
11 }
12  
13 45 ▶use base 'XML::Compile::Translate';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 45 ▶no warnings 'once', 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 45 ▶use Log::Report 'xml-compile';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 45 ▶use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 45 ▶use Scalar::Util qw/weaken blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 45 ▶use XML::Compile::Util qw/pack_type odd_elements type_of_node SCHEMA2001i/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 45 ▶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 1361 ▶sub actsAs($) {$_[1] eq 'READER'}
Subroutine actsAs: called CC=1 SCAR=0.0
Pod undocumented
41 953 ▶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 400 ▶{ my ($self, $hooks, $typemap) = @_;
Subroutine typemapToHooks: called CC=8 SCAR=20.9
Pod undocumented
46 400 ▶ while(my($type, $action) = each %$typemap)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$typemap) 3 400 403
47 3 ▶ { defined $action or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $action or next 3 0 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 45 ▶ 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)) 1 0 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)) 1 0 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)) 1 0 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 400 $hooks;
80 }
81  
82 sub makeElementWrapper
83 394 ▶{ 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 401 ▶ sub { my $tree;
Subroutine __ANON__: called CC=6 SCAR=20.2
86 401 ▶ if(blessed $_[0] && $_[0]->isa('XML::LibXML::Iterator'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_[0]) and $_[0]->isa('XML::LibXML::Iterator')) { } 0 401 401
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa("XML::LibXML::Iterator")
!ll&&!rl&&r
40100
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 401 ▶ { my $xml = XML::Compile->dataToXML($_[0])
Branch: 1 branch
BranchTrueFalseTotal
my $xml = "XML::Compile"->dataToXML($_[0]) or return () 400 1 401
91 or return ();
92 400 ▶ $xml = $xml->documentElement
Branch: 1 branch
BranchTrueFalseTotal
if $xml->isa("XML::LibXML::Document") 0 400 400
93 if $xml->isa('XML::LibXML::Document');
94 $tree = XML::Compile::Iterator->new($xml, 'top',
95 400 ▶ sub { $_[0]->isa('XML::LibXML::Element') } );
Subroutine __ANON__: called CC=1 SCAR=0.0
96 }
97  
98 400 my $data = ($processor->($tree))[-1];
99 332 ▶ unless(defined $data)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 0 332 332
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 332 $data;
105 394 };
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)) 4 0 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 227 ▶{ my ($self, $path, @pairs) = @_;
Subroutine makeSequence: called CC=4 SCAR=13.9
Pod undocumented
134 227 ▶ if(@pairs==2)
Branch: 1 branch
BranchTrueFalseTotal
if (@pairs == 2) 89 138 227
135 89 { 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 89 ▶ : 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 83 89
$_[0] && $_[0]->currentType eq $take ? : 64 7 71
Condition66%4/6
ref $action eq "BLOCK" or ref $action eq "ANY"
l!l&&r!l&&!r
6083
$_[0] and $_[0]->currentType eq $take
!ll&&!rl&&r
0764
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 89 return bless $code, 'BLOCK';
141 }
142  
143 bless
144 153 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=6 SCAR=17.9
145 153 my @res;
146 153 my @do = @pairs;
147  
148 153 ▶ while(@do)
Branch: 1 branch
BranchTrueFalseTotal
if (@do) 344 137 481
149 344 { my ($take, $do) = (shift @do, shift @do);
150 344 ▶ push @res, ref $do eq 'BLOCK'
Branch: 1 branch
BranchTrueFalseTotal
ref $do eq 'BLOCK' || ref $do eq 'ANY' || defined $tree && $tree->currentType eq $take ? : 296 48 344
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
3426248
ref $do eq "BLOCK" or ref $do eq "ANY"
l!l&&r!l&&!r
295310
defined $tree and $tree->currentType eq $take
!ll&&!rl&&r
147262
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 137 @res;
157 138 }, '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 () 1 0 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")) 0 1 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 () 8 1 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")) 2 1 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") 10 26 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 46 21 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 45 1 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") 3 22 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 9 2 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 () 3 0 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 307 ▶{ my ($self, $path, $label, $min, $max, $process, $kind, $multi) = @_;
Subroutine makeBlockHandler: called CC=7 SCAR=20.6
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 307 ▶ if($max ne 'unbounded' && $max==1)
Branch: 1 branch
BranchTrueFalseTotal
if ($max ne "unbounded" and $max == 1) 276 31 307
Condition100%3/3
$max ne "unbounded" and $max == 1
!ll&&!rl&&r
2011276
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 276 ▶ return ($label => $process) if $min==1;
Branch: 1 branch
BranchTrueFalseTotal
if $min == 1 271 5 276
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 () 5 0 5
327 5 ▶ my $starter = $tree->currentChild or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $starter = $tree->currentChild or return () 4 1 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 31 ▶ if($max ne 'unbounded' && $min>=$max)
Branch: 1 branch
BranchTrueFalseTotal
if ($max ne "unbounded" and $min >= $max) 0 31 31
Condition66%2/3
$max ne "unbounded" and $min >= $max
!ll&&!rl&&r
20110
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 31 ▶ if($min==0)
Branch: 1 branch
BranchTrueFalseTotal
if ($min == 0) 18 13 31
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 () 18 0 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 35 11 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 29 3 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 11 ▶ sub { my $tree = shift or error __xn
Subroutine __ANON__: called CC=11 SCAR=27.2
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)) 11 0 11
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 11 my @res;
385 11 ▶ while(@res < $min)
Branch: 1 branch
BranchTrueFalseTotal
if (@res < $min) 11 9 20
386 11 { my @pairs = $process->($tree);
387 9 push @res, {@pairs};
388 }
389 9 ▶ while($max eq 'unbounded' || @res < $max)
Branch: 1 branch
BranchTrueFalseTotal
if ($max eq "unbounded" or @res < $max) 20 2 22
Condition100%3/3
$max eq "unbounded" or @res < $max
l!l&&r!l&&!r
1552
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 20 ▶ { my $starter = $tree->currentChild or last;
Branch: 1 branch
BranchTrueFalseTotal
my $starter = $tree->currentChild or last 14 6 20
391 14 ▶ my @pairs = try { $process->($tree) };
Subroutine __ANON__: called CC=1 SCAR=0.0
392 14 ▶ if($@->wasFatal(class => 'misfit'))
Branch: 2 branches
BranchTrueFalseTotal
if ($@->wasFatal('class', 'misfit')) { } 0 14 14
elsif ($@) { } 0 14 14
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 14 ▶ @pairs or last;
Branch: 1 branch
BranchTrueFalseTotal
@pairs or last 13 1 14
402 13 push @res, {@pairs};
403 }
404 9 ($multi => \@res);
405 13 };
406  
407 13 ($label => bless($code, 'BLOCK'));
408 }
409  
410 sub makeElementHandler
411 532 ▶{ my ($self, $path, $label, $min, $max, $required, $optional) = @_;
Subroutine makeElementHandler: called CC=8 SCAR=20.9
Pod undocumented
412 532 ▶ $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 531 532
413  
414 531 ▶ if($max ne 'unbounded' && $max==1)
Branch: 1 branch
BranchTrueFalseTotal
if ($max ne "unbounded" and $max == 1) 504 27 531
Condition100%3/3
$max ne "unbounded" and $max == 1
!ll&&!rl&&r
1314504
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 388 ▶ ? sub { my $tree = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
417 388 ▶ my @pairs = $required->(defined $tree ? $tree->descend :undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $tree ? : 346 42 388
418 350 ▶ $tree->nextChild if defined $tree;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tree 342 8 350
419 350 ($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 () 53 30 83
422 53 ▶ $tree->currentChild or return ();
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentChild or return () 53 0 53
423 53 my @pairs = $optional->($tree->descend);
424 52 $tree->nextChild;
425 52 ▶ @pairs or return ();
Branch: 1 branch
BranchTrueFalseTotal
@pairs or return () 52 0 52
426 52 ($label => $pairs[1]);
427 504 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$min == 1 ? : 433 71 504
428 }
429
430 27 ▶ if($max ne 'unbounded' && $min>=$max)
Branch: 1 branch
BranchTrueFalseTotal
if ($max ne "unbounded" and $min >= $max) 2 25 27
Condition100%3/3
$max ne "unbounded" and $min >= $max
!ll&&!rl&&r
13122
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 25 ▶ if(!defined $required)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $required) 22 3 25
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 () 16 6 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 40 10 50
449 40 my @pairs = $optional->($tree->descend);
450 40 ▶ @pairs or last;
Branch: 1 branch
BranchTrueFalseTotal
@pairs or last 34 6 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 3 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=9 SCAR=22.1
459 3 my @res;
460 3 ▶ while(@res < $min)
Branch: 1 branch
BranchTrueFalseTotal
if (@res < $min) 3 3 6
461 3 ▶ { my @pairs = $required->(defined $tree ? $tree->descend : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $tree ? : 3 0 3
462 3 push @res, $pairs[1];
463 3 ▶ $tree->nextChild if defined $tree;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tree 3 0 3
464 }
465 3 ▶ while(defined $tree && ($max eq 'unbounded' || @res < $max))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tree and $max eq "unbounded" || @res < $max) 4 1 5
Condition83%5/6
defined $tree and $max eq "unbounded" || @res < $max
!ll&&!rl&&r
014
$max eq "unbounded" or @res < $max
l!l&&r!l&&!r
221
MC/DC66%2/3
defined $tree and $max eq "unbounded" || @res < $max
defined $tree $max eq "unbounded" @res < $max
Truth table75%3/4
A and B or C
A= defined $treeB= $max eq "unbounded"C= @res < $max
ABCresult
0XX0
1000
11X1
1011
466 4 ▶ { $tree->currentChild or last;
Branch: 1 branch
BranchTrueFalseTotal
$tree->currentChild or last 3 1 4
467 3 my @pairs = $optional->($tree->descend);
468 3 ▶ @pairs or last;
Branch: 1 branch
BranchTrueFalseTotal
@pairs or last 2 1 3
469 2 push @res, $pairs[1];
470 2 $tree->nextChild;
471 }
472 3 ($label => \@res);
473 3 };
474 }
475  
476 sub makeRequired
477 439 ▶{ my ($self, $path, $label, $do) = @_;
Subroutine makeRequired: called CC=2 SCAR=6.9
Pod undocumented
478  
479 my $req =
480 395 ▶ sub { my $tree = shift; # can be undef
Subroutine __ANON__: called CC=2 SCAR=6.9
481 395 my @pairs = $do->($tree);
482 @pairs
483 390 ▶ 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")) 356 34 390
484 , tag => $label, path => $path, _class => 'misfit';
485 356 @pairs;
486 439 };
487 439 ▶ ref $do eq 'BLOCK' ? bless($req, 'BLOCK') : $req;
Branch: 1 branch
BranchTrueFalseTotal
ref $do eq 'BLOCK' ? : 0 439 439
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 916 ▶{ my ($self, $path, $ns, $childname, $do) = @_;
Subroutine makeElement: called CC=1 SCAR=0.0
Pod undocumented
506 876 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
507 876 ▶ my $value = defined $tree && $tree->nodeType eq $childname
Branch: 1 branch
BranchTrueFalseTotal
defined $tree && $tree->nodeType eq $childname ? : 835 41 876
Condition100%3/3
defined $tree and $tree->nodeType eq $childname
!ll&&!rl&&r
347835
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 803 ▶ defined $value ? ($childname => $value) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 763 40 803
510 916 };
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 () 2 0 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 "" 8 7 15
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 () 3 0 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 2 1 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)) 2 0 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 10 ▶{ 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 () 2 1 3
574 2 ▶ $tree->nodeType eq $childname or return ();
Branch: 1 branch
BranchTrueFalseTotal
$tree->nodeType eq $childname or return () 2 0 2
575  
576 2 error __x"abstract element `{name}' used at {path}"
577 , name => $childname, path => $path;
578 10 };
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  
589 sub _not_processed($$)
590 4 ▶{ my ($child, $path) = @_;
Subroutine _not_processed: called CC=1 SCAR=0.0
591 4 error __x"element `{name}' not processed for {path} at {where}"
592 , name => type_of_node($child), path => $path
593 , _class => 'misfit', where => $child->nodePath;
594 }
595  
596 sub makeComplexElement
597 269 ▶{ my ($self, $path, $tag, $elems, $attrs, $attrs_any,undef,$is_nillable) = @_;
Subroutine makeComplexElement: called CC=5 SCAR=16.2
Pod undocumented
598 269 my @e = @$elems; my @a = @$attrs;
599  
600 269 my @elems = odd_elements @$elems;
601 269 my @attrs = (odd_elements(@$attrs), @$attrs_any);
602  
603 $is_nillable and return
604 10 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=4 SCAR=14.1
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 10 0 10
605 10 my $node = $tree->node;
606 10 ▶ my %complex =
Branch: 1 branch
BranchTrueFalseTotal
$tree->nodeNil ? : 5 5 10
607 ( ($tree->nodeNil ? (_ => 'NIL') : (map $_->($tree), @elems))
608 , (map $_->($node), @attrs)
609 );
610  
611 10 ▶ _not_processed $tree->currentChild, $path
Branch: 1 branch
BranchTrueFalseTotal
if $tree->currentChild 0 10 10
612 if $tree->currentChild;
613  
614 10 ($tag => \%complex);
615 269 ▶ };
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 263 269
616  
617 @elems > 1 || @attrs and return
618 63 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 62 1 63
619 62 my $node = $tree->node;
620 62 my %complex = ((map $_->($tree), @elems), (map $_->($node), @attrs));
621  
622 #if($tree->currentChild)
623 #{ warn "COMPLEX ELEMS($tag) @e;@a";
624 #}
625 58 ▶ _not_processed $tree->currentChild, $path
Branch: 1 branch
BranchTrueFalseTotal
if $tree->currentChild 0 58 58
626 if $tree->currentChild;
627  
628 58 ($tag => \%complex);
629 263 ▶ };
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; } 58 205 263
Condition100%3/3
@elems > 1 or @attrs
l!l&&r!l&&!r
652205
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
630  
631 @elems || return
632 9 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 9 0 9
633 9 ▶ _not_processed $tree->currentChild, $path
Branch: 1 branch
BranchTrueFalseTotal
if $tree->currentChild 0 9 9
634 if $tree->currentChild;
635  
636 9 ($tag => {});
637 205 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
@elems or return sub { my $tree = shift() or return (); &_not_processed(scalar $tree->currentChild, $path) if $tree->currentChild; $tag, {}; } 194 11 205
638  
639 194 my $el = shift @elems;
640 190 ▶ sub { my $tree = shift or return ();
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 190 0 190
641 190 my %complex = $el->($tree);
642  
643 161 ▶ _not_processed $tree->currentChild, $path
Branch: 1 branch
BranchTrueFalseTotal
if $tree->currentChild 4 157 161
644 if $tree->currentChild;
645  
646 157 ($tag => \%complex);
647 194 };
648 }
649  
650 #
651 # complexType/simpleContent
652 #
653  
654 sub makeTaggedElement
655 10 ▶{ my ($self, $path, $tag, $st, $attrs, $attrs_any,undef,$is_nillable) = @_;
Subroutine makeTaggedElement: called CC=1 SCAR=0.1
Pod undocumented
656 10 my @attrs = (odd_elements(@$attrs), @$attrs_any);
657  
658 11 ▶ sub { my $tree = shift // return ();
Subroutine __ANON__: called CC=8 SCAR=22.1
Condition50%1/2
shift() // (return ())
l!l
110
MC/DC0%0/1
shift() // (return ())
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
659 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
660 11 ▶ ref $tree or return ($tag => {_ => $simple});
Branch: 1 branch
BranchTrueFalseTotal
ref $tree or return $tag, {"_", $simple} 10 1 11
661 10 my $node = $tree->node;
662 10 my @pairs = map $_->($node), @attrs;
663 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
664 10 };
665 }
666  
667 #
668 # complexType mixed or complexContent mixed
669 #
670  
671 sub makeMixedElement
672 6 ▶{ my ($self, $path, $tag, $elems, $attrs, $attrs_any,undef,$is_nillable) = @_;
Subroutine makeMixedElement: called CC=9 SCAR=23.2
Pod undocumented
673 6 my @attrs = (odd_elements(@$attrs), @$attrs_any);
674 my $mixed = $self->{mixed_elements}
675 6 ▶ or panic "how to handle mixed?";
Branch: 1 branch
BranchTrueFalseTotal
my $mixed = $self->{"mixed_elements"} or &panic("how to handle mixed?") 6 0 6
676  
677 6 ▶ $is_nillable
Branch: 1 branch
BranchTrueFalseTotal
$is_nillable and &panic("nillable mixed not yet supported") 0 6 6
678 and panic "nillable mixed not yet supported";
679  
680 ref $mixed eq 'CODE'
681 1 ▶ ? sub { my $tree = shift or return;
Subroutine __ANON__: called CC=4 SCAR=14.9
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return 1 0 1
682 1 ▶ my $node = $tree->node or return;
Branch: 1 branch
BranchTrueFalseTotal
my $node = $tree->node or return 1 0 1
683 1 my @v = $mixed->($path, $node);
684 1 ▶ @v ? ($tag => $v[0]) : ();
Branch: 1 branch
BranchTrueFalseTotal
@v ? : 1 0 1
685 }
686  
687 : $mixed eq 'XML_NODE'
688 1 ▶ ? sub {$_[0] ? ($tag => $_[0]->node) : () }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
689  
690 : $mixed eq 'ATTRIBUTES'
691 2 ▶ ? sub { my $tree = shift or return;
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return 2 0 2
692 2 my $node = $tree->node;
693 2 my @pairs = map $_->($node), @attrs;
694 2 ($tag => { _ => $node, @pairs
695 , _MIXED_ELEMENT_MODE => 'ATTRIBUTES'});
696 }
697 : $mixed eq 'TEXTUAL'
698 1 ▶ ? sub { my $tree = shift or return;
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return 1 0 1
699 1 my $node = $tree->node;
700 1 my @pairs = map $_->($node), @attrs;
701 1 ($tag => { _ => $node->textContent, @pairs
702 , _MIXED_ELEMENT_MODE => 'TEXTUAL'});
703 }
704 : $mixed eq 'XML_STRING'
705 1 ▶ ? sub { my $tree = shift or return;
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return 1 0 1
706 1 ▶ my $node = $tree->node or return;
Branch: 1 branch
BranchTrueFalseTotal
my $node = $tree->node or return 1 0 1
707 1 ($tag => $node->toString);
708 }
709 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
710  
711 # this cannot be reached, because handled somewhere else
712 ? panic "mixed structural handled as normal element"
713  
714 : error __x"unknown mixed_elements value `{value}'", value => $mixed;
715 }
716  
717 #
718 # simpleType
719 #
720  
721 sub makeSimpleElement
722 663 ▶{ my ( $self, $path, $tag, $st, undef, undef, $comptype, $is_nillable) = @_;
Subroutine makeSimpleElement: called CC=2 SCAR=7.0
Pod undocumented
723  
724 $is_nillable
725 15 ▶ ? sub { my $tree = shift // return $st->(undef);
Subroutine __ANON__: called CC=5 SCAR=16.3
Condition100%2/2
shift() // (return &$st(undef))
l!l
141
MC/DC100%1/1
shift() // (return &$st(undef))
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
726 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
727 14 ▶ defined $value ? ($tag => $value) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 14 0 14
728 }
729 606 ▶ : sub { my $value = $st->(@_);
Subroutine __ANON__: called CC=2 SCAR=6.9
730 570 ▶ defined $value ? ($tag => $value) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 532 38 570
731 663 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$is_nillable ? : 14 649 663
732  
733 }
734  
735 sub default_anytype_handler($$)
736 1 ▶{ my ($path, $node) = @_;
Subroutine default_anytype_handler: called CC=3 SCAR=11.4
Pod undocumented
737 1 ▶ ref $node or return $node;
Branch: 1 branch
BranchTrueFalseTotal
ref $node or return $node 1 0 1
738 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
739 ? $node : $node->textContent;
740 }
741  
742 sub makeBuiltin
743 807 ▶{ my ($self, $path, $node, $type, $def, $check_values) = @_;
Subroutine makeBuiltin: called CC=8 SCAR=21.8
Pod undocumented
744  
745 807 ▶ if($type =~ m/}anyType$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /}anyType$/) 8 799 807
746 {
747 8 ▶ if(my $a = $self->{any_type})
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = $self->{'any_type'}) { } 1 7 8
748 1 ▶ { return sub {
Subroutine __ANON__: called CC=3 SCAR=12.5
749 1 ▶ my $node
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
750 = ref $_[0] && UNIVERSAL::isa($_[0], 'XML::Compile::Iterator')
751 ? $_[0]->node : $_[0];
752 1 $a->( $path, $node, \&default_anytype_handler)};
753 }
754 else
755 { return sub
756 7 ▶ { ref $_[0] or return $_[0];
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] or return $_[0] 7 0 7
757 7 ▶ my $node = UNIVERSAL::isa($_[0], 'XML::Compile::Iterator')
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_[0], 'XML::Compile::Iterator') ? : 5 2 7
758 ? $_[0]->node : $_[0];
759 5 ▶ (first{ UNIVERSAL::isa($_, 'XML::LibXML::Element') }
Subroutine __ANON__: called CC=1 SCAR=0.0
760 7 ▶ $node->childNodes) ? $node : $node->textContent;
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { UNIVERSAL::isa($_, 'XML::LibXML::Element'); } , $node->childNodes) ? : 1 6 7
761 7 };
762 }
763 }
764  
765 799 ▶ my $check = $check_values ? $def->{check} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$check_values ? : 799 0 799
766 799 my $parse = $def->{parse};
767 799 ▶ my $err = $path eq $type
Branch: 1 branch
BranchTrueFalseTotal
$path eq $type ? : 1 798 799
768 ? N__"illegal value `{value}' for type {type}"
769 : N__"illegal value `{value}' for type {type} at {path}";
770  
771 $check
772 ? ( defined $parse
773 679 ▶ ? sub { my $value = ref $_[0] ? $_[0]->textContent : $_[0];
Subroutine __ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 576 103 679
774 679 ▶ defined $value or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $value or return undef 640 39 679
775 640 ▶ return $parse->($value, $_[1]||$_[0])
Branch: 1 branch
BranchTrueFalseTotal
if &$check($value) 628 12 640
Condition100%3/3
$_[1] || $_[0]
l!l&&r!l&&!r
385873
MC/DC100%2/2
$_[1] || $_[0]
$_[1] $_[0]
Truth table100%3/3
A || B
A= $_[1]B= $_[0]
ABresult
1X1
011
000
776 if $check->($value);
777 12 error __x$err, value => $value, type => $type, path => $path;
778 }
779 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
780 0 ▶ defined $value or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $value or return undef 0 0 0
781 0 ▶ return $value if $check->($value);
Branch: 1 branch
BranchTrueFalseTotal
if &$check($value) 0 0 0
782 0 error __x$err, value => $value, type => $type, path => $path;
783 }
784 )
785  
786 : ( defined $parse
787 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
788 13 ▶ defined $value or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $value or return undef 13 0 13
789 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
790 }
791 57 ▶ : sub { ref $_[0] ? shift->textContent : $_[0] }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 48 9 57
792 799 ▶ );
Branch: 3 branches
BranchTrueFalseTotal
$check ? : 705 94 799
defined $parse ? : 705 0 705
defined $parse ? : 10 84 94
793 }
794  
795 sub makeList
796 28 ▶{ my ($self, $path, $st) = @_;
Subroutine makeList: called CC=1 SCAR=0.0
Pod undocumented
797 27 ▶ sub { my $tree = shift // return undef;
Subroutine __ANON__: called CC=5 SCAR=16.3
Condition50%1/2
shift() // (return undef)
l!l
270
MC/DC0%0/1
shift() // (return undef)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
798 27 ▶ my $node
Branch: 2 branches
BranchTrueFalseTotal
UNIVERSAL::isa($tree, 'XML::LibXML::Node') ? : 0 27 27
ref $tree ? : 25 2 27
799 = UNIVERSAL::isa($tree, 'XML::LibXML::Node') ? $tree
800 : ref $tree ? $tree->node : undef;
801 27 ▶ my $v = ref $tree ? $tree->textContent : $tree;
Branch: 1 branch
BranchTrueFalseTotal
ref $tree ? : 25 2 27
802 27 [ grep defined, map $st->($_, $node), split " ", $v ];
803 28 };
804 }
805  
806 sub makeFacetsList
807 11 ▶{ my ($self, $path, $st, $info, $early, $late) = @_;
Subroutine makeFacetsList: called CC=2 SCAR=7.0
Pod undocumented
808 11 my @e = grep defined, @$early;
809 11 my @l = grep defined, @$late;
810  
811 # enumeration and pattern are probably rare
812 7 ▶ @e or return sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
813 7 ▶ my $values = $st->(@_) // return;
Condition50%1/2
&$st(@_) // (return)
l!l
70
MC/DC0%0/1
&$st(@_) // (return)
&$st(@_)
Truth table50%1/2
A
A= &$st(@_)
Aresult
11
00
814 7 $_->($values) for @l;
815 4 $values;
816 11 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
@e or return sub { my $values = &$st(@_) // (return); &$_($values) foreach (@l); $values; } 4 7 11
817  
818 4 ▶ sub { defined $_[0] or return undef;
Subroutine __ANON__: called CC=6 SCAR=18.8
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] or return undef 4 0 4
819 4 ▶ my $list = ref $_[0] ? $_[0]->textContent : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 4 0 4
820 4 $_->($list) for @e;
821 3 ▶ my $values = $st->($_[0]) // return;
Condition50%1/2
&$st($_[0]) // (return)
l!l
30
MC/DC0%0/1
&$st($_[0]) // (return)
&$st($_[0])
Truth table50%1/2
A
A= &$st($_[0])
Aresult
11
00
822 3 $_->($values) for @l;
823 3 $values;
824 4 };
825 }
826  
827 sub makeFacets
828 94 ▶{ my ($self, $path, $st, $info, $early, $late) = @_;
Subroutine makeFacets: called CC=4 SCAR=13.9
Pod undocumented
829 94 ▶ @$early || @$late or return $st;
Branch: 1 branch
BranchTrueFalseTotal
@$early or @$late or return $st 93 1 94
Condition100%3/3
@$early or @$late
l!l&&r!l&&!r
14791
MC/DC100%2/2
@$early or @$late
@$early @$late
Truth table100%3/3
A or B
A= @$earlyB= @$late
ABresult
1X1
011
000
830  
831 93 ▶ unless(@$early)
Branch: 1 branch
BranchTrueFalseTotal
unless (@$early) 79 14 93
832 73 ▶ { return sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
833 73 my $v = $st->(shift);
834 72 ▶ defined $v or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $v or return undef 72 0 72
835 72 $v = $_->($v) for @$late;
836 47 $v;
837 79 };
838 }
839  
840 12 ▶ sub {
Subroutine __ANON__: called CC=6 SCAR=18.6
841 12 my $v = shift;
842 12 ▶ if(@$early)
Branch: 1 branch
BranchTrueFalseTotal
if (@$early) 12 0 12
843 12 ▶ { return if !defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 12 12
844 12 $v = $_->($v) for @$early;
845 }
846 9 ▶ $v = $st->($v) // return undef;
Condition50%1/2
&$st($v) // (return undef)
l!l
90
MC/DC0%0/1
&$st($v) // (return undef)
&$st($v)
Truth table50%1/2
A
A= &$st($v)
Aresult
11
00
847 9 $v = $_->($v) for @$late;
848 9 $v;
849 14 };
850 }
851  
852 sub makeUnion
853 19 ▶{ my ($self, $path, @types) = @_;
Subroutine makeUnion: called CC=1 SCAR=0.0
Pod undocumented
854 26 ▶ sub { my $tree = shift // return undef;
Subroutine __ANON__: called CC=6 SCAR=18.0
Condition50%1/2
shift() // (return undef)
l!l
260
MC/DC0%0/1
shift() // (return undef)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
855 26 ▶ for(@types) { my $v = try { $_->($tree) }; $@ or return $v }
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$@ or return $v 16 23 39
856 3 ▶ my $text = ref $tree ? $tree->textContent : $tree;
Branch: 1 branch
BranchTrueFalseTotal
ref $tree ? : 2 1 3
857  
858 3 ▶ substr $text, 20, -5, '...' if length($text) > 50;
Branch: 1 branch
BranchTrueFalseTotal
if length $text > 50 0 3 3
859 3 error __x"no match for `{text}' in union at {path}"
860 , text => $text, path => $path;
861 19 };
862 }
863  
864 # Attributes
865  
866 sub makeAttributeRequired
867 12 ▶{ my ($self, $path, $ns, $tag, $label, $do) = @_;
Subroutine makeAttributeRequired: called CC=1 SCAR=0.0
Pod undocumented
868 12 ▶ sub { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=4 SCAR=14.1
869 12 ▶ defined $node
Branch: 1 branch
BranchTrueFalseTotal
defined $node or &error(&__x("attribute `{name}' is required at {path}", "name", $tag, "path", $path)) 11 1 12
870 or error __x"attribute `{name}' is required at {path}"
871 , name => $tag, path => $path;
872  
873 11 ▶ defined $node or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $node or return () 11 0 11
874 11 my $value = $do->($node);
875 11 ▶ defined $value ? ($label => $value) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 11 0 11
876 12 };
877 }
878  
879 sub makeAttributeProhibited
880 3 ▶{ my ($self, $path, $ns, $tag, $label, $do) = @_;
Subroutine makeAttributeProhibited: called CC=1 SCAR=0.0
Pod undocumented
881 3 ▶ sub { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=2 SCAR=7.0
882 3 ▶ defined $node or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $node or return () 1 2 3
883 1 error __x"attribute `{name}' is prohibited at {path}"
884 , name => $tag, path => $path;
885 0 ();
886 3 };
887 }
888  
889 sub makeAttribute
890 94 ▶{ my ($self, $path, $ns, $tag, $label, $do) = @_;
Subroutine makeAttribute: called CC=1 SCAR=0.0
Pod undocumented
891 94 ▶ sub { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=3 SCAR=11.0
892 94 ▶ defined $node or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $node or return () 72 22 94
893 72 my $val = $do->($node);
894 70 ▶ defined $val ? ($label => $val) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 70 0 70
895 94 };
896 }
897  
898 sub makeAttributeDefault
899 7 ▶{ my ($self, $path, $ns, $tag, $label, $do, $default) = @_;
Subroutine makeAttributeDefault: called CC=4 SCAR=13.9
Pod undocumented
900  
901 7 my $mode = $self->{default_values};
902 $mode eq 'IGNORE'
903 and return sub
904 3 ▶ { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=2 SCAR=6.9
905 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
906  
907 5 my $def = $do->($default);
908  
909 $mode eq 'EXTEND'
910 and return sub
911 4 ▶ { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=2 SCAR=6.9
912 4 ▶ ($label => ($node ? $do->($node) : $def))
Branch: 1 branch
BranchTrueFalseTotal
$node ? : 2 2 4
913 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
914  
915 $mode eq 'MINIMAL'
916 and return sub
917 3 ▶ { my $node = $_[0]->getAttributeNodeNS($ns, $tag);
Subroutine __ANON__: called CC=4 SCAR=13.9
918 3 ▶ my $v = $node ? $do->($node) : $def;
Branch: 1 branch
BranchTrueFalseTotal
$node ? : 2 1 3
919 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
920 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
921  
922 0 error __x"illegal default_values mode `{mode}'", mode => $mode;
923 }
924  
925 sub makeAttributeFixed
926 5 ▶{ my ($self, $path, $ns, $tag, $label, $do, $fixed) = @_;
Subroutine makeAttributeFixed: called CC=1 SCAR=0.0
Pod undocumented
927 5 my $def = $do->($fixed);
928  
929 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 4 1 5
930 or return ($label => $def);
931  
932 4 my $value = $do->($node);
933 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)) 3 1 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
934 or error __x"value of attribute `{tag}' is fixed to `{fixed}', not `{value}' at {path}"
935 , tag => $tag, fixed => $def, value => $value, path => $path;
936  
937 3 ($label => $def);
938 5 };
939 }
940  
941 # SubstitutionGroups
942  
943 sub makeSubstgroup
944 10 ▶{ my ($self, $path, $base, %do) = @_;
Subroutine makeSubstgroup: called CC=2 SCAR=7.2
Pod undocumented
945 0 ▶ 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") 10 0 10
946  
947 bless
948 17 ▶ sub { my $tree = shift;
Subroutine __ANON__: called CC=5 SCAR=16.5
949 17 ▶ 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")) 17 0 17
$tree ? : 17 0 17
950 or error __x"no data for substitution group {type} at {path}"
951 , type => $base, path => $path, class => 'misfit';
952  
953 17 ▶ my $do = $do{$type} or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $do = $do{$type} or return () 13 4 17
954 13 my @subst = $do->[1]($tree->descend);
955 12 ▶ @subst or return ();
Branch: 1 branch
BranchTrueFalseTotal
@subst or return () 12 0 12
956  
957 12 $tree->nextChild;
958 12 ($do->[0] => $subst[1]); # key-rewrite
959 10 }, 'BLOCK';
960 }
961  
962 # anyAttribute
963  
964 sub makeAnyAttribute
965 5 ▶{ my ($self, $path, $handler, $yes, $no, $process) = @_;
Subroutine makeAnyAttribute: called CC=6 SCAR=17.9
Pod undocumented
966 5 ▶ return () unless defined $handler;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $handler 1 4 5
967  
968 4 ▶ my %yes = map +($_ => 1), @{$yes || []};
Condition100%2/2
$yes || []
l!l
13
MC/DC100%1/1
$yes || []
$yes
Truth table100%2/2
A
A= $yes
Aresult
11
00
969 4 ▶ my %no = map +($_ => 1), @{$no || []};
Condition100%2/2
$no || []
l!l
31
MC/DC100%1/1
$no || []
$no
Truth table100%2/2
A
A= $no
Aresult
11
00
970  
971 # Takes all, before filtering
972 my $all =
973 4 ▶ sub { my @result;
Subroutine __ANON__: called CC=9 SCAR=22.0
974 4 foreach my $attr ($_[0]->attributes)
975 16 ▶ { $attr->isa('XML::LibXML::Attr') or next;
Branch: 1 branch
BranchTrueFalseTotal
$attr->isa("XML::LibXML::Attr") or next 8 8 16
976 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
977 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
978 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
979  
980 6 push @result, pack_type($ns, $attr->localName) => $attr;
981 }
982 4 @result;
983 4 };
984  
985 4 weaken $self;
986  
987 # Create filter if requested
988 my $run = $handler eq 'TAKE_ALL' ? $all
989 : ref $handler ne 'CODE'
990 ? error(__x"any_attribute handler `{got}' not understood", got => $handler)
991 1 ▶ : sub { my @attrs = $all->(@_);
Subroutine __ANON__: called CC=3 SCAR=11.0
992 1 my @result;
993 1 ▶ while(@attrs)
Branch: 1 branch
BranchTrueFalseTotal
if (@attrs) 2 1 3
994 2 { my ($type, $data) = (shift @attrs, shift @attrs);
995 2 my ($label, $out) = $handler->($type, $data, $path, $self);
996 2 ▶ push @result, $label, $out if defined $label;
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 1 1 2
997 }
998 1 @result;
999 4 ▶ };
Branch: 2 branches
BranchTrueFalseTotal
$handler eq 'TAKE_ALL' ? : 3 1 4
ref $handler ne 'CODE' ? : 0 1 1
1000  
1001 4 bless $run, 'ANY';
1002 }
1003  
1004 # anyElement
1005  
1006 sub makeAnyElement
1007 5 ▶{ my ($self, $path, $handler, $yes, $no, $process, $min, $max) = @_;
Subroutine makeAnyElement: called CC=9 SCAR=28.8
Pod undocumented
1008 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
1009  
1010 5 ▶ my %yes = map +($_ => 1), @{$yes || []};
Condition100%2/2
$yes || []
l!l
23
MC/DC100%1/1
$yes || []
$yes
Truth table100%2/2
A
A= $yes
Aresult
11
00
1011 5 ▶ my %no = map +($_ => 1), @{$no || []};
Condition100%2/2
$no || []
l!l
32
MC/DC100%1/1
$no || []
$no
Truth table100%2/2
A
A= $no
Aresult
11
00
1012  
1013 # Takes all, before filtering
1014 my $any = ($max eq 'unbounded' || $max > 1)
1015 ? sub
1016 5 ▶ { my $tree = shift or return ();
Subroutine __ANON__: called CC=11 SCAR=25.4
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 5 0 5
1017 5 my $count = 0;
1018 5 my %result;
1019 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
502
$max eq "unbounded" or $count < $max
l!l&&r!l&&!r
200
MC/DC33%1/3
my $child = $tree->currentChild and $max eq "unbounded" || $count < $max
my $child = $tree->currentChild $max eq "unbounded" $count < $max
Truth table50%2/4
A and B or C
A= my $child = $tree->currentChildB= $max eq "unbounded"C= $count < $max
ABCresult
0XX0
1000
11X1
1011
1020 && ($max eq 'unbounded' || $count < $max))
1021 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
1022 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
1023 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
1024  
1025 2 my $k = pack_type $ns, $child->localName;
1026 2 push @{$result{$k}}, $child;
1027 2 $count++;
1028 2 $tree->nextChild;
1029 }
1030  
1031 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)) 5 0 5
1032 or error __x"too few any elements, requires {min} and got {found}"
1033 , min => $min, found => $count;
1034  
1035 5 %result;
1036 }
1037 : sub
1038 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
1039 0 ▶ my $child = $tree->currentChild or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $child = $tree->currentChild or return () 0 0 0
1040 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
1041  
1042 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
1043 or return ();
1044  
1045 0 $tree->nextChild;
1046 0 (type_of_node($child), $child);
1047 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
1048
1049 5 bless $any, 'ANY';
1050  
1051 # I would like to weaken here, but "ANY" needs the whole compiler structure
1052 # intact: someone has to catch it.
1053 # weaken $self;
1054  
1055 # Create filter if requested
1056 my $run
1057 = $handler eq 'TAKE_ALL' ? $any
1058 1 ▶ : $handler eq 'SKIP_ALL' ? sub { $any->(@_); () }
Subroutine __ANON__: called CC=1 SCAR=0.0
1059 : ref $handler ne 'CODE'
1060 ? error(__x"any_element handler `{got}' not understood", got => $handler)
1061 0 ▶ : sub { my @elems = $any->(@_);
Subroutine __ANON__: not called CC=3 SCAR=24.8
1062 0 my @result;
1063 0 ▶ while(@elems)
Branch: 1 branch
BranchTrueFalseTotal
if (@elems) 0 0 0
1064 0 { my ($type, $data) = (shift @elems, shift @elems);
1065 0 my ($label, $out) = $handler->($type, $data, $path, $self);
1066 0 ▶ push @result, $label, $out if defined $label;
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 0 0 0
1067 }
1068 0 @result;
1069 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
1070  
1071 5 bless $run, 'ANY';
1072 }
1073  
1074 # xsi:type handling
1075  
1076 sub makeXsiTypeSwitch($$$$)
1077 3 ▶{ my ($self, $where, $elem, $default_type, $types) = @_;
Subroutine makeXsiTypeSwitch: called CC=1 SCAR=0.1
Pod undocumented
1078  
1079 7 ▶ sub {
Subroutine __ANON__: called CC=9 SCAR=23.0
1080 7 ▶ my $tree = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return 7 0 7
1081 7 ▶ my $node = $tree->node or return;
Branch: 1 branch
BranchTrueFalseTotal
my $node = $tree->node or return 7 0 7
1082 7 my $type = $node->getAttributeNS(SCHEMA2001i, 'type');
1083 7 my ($alt, $code);
1084 7 ▶ if($type)
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 6 1 7
1085 6 ▶ { my ($pre, $local) = $type =~ /(.*?)\:(.*)/ ? ($1, $2) : ('',$type);
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /(.*?)\:(.*)/ ? : 0 6 6
1086 6 $alt = pack_type $node->lookupNamespaceURI($pre), $local;
1087 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)) 6 0 6
1088 or error __x"specified xsi:type list for `{default}' does not contain `{got}'"
1089 , default => $default_type, got => $type;
1090 }
1091 else
1092 1 { ($alt, $code) = ($default_type, $types->{$default_type});
1093 }
1094  
1095 7 my ($t, $d) = $code->($tree);
1096 7 ▶ defined $t or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $t or return () 6 1 7
1097  
1098 6 ▶ $d = { _ => $d } if ref $d ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $d ne "HASH" 0 6 6
1099 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
1100 6 ($t, $d);
1101 3 };
1102 }
1103  
1104 # any kind of hook
1105  
1106 sub makeHook($$$$$$$)
1107 11 ▶{ my ($self, $path, $r, $tag, $before, $replace, $after, $fulltype) = @_;
Subroutine makeHook: called CC=9 SCAR=22.7
Pod undocumented
1108 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
1109  
1110 1 ▶ return sub { ($_[0]->node->localName => 'SKIPPED') }
Subroutine __ANON__: called CC=1 SCAR=0.0
1111 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
1112  
1113 10 ▶ my @replace = $replace ? map $self->_decodeReplace($path,$_),@$replace : ();
Branch: 1 branch
BranchTrueFalseTotal
$replace ? : 0 10 10
1114 10 ▶ my @before = $before ? map $self->_decodeBefore($path,$_), @$before : ();
Branch: 1 branch
BranchTrueFalseTotal
$before ? : 3 7 10
1115 10 ▶ my @after = $after ? map $self->_decodeAfter($path,$_), @$after : ();
Branch: 1 branch
BranchTrueFalseTotal
$after ? : 10 0 10
1116  
1117 10 weaken $self;
1118  
1119 sub
1120 10 ▶ { my $tree = shift or return ();
Subroutine __ANON__: called CC=9 SCAR=23.0
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or return () 10 0 10
1121 10 my $xml = $tree->node;
1122 10 foreach (@before)
1123 3 { $xml = $_->($xml, $path, $fulltype);
1124 3 ▶ defined $xml or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $xml or return () 3 0 3
1125 }
1126  
1127 10 ▶ my $process = sub { $r->($tree->descend($xml)) };
Subroutine __ANON__: called CC=1 SCAR=0.0
1128 10 ▶ my @h = @replace
Branch: 1 branch
BranchTrueFalseTotal
@replace ? : 0 10 10
1129 ? map $_->($xml, $self, $path, $tag, $process, $fulltype), @replace
1130 : $process->();
1131  
1132 10 ▶ @h or return ();
Branch: 1 branch
BranchTrueFalseTotal
@h or return () 10 0 10
1133 10 ▶ my $h = @h==1 ? $h[0] : $h[1]; # detect simpleType
Branch: 1 branch
BranchTrueFalseTotal
@h == 1 ? : 0 10 10
1134 10 foreach my $after (@after)
1135 13 { $h = $after->($xml, $h, $path, $fulltype);
1136 13 ▶ defined $h or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $h or return () 13 0 13
1137 }
1138 10 ($tag => $h);
1139 10 };
1140 }
1141  
1142 sub _decodeBefore($$)
1143 3 ▶{ my ($self, $path, $call) = @_;
Subroutine _decodeBefore: called CC=3 SCAR=17.3
1144 3 ▶ return $call if ref $call eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $call eq "CODE" 3 0 3
1145  
1146 0 ▶ $call eq 'PRINT_PATH' ? sub {print "$_[1]\n"; $_[0] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1147 0 ▶ : error __x"labeled before hook `{call}' undefined for READER", call=>$call;
Branch: 1 branch
BranchTrueFalseTotal
$call eq 'PRINT_PATH' ? : 0 0 0
1148 }
1149  
1150 sub _decodeReplace($$)
1151 0 ▶{ my ($self, $path, $call) = @_;
Subroutine _decodeReplace: not called CC=3 SCAR=24.8
1152 0 ▶ return $call if ref $call eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $call eq "CODE" 0 0 0
1153  
1154 0 ▶ $call eq 'XML_NODE' ? sub { ($_[3] => $_[0]) } # don't parse XML
Subroutine __ANON__: not called CC=1 SCAR=6.9
1155 0 ▶ : error __x"labeled replace hook `{call}' undefined for READER",call=>$call;
Branch: 1 branch
BranchTrueFalseTotal
$call eq 'XML_NODE' ? : 0 0 0
1156 }
1157  
1158 my %after =
1159 1 ▶ ( PRINT_PATH => sub {print "$_[2]\n"; $_[1] }
Subroutine __ANON__: called CC=1 SCAR=0.0
1160 0 ▶ , INCLUDE_PATH => sub { my $h = $_[1];
Subroutine __ANON__: not called CC=2 SCAR=17.9
1161 0 ▶ $h = { _ => $h } if ref $h ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $h ne "HASH" 0 0 0
1162 0 $h->{_PATH} = $_[0];
1163 0 $h;
1164 }
1165 1 ▶ , XML_NODE => sub { my $h = $_[1];
Subroutine __ANON__: called CC=2 SCAR=7.0
1166 1 ▶ $h = { _ => $h } if ref $h ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $h ne "HASH" 1 0 1
1167 1 $h->{_XML_NODE} = $_[0];
1168 1 $h;
1169 }
1170 2 ▶ , ELEMENT_ORDER => sub { my ($xml, $h) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
1171 2 ▶ $h = { _ => $h } if ref $h ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $h ne "HASH" 0 2 2
1172 2 my @order = map type_of_node($_)
1173 , grep $_->isa('XML::LibXML::Element'), $xml->childNodes;
1174 2 $h->{_ELEMENT_ORDER} = \@order;
1175 2 $h;
1176 }
1177 2 ▶ , ATTRIBUTE_ORDER => sub { my ($xml, $h) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
1178 2 ▶ $h = { _ => $h } if ref $h ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $h ne "HASH" 0 2 2
1179 2 my @order = map $_->nodeName, $xml->attributes;
1180 2 $h->{_ATTRIBUTE_ORDER} = \@order;
1181 2 $h;
1182 }
1183 0 ▶ , NODE_TYPE => sub { my ($xml, $h) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
1184 0 ▶ $h = { _ => $h } if ref $h ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $h ne "HASH" 0 0 0
1185 0 $h->{_NODE_TYPE} = type_of_node $xml;
1186 0 $h;
1187 }
1188 45 );
1189  
1190 sub _decodeAfter($$)
1191 13 ▶{ my ($self, $path, $call) = @_;
Subroutine _decodeAfter: called CC=3 SCAR=11.0
1192 13 ▶ return $call if ref $call eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $call eq "CODE" 7 6 13
1193  
1194 # The 'after' can be called on a single. In that case, turn it into
1195 # a HASH for additional information.
1196 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)) 6 0 6
1197 or error __x"labeled after hook `{call}' undefined for READER"
1198 , call=> $call;
1199  
1200 6 $dec;
1201 }
1202  
1203 sub makeBlocked($$$)
1204 19 ▶{ my ($self, $where, $class, $type) = @_;
Subroutine makeBlocked: called CC=6 SCAR=18.7
Pod undocumented
1205 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
1206  
1207 # errors are produced in class=misfit to allow other choices to succeed.
1208 $class eq 'anyType'
1209 5 ▶ ? { st => sub { error __x"use of `{type}' blocked at {where}"
Subroutine __ANON__: called CC=1 SCAR=0.0
1210 , type => $err_type, where => $where, _class => 'misfit';
1211 }}
1212 : $class eq 'simpleType'
1213 2 ▶ ? { st => sub { error __x"use of {class} `{type}' blocked at {where}"
Subroutine __ANON__: called CC=1 SCAR=0.0
1214 , class => $class, type => $err_type, where => $where
1215 , _class => 'misfit';
1216 }}
1217 : $class eq 'complexType'
1218 ? { elems => [] }
1219 : $class eq 'ref'
1220 0 ▶ ? { st => sub { error __x"use of referenced `{type}' blocked at {where}"
Subroutine __ANON__: not called CC=1 SCAR=6.9
1221 , type => $err_type, where => $where, _class => 'misfit';
1222 }}
1223 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
1224 }
1225  
1226 #-----------------------------------
1227  
1228  
1229 45 1;
« Compile/Schema/Specs.pm ↑ Summary Compile/Util.pm »