lib/XML/Compile/Translate/Template.pm

filter: Statementstmt 74.7% 367 / 491 Branchbran 61.8% 193 / 312 Conditioncond 64.0% 121 / 189 MC/DCmcdc 44.3% 47 / 106 Subroutinesub 68.9% 60 / 87 Podpod 2.5% 1 / 40 totaltotal 64.4% 789 / 1225 CC 245 SCAR 37.9
CC
245
Cov
69%
makeAnyElement
342.0
_perlAny
78.2
makeAnyAttribute
56.0
CRAP 44.1
« blib/lib/XML/Compile/Schema/Instance.pm ↑ Summary blib/lib/XML/Compile.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::Template;
10 11 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 $VERSION = '1.60';
12  
13 11 ▶use base 'XML::Compile::Translate';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶no warnings 'once', 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 11 ▶use Log::Report 'xml-compile';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 use XML::Compile::Util
22 11 ▶ qw/odd_elements even_elements SCHEMA2001i pack_type unpack_type/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 11 ▶use List::Util qw/max first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 11 ▶use vars '$VERSION'; # OODoc adds $VERSION to the script
Subroutine BEGIN: called CC=1 SCAR=0.0
26 11 ▶$VERSION ||= 'undef';
Condition50%1/2
$XML::Compile::Translate::Template::VERSION ||= "undef"
l!l
110
MC/DC0%0/1
$XML::Compile::Translate::Template::VERSION ||= "undef"
$XML::Compile::Translate::Template::VERSION
Truth table50%1/2
A
A= $XML::Compile::Translate::Template::VERSION
Aresult
11
00
27  
28  
29 sub makeTagQualified
30 31 ▶{ my ($self, $path, $node, $local, $ns) = @_;
Subroutine makeTagQualified: called CC=3 SCAR=11.0
Pod undocumented
31 31 my $prefix = $self->_registerNSprefix('', $ns, 1);
32  
33 # it is certainly not correct to do a keyRewrite here, but it works :(
34 31 ▶ $self->{_output} eq 'PERL' ? $self->keyRewrite($ns, $local)
Branch: 2 branches
BranchTrueFalseTotal
$self->{'_output'} eq 'PERL' ? : 28 3 31
length $prefix ? : 1 2 3
35 : length $prefix ? "$prefix:$local"
36 : $local;
37 }
38  
39 sub makeTagUnqualified
40 95 ▶{ my ($self, $path, $node, $local, $ns) = @_;
Subroutine makeTagUnqualified: called CC=3 SCAR=11.0
Pod undocumented
41 # $name =~ s/.*\://;
42 return $self->keyRewrite($ns, $local)
43 95 ▶ if $self->{_output} eq 'PERL';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_output"} eq "PERL" 60 35 95
44  
45 35 my $prefix = $self->_registerNSprefix('', $ns, 1);
46 35 ▶ length $prefix ? "$prefix:$local" : $local;
Branch: 1 branch
BranchTrueFalseTotal
length $prefix ? : 10 25 35
47 }
48  
49 # Detect recursion. Based on type is best, but some schema's do not
50 # have named types, so tags are indexed as well.
51 11 my (%recurse_type, %reuse_type, %recurse_tag, %reuse_tag);
52  
53 sub compile($@)
54 19 ▶{ my ($self, $type, %args) = @_;
Subroutine compile: called CC=1 SCAR=0.0
Pod documented
55 19 $self->{_output} = $args{output};
56 19 (%recurse_type, %reuse_type, %recurse_tag, %reuse_tag) = ();
57 19 $self->SUPER::compile($type, %args);
58 }
59  
60 sub actsAs($)
61 213 ▶{ my ($self, $as) = @_;
Subroutine actsAs: called CC=4 SCAR=13.9
Pod undocumented
62 ($as eq 'READER' && $self->{_output} eq 'PERL')
63 213 ▶ || ($as eq 'WRITER' && $self->{_output} eq 'XML')
Branch: 1 branch
BranchTrueFalseTotal
$as eq "READER" and $self->{"_output"} eq "PERL" or $as eq "WRITER" and $self->{"_output"} eq "XML" 158 55 213
Condition100%9/9
$as eq 'READER' && $self->{'_output'} eq 'PERL' || $as eq 'WRITER' && $self->{'_output'} eq 'XML'
l!l&&r!l&&!r
5540118
$as eq "READER" and $self->{"_output"} eq "PERL"
!ll&&!rl&&r
1283055
$as eq "WRITER" and $self->{"_output"} eq "XML"
!ll&&!rl&&r
308840
MC/DC75%3/4
$as eq 'READER' && $self->{'_output'} eq 'PERL' || $as eq 'WRITER' && $self->{'_output'} eq 'XML'
$as eq "READER" $self->{"_output"} eq "PERL" $as eq "WRITER" $self->{"_output"} eq "XML"
Truth table57%4/7
A and B || C and D
A= $as eq "READER"B= $self->{"_output"} eq "PERL"C= $as eq "WRITER"D= $self->{"_output"} eq "XML"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
64 }
65  
66 sub makeWrapperNs($$$$$)
67 4 ▶{ my ($self, $path, $processor, $index, $filter) = @_;
Subroutine makeWrapperNs: called CC=5 SCAR=16.3
Pod undocumented
68  
69 4 my @entries;
70 4 ▶ $filter = sub {1} if ref $filter ne 'CODE';
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if ref $filter ne "CODE" 4 0 4
71  
72 4 foreach my $entry (sort {$a->{prefix} cmp $b->{prefix}} values %$index)
73 16 ▶ { $entry->{used} or next;
Branch: 1 branch
BranchTrueFalseTotal
$entry->{"used"} or next 8 8 16
74 8 my ($prefix, $uri) = @{$entry}{'prefix', 'uri'};
75 8 ▶ $filter->($uri, $prefix) or next;
Branch: 1 branch
BranchTrueFalseTotal
&$filter($uri, $prefix) or next 0 8 8
76 8 push @entries, [ $uri, $prefix ];
77 8 $entry->{used} = 0;
78 }
79  
80 4 ▶ sub { my $data = $processor->(@_) or return ();
Subroutine __ANON__: called CC=4 SCAR=14.5
Branch: 1 branch
BranchTrueFalseTotal
my $data = &$processor(@_) or return () 0 4 4
81 4 ▶ if($self->{include_namespaces})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"include_namespaces"}) 4 0 4
82 4 { $data->{"xmlns:$_->[1]"} = $_->[0] for @entries;
83 }
84 4 $data;
85 4 };
86 }
87  
88 sub typemapToHooks($$)
89 19 ▶{ my ($self, $hooks, $typemap) = @_;
Subroutine typemapToHooks: called CC=5 SCAR=16.1
Pod undocumented
90  
91 19 ▶ while(my($type, $action) = each %$typemap)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$typemap) 3 19 22
92 3 ▶ { defined $action or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $action or next 0 3 3
93  
94 3 ▶ my ($struct, $example)
Branch: 2 branches
BranchTrueFalseTotal
$action =~ s/^[\\]?\&/\$/ ? : 1 2 3
$action =~ /^\$/ ? : 1 1 2
95 = $action =~ s/^[\\]?\&/\$/
96 ? ( "call on converter function with object"
97 , "$action->('WRITER', \$object, '$type', \$doc)")
98 : $action =~ m/^\$/
99 ? ( "call on converter with object"
100 , "$action->toXML(\$object, '$type', \$doc)")
101 : ( [ "calls toXML() on $action objects", " with $type and doc" ]
102 , "bless({}, '$action')" );
103  
104 3 my $details =
105 { struct => $struct
106 , example => $example
107 };
108  
109 3 ▶ push @$hooks, { type => $type, replace => sub { $details} };
Subroutine __ANON__: called CC=1 SCAR=0.0
110 }
111  
112 19 $hooks;
113 }
114  
115 sub makeElementWrapper
116 19 ▶{ my ($self, $path, $processor) = @_;
Subroutine makeElementWrapper: called CC=1 SCAR=0.0
Pod undocumented
117 19 ▶ sub { $processor->() };
Subroutine __ANON__: called CC=1 SCAR=0.0
118 }
119 11 *makeAttributeWrapper = \&makeElementWrapper;
120  
121 sub _block($@)
122 45 ▶{ my ($self, $block, $path, @pairs) = @_;
Subroutine _block: called CC=1 SCAR=0.1
123 bless
124 40 ▶ sub { my @elems = map { $_->() } odd_elements @pairs;
Subroutine __ANON__: called CC=5 SCAR=17.0
125 40 my @tags = map { $_->{tag} } @elems;
126  
127 40 local $" = ', ';
128 40 ▶ my $struct = @tags ? "$block of @tags"
Branch: 1 branch
BranchTrueFalseTotal
@tags ? : 40 0 40
129 : "empty $block from ".join(" ", even_elements @pairs);
130  
131 40 my @lines;
132 40 ▶ while(length $struct > 65)
Branch: 1 branch
BranchTrueFalseTotal
if (length $struct > 65) 0 40 40
133 0 { $struct =~ s/(.{1,60}|\S+)(?:\s+|$)//;
134 0 push @lines, $1;
135 }
136 40 ▶ push @lines, $struct
Branch: 1 branch
BranchTrueFalseTotal
if length $struct 40 0 40
137 if length $struct;
138 40 $lines[$_] =~ s/^/ / for 1..$#lines;
139  
140 40 { tag => $block
141 , elems => \@elems
142 , struct => \@lines
143 };
144 45 }, 'BLOCK';
145 }
146  
147 39 ▶sub makeSequence { my $self = shift; $self->_block(sequence => @_) }
Subroutine makeSequence: called CC=1 SCAR=0.0
Pod undocumented
148 6 ▶sub makeChoice { my $self = shift; $self->_block(choice => @_) }
Subroutine makeChoice: called CC=1 SCAR=0.0
Pod undocumented
149 0 ▶sub makeAll { my $self = shift; $self->_block(all => @_) }
Subroutine makeAll: not called CC=1 SCAR=6.9
Pod undocumented
150  
151 sub makeBlockHandler
152 45 ▶{ my ($self, $path, $label, $min, $max, $proc, $kind, $multi) = @_;
Subroutine makeBlockHandler: called CC=1 SCAR=0.0
Pod undocumented
153  
154 my $code =
155 40 ▶ sub { my $data = $proc->();
Subroutine __ANON__: called CC=13 SCAR=26.3
156 40 ▶ my $occur
Branch: 3 branches
BranchTrueFalseTotal
$max eq 'unbounded' && $min == 0 ? : 0 40 40
$max ne 'unbounded' && $max == 1 && $min == 0 ? : 0 40 40
$max ne 'unbounded' && $max == 1 && $min == 1 ? : 35 5 40
Condition80%12/15
$max eq "unbounded" and $min == 0
!ll&&!rl&&r
3910
$max ne "unbounded" and $max == 1 and $min == 0
!ll&&!rl&&r
5350
$max ne "unbounded" and $max == 1
!ll&&!rl&&r
1435
$max ne "unbounded" and $max == 1 and $min == 1
!ll&&!rl&&r
5035
$max ne "unbounded" and $max == 1
!ll&&!rl&&r
1435
MC/DC0%0/2
$max eq "unbounded" and $min == 0
$max eq "unbounded" $min == 0
MC/DC0%0/3
$max ne "unbounded" and $max == 1 and $min == 0
$max ne "unbounded" $max == 1 $min == 0
MC/DC66%2/3
$max ne "unbounded" and $max == 1 and $min == 1
$max ne "unbounded" $max == 1 $min == 1
Truth table66%2/3
A and B
A= $max eq "unbounded"B= $min == 0
ABresult
0X0
100
111
Truth table75%3/4
A and B and C
A= $max ne "unbounded"B= $max == 1C= $min == 0
ABCresult
0XX0
10X0
1100
1111
Truth table75%3/4
A and B and C
A= $max ne "unbounded"B= $max == 1C= $min == 1
ABCresult
0XX0
10X0
1100
1111
157 = $max eq 'unbounded' && $min==0 ? 'occurs any number of times'
158 : $max ne 'unbounded' && $max==1 && $min==0 ? 'is optional'
159 : $max ne 'unbounded' && $max==1 && $min==1 ? '' # the usual case
160 : "occurs $min <= # <= $max times";
161  
162 40 ▶ $data->{occur} ||= $occur if $occur;
Branch: 1 branch
BranchTrueFalseTotal
if $occur 5 35 40
Condition33%1/3
$data->{"occur"} ||= $occur
l!l&&r!l&&!r
050
MC/DC0%0/2
$data->{"occur"} ||= $occur
$data->{"occur"} $occur
Truth table33%1/3
A ||= B
A= $data->{"occur"}B= $occur
ABresult
1X1
011
000
163 40 ▶ if($max ne 'unbounded' && $max==1)
Branch: 1 branch
BranchTrueFalseTotal
if ($max ne 'unbounded' and $max == 1) { } 35 5 40
Condition100%3/3
$max ne "unbounded" and $max == 1
!ll&&!rl&&r
1435
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
164 35 { bless $data, 'BLOCK';
165 }
166 else
167 5 { $data->{tag} = $multi;
168 5 $data->{is_array} = 1;
169 5 bless $data, 'REP-BLOCK';
170 }
171 40 $data;
172 45 };
173 45 ($label => $code);
174 }
175  
176 sub makeElementHandler
177 85 ▶{ my ($self, $path, $label, $min, $max, $req, $opt) = @_;
Subroutine makeElementHandler: called CC=1 SCAR=0.0
Pod undocumented
178 80 ▶ sub { my $data = $opt->() or return;
Subroutine __ANON__: called CC=13 SCAR=25.8
Branch: 1 branch
BranchTrueFalseTotal
my $data = &$opt() or return 0 80 80
179 80 ▶ my $occur
Branch: 3 branches
BranchTrueFalseTotal
$max eq 'unbounded' && $min == 0 ? : 1 79 80
$max ne 'unbounded' && $max == 1 && $min == 0 ? : 4 75 79
$max ne 'unbounded' && $max == 1 && $min == 1 ? : 61 14 75
Condition93%14/15
$max eq "unbounded" and $min == 0
!ll&&!rl&&r
7541
$max ne "unbounded" and $max == 1 and $min == 0
!ll&&!rl&&r
14614
$max ne "unbounded" and $max == 1
!ll&&!rl&&r
41065
$max ne "unbounded" and $max == 1 and $min == 1
!ll&&!rl&&r
14061
$max ne "unbounded" and $max == 1
!ll&&!rl&&r
41061
MC/DC100%2/2
$max eq "unbounded" and $min == 0
$max eq "unbounded" $min == 0
MC/DC100%3/3
$max ne "unbounded" and $max == 1 and $min == 0
$max ne "unbounded" $max == 1 $min == 0
MC/DC66%2/3
$max ne "unbounded" and $max == 1 and $min == 1
$max ne "unbounded" $max == 1 $min == 1
Truth table100%3/3
A and B
A= $max eq "unbounded"B= $min == 0
ABresult
0X0
100
111
Truth table100%4/4
A and B and C
A= $max ne "unbounded"B= $max == 1C= $min == 0
ABCresult
0XX0
10X0
1100
1111
Truth table75%3/4
A and B and C
A= $max ne "unbounded"B= $max == 1C= $min == 1
ABCresult
0XX0
10X0
1100
1111
180 = $max eq 'unbounded' && $min==0 ? 'occurs any number of times'
181 : $max ne 'unbounded' && $max==1 && $min==0 ? 'is optional'
182 : $max ne 'unbounded' && $max==1 && $min==1 ? '' # the usual case
183 : "occurs $min <= # <= $max times";
184 80 ▶ $data->{occur} ||= $occur if $occur;
Branch: 1 branch
BranchTrueFalseTotal
if $occur 19 61 80
Condition33%1/3
$data->{"occur"} ||= $occur
l!l&&r!l&&!r
0190
MC/DC0%0/2
$data->{"occur"} ||= $occur
$data->{"occur"} $occur
Truth table33%1/3
A ||= B
A= $data->{"occur"}B= $occur
ABresult
1X1
011
000
185 80 ▶ $data->{is_array} = $max eq 'unbounded' || $max > 1;
Condition100%3/3
$max eq 'unbounded' || $max > 1
l!l&&r!l&&!r
51065
MC/DC100%2/2
$max eq 'unbounded' || $max > 1
$max eq 'unbounded' $max > 1
Truth table100%3/3
A || B
A= $max eq 'unbounded'B= $max > 1
ABresult
1X1
011
000
186 80 $data;
187 85 };
188 }
189  
190 sub makeRequired
191 78 ▶{ my ($self, $path, $label, $do) = @_;
Subroutine makeRequired: called CC=1 SCAR=0.0
Pod undocumented
192 78 $do;
193 }
194  
195 sub makeElementHref
196 0 ▶{ my ($self, $path, $ns, $childname, $do) = @_;
Subroutine makeElementHref: not called CC=1 SCAR=6.9
Pod undocumented
197 0 $do;
198 }
199  
200 sub makeElement
201 99 ▶{ my ($self, $path, $ns, $childname, $do) = @_;
Subroutine makeElement: called CC=1 SCAR=0.0
Pod undocumented
202 97 ▶ sub { my $h = $do->(@_);
Subroutine __ANON__: called CC=1 SCAR=0.0
203 97 $h->{_NAME} = $childname;
204 97 $h;
205 99 };
206 }
207  
208 sub makeElementDefault
209 0 ▶{ my ($self, $path, $ns, $childname, $do, $default) = @_;
Subroutine makeElementDefault: not called CC=1 SCAR=6.9
Pod undocumented
210 0 ▶ sub { my $h = $do->(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
211 0 $h->{occur} = "defaults to '$default'";
212 0 $h->{example} = $default;
213 0 $h;
214 0 };
215 }
216  
217 sub makeElementFixed
218 0 ▶{ my ($self, $path, $ns, $childname, $do, $fixed) = @_;
Subroutine makeElementFixed: not called CC=1 SCAR=6.9
Pod undocumented
219 0 ▶ sub { my $h = $do->(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
220 0 $h->{occur} = "fixed to '$fixed'";
221 0 $h->{example} = $fixed;
222 0 $h;
223 0 };
224 }
225  
226 sub makeElementAbstract
227 2 ▶{ my ($self, $path, $ns, $childname, $do) = @_;
Subroutine makeElementAbstract: called CC=1 SCAR=0.0
Pod undocumented
228 # sub { () };
229 sub {
230 2 ▶ my $h = $do->(@_);
Subroutine __ANON__: called CC=1 SCAR=0.0
231 2 $h->{_NAME} = $childname;
232 2 $h->{occur} = "ABSTRACT";
233 2 $h;
234 2 };
235 }
236  
237 sub makeComplexElement
238 35 ▶{ my ($self, $path, $tag, $elems, $attrs, $any_attr, $type, $is_nillable)=@_;
Subroutine makeComplexElement: called CC=1 SCAR=0.2
Pod undocumented
239 35 my @elem_parts = odd_elements @$elems;
240 35 my @attr_parts = (odd_elements(@$attrs), @$any_attr);
241  
242 30 ▶ sub { my (@attrs, @elems);
Subroutine __ANON__: called CC=10 SCAR=25.5
243 30 my $is_pseudo_type = $type !~ m/^{/; # like "unnamed complex"
244  
245 30 ▶ if((!$is_pseudo_type && $recurse_type{$type}) || $recurse_tag{$tag})
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_pseudo_type and $recurse_type{$type} or $recurse_tag{$tag}) 0 30 30
Condition50%3/6
not $is_pseudo_type and $recurse_type{$type} or $recurse_tag{$tag}
l!l&&r!l&&!r
0030
not $is_pseudo_type and $recurse_type{$type}
!ll&&!rl&&r
18120
MC/DC0%0/3
not $is_pseudo_type and $recurse_type{$type} or $recurse_tag{$tag}
not $is_pseudo_type $recurse_type{$type} $recurse_tag{$tag}
Truth table40%2/5
not(A) and B or C
A= not $is_pseudo_typeB= $recurse_type{$type}C= $recurse_tag{$tag}
ABCresult
11X1
0X11
1011
0X00
1000
246 { return
247 0 +{ kind => 'complex'
248 , struct => 'probably a recursive complex'
249 , tag => $tag
250 , _TYPE => $type
251 };
252 }
253  
254 30 ▶ if((!$is_pseudo_type && $reuse_type{$type}) || $reuse_tag{$tag})
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_pseudo_type and $reuse_type{$type} or $reuse_tag{$tag}) 0 30 30
Condition50%3/6
not $is_pseudo_type and $reuse_type{$type} or $reuse_tag{$tag}
l!l&&r!l&&!r
0030
not $is_pseudo_type and $reuse_type{$type}
!ll&&!rl&&r
18120
MC/DC0%0/3
not $is_pseudo_type and $reuse_type{$type} or $reuse_tag{$tag}
not $is_pseudo_type $reuse_type{$type} $reuse_tag{$tag}
Truth table40%2/5
not(A) and B or C
A= not $is_pseudo_typeB= $reuse_type{$type}C= $reuse_tag{$tag}
ABCresult
11X1
0X11
1011
0X00
1000
255 { return
256 0 +{ kind => 'complex'
257 , struct => 'complex structure shown above'
258 , tag => $tag
259 , _TYPE => $type
260 };
261 }
262  
263 30 $recurse_type{$type}++; $recurse_tag{$tag}++;
264 30 $reuse_type{$type}++; $reuse_tag{$tag}++;
265 30 push @elems, $_->() for @elem_parts;
266 30 push @attrs, $_->() for @attr_parts;
267  
268 30 $recurse_type{$type}--; $recurse_tag{$tag}--;
269  
270 30 ▶ +{ kind => 'complex'
Branch: 1 branch
BranchTrueFalseTotal
$is_nillable ? : 1 29 30
271 , struct => ($is_nillable ? "is nillable, as: $tag => NIL" : undef)
272 , tag => $tag
273 , attrs => \@attrs
274 , elems => \@elems
275 , _TYPE => $type
276 };
277 35 };
278 }
279  
280 sub makeTaggedElement
281 1 ▶{ my ($self, $path, $tag, $st, $attrs, $attrs_any, $type, $is_nillable) = @_;
Subroutine makeTaggedElement: called CC=1 SCAR=0.1
Pod undocumented
282 1 my @parts = (odd_elements(@$attrs), @$attrs_any);
283  
284 1 ▶ sub { my @attrs = map $_->(), @parts;
Subroutine __ANON__: called CC=5 SCAR=16.8
285 1 my %simple = $st->();
286  
287 1 my @struct = 'string content of the container';
288 1 ▶ push @struct, $simple{struct} if $simple{struct};
Branch: 1 branch
BranchTrueFalseTotal
if $simple{"struct"} 0 1 1
289 1 ▶ push @struct, 'is nillable, hence value or NIL' if $is_nillable;
Branch: 1 branch
BranchTrueFalseTotal
if $is_nillable 1 0 1
290  
291 my %content =
292 ( tag => '_'
293 , struct => \@struct
294 1 ▶ , example => ($simple{example} || 'Hello, World!')
Condition50%1/2
$simple{'example'} || 'Hello, World!'
l!l
10
MC/DC0%0/1
$simple{'example'} || 'Hello, World!'
$simple{'example'}
Truth table50%1/2
A
A= $simple{'example'}
Aresult
11
00
295 );
296 1 ▶ $content{_TYPE} = $simple{_TYPE} if $simple{_TYPE};
Branch: 1 branch
BranchTrueFalseTotal
if $simple{"_TYPE"} 1 0 1
297  
298 1 +{ kind => 'tagged'
299 , struct => "$tag is simple value with attributes"
300 , tag => $tag
301 , attrs => \@attrs
302 , elems => [ \%content ]
303 , _TYPE => $type
304 };
305 1 };
306 }
307  
308 sub makeMixedElement
309 1 ▶{ my ($self, $path, $tag, $elems, $attrs, $attrs_any, $type, $is_nillable)=@_;
Subroutine makeMixedElement: called CC=3 SCAR=12.2
Pod undocumented
310 1 my @parts = (odd_elements(@$attrs), @$attrs_any);
311  
312 1 my @struct = 'mixed content cannot be processed automatically';
313 1 ▶ push @struct, 'is nillable' if $is_nillable;
Branch: 1 branch
BranchTrueFalseTotal
if $is_nillable 0 1 1
314  
315 1 my %mixed =
316 ( tag => '_'
317 , struct => \@struct
318 , example => "XML::LibXML::Element->new('$tag')"
319 );
320  
321 1 ▶ unless(@parts) # show simpler alternative
Branch: 1 branch
BranchTrueFalseTotal
unless (@parts) 0 1 1
322 0 { $mixed{tag} = $tag;
323 0 $mixed{type} = $type;
324 0 ▶ return sub { \%mixed };
Subroutine __ANON__: not called CC=1 SCAR=6.9
325 }
326  
327 1 ▶ sub { my @attrs = map $_->(), @parts;
Subroutine __ANON__: called CC=1 SCAR=0.0
328 1 +{ kind => 'mixed'
329 , struct => "$tag has a mixed content"
330 , tag => $tag
331 , elems => [ \%mixed ]
332 , attrs => \@attrs
333 , _TYPE => $type
334 };
335 1 };
336 }
337  
338 sub makeSimpleElement
339 64 ▶{ my ($self, $path, $tag, $st, undef, undef, $type, $is_nillable) = @_;
Subroutine makeSimpleElement: called CC=1 SCAR=0.0
Pod undocumented
340 67 ▶ sub { my @struct;
Subroutine __ANON__: called CC=2 SCAR=6.9
341 67 ▶ push @struct, 'is nillable, hence value or NIL' if $is_nillable;
Branch: 1 branch
BranchTrueFalseTotal
if $is_nillable 1 66 67
342 67 +{ kind => 'simple'
343 , struct => \@struct
344 , tag => $tag
345 , $st->()
346 };
347 64 };
348 }
349  
350 sub makeBuiltin
351 90 ▶{ my ($self, $path, $node, $type, $def, $check_values) = @_;
Subroutine makeBuiltin: called CC=1 SCAR=0.0
Pod undocumented
352 90 ▶ sub { (_TYPE=> $type, example => $def->{example}) };
Subroutine __ANON__: called CC=1 SCAR=0.0
353 }
354  
355 sub makeList
356 0 ▶{ my ($self, $path, $st) = @_;
Subroutine makeList: not called CC=1 SCAR=6.9
Pod undocumented
357 0 ▶ sub { my %d = $st->();
Subroutine __ANON__: not called CC=3 SCAR=24.8
358 0 $d{struct} = 'a list of values, where each';
359 0 my $example = $d{example};
360 0 ▶ if($self->{_output} eq 'PERL')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_output'} eq 'PERL') { } 0 0 0
361 0 ▶ { $example = qq("$example") if $example =~ m/[^0-9.]/;
Branch: 1 branch
BranchTrueFalseTotal
if $example =~ /[^0-9.]/ 0 0 0
362 0 $d{example} = "[ $example , ... ]";
363 }
364 else
365 0 { $d{example} = "$example $example ...";
366 }
367 0 %d };
368 }
369  
370 sub makeFacetsList
371 0 ▶{ my ($self, $path, $st, $info) = @_;
Subroutine makeFacetsList: not called CC=1 SCAR=6.9
Pod undocumented
372 0 $self->makeFacets($path, $st, $info);
373 }
374  
375 sub _ff($@)
376 0 ▶{ my ($self,$type) = (shift, shift);
Subroutine _ff: not called CC=4 SCAR=30.0
377 0 my @lines = $type.':';
378 0 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
379 0 { my $facet = shift;
380 0 $facet =~ s/\t/\t/g;
381 0 ▶ $facet = qq{"$facet"} if $facet =~ m/\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $facet =~ /\s/ 0 0 0
382 0 ▶ push @lines, ' ' if length($lines[-1]) + length($facet) > 55;
Branch: 1 branch
BranchTrueFalseTotal
if length($lines[-1]) + length($facet) > 55 0 0 0
383 0 $lines[-1] .= ' '.$facet;
384 }
385 0 @lines;
386 }
387  
388 sub makeFacets
389 6 ▶{ my ($self, $path, $st, $info) = @_;
Subroutine makeFacets: called CC=17 SCAR=37.7
Pod undocumented
390 6 my @comment;
391 6 foreach my $k (sort keys %$info)
392 12 { my $v = $info->{$k};
393 12 ▶ push @comment
Branch: 14 branches
BranchTrueFalseTotal
$k eq 'enumeration' ? : 0 12 12
$k eq 'pattern' ? : 0 12 12
$k eq 'length' ? : 0 12 12
$k eq 'maxLength' ? : 0 12 12
$k eq 'minLength' ? : 0 12 12
$k eq 'totalDigits' ? : 0 12 12
$k eq 'maxScale' ? : 0 12 12
$k eq 'minScale' ? : 0 12 12
$k eq 'maxInclusive' ? : 0 12 12
$k eq 'maxExclusive' ? : 6 6 12
$k eq 'minInclusive' ? : 6 0 6
$k eq 'minExclusive' ? : 0 0 0
$k eq 'fractionDigits' ? : 0 0 0
$k eq 'whiteSpace' ? : 0 0 0
394 , $k eq 'enumeration' ? $self->_ff('Enum', sort @$v)
395 : $k eq 'pattern' ? $self->_ff('Pattern', @$v)
396 : $k eq 'length' ? "fixed length of $v"
397 : $k eq 'maxLength' ? "length <= $v"
398 : $k eq 'minLength' ? "length >= $v"
399 : $k eq 'totalDigits' ? "total digits is $v"
400 : $k eq 'maxScale' ? "scale <= $v"
401 : $k eq 'minScale' ? "scale >= $v"
402 : $k eq 'maxInclusive' ? "value <= $v"
403 : $k eq 'maxExclusive' ? "value < $v"
404 : $k eq 'minInclusive' ? "value >= $v"
405 : $k eq 'minExclusive' ? "value > $v"
406 : $k eq 'fractionDigits' ? "faction digits is $v"
407 : $k eq 'whiteSpace' ? "white-space $v"
408 : "restriction? $k = $v";
409 }
410  
411 6 my %facet = (facets => \@comment, $st->());
412  
413 6 ▶ if(my $enum = $info->{enumeration})
Branch: 1 branch
BranchTrueFalseTotal
if (my $enum = $info->{"enumeration"}) 0 6 6
414 0 { $facet{example} = $enum->[0];
415 }
416  
417 6 ▶ sub { %facet };
Subroutine __ANON__: called CC=1 SCAR=0.0
418 }
419  
420 sub makeUnion
421 0 ▶{ my ($self, $path, @types) = @_;
Subroutine makeUnion: not called CC=1 SCAR=6.9
Pod undocumented
422 0 ▶ sub { my @choices = map { +{$_->()} } @types;
Subroutine __ANON__: not called CC=1 SCAR=6.9
423 +( kind => 'union'
424 , struct => "one of the following (union)"
425 , choice => \@choices
426 , example => $choices[0]->{example}
427 0 );
428 0 };
429 }
430  
431 sub makeAttributeRequired
432 6 ▶{ my ($self, $path, $ns, $tag, $label, $do) = @_;
Subroutine makeAttributeRequired: called CC=1 SCAR=0.0
Pod undocumented
433  
434 6 ▶ sub { +{ kind => 'attr'
Subroutine __ANON__: called CC=1 SCAR=0.0
435 , tag => $label
436 , occur => "attribute $tag is required"
437 , $do->()
438 };
439 6 };
440 }
441  
442 sub makeAttributeProhibited
443 0 ▶{ my ($self, $path, $ns, $tag, $label, $do) = @_;
Subroutine makeAttributeProhibited: not called CC=1 SCAR=6.9
Pod undocumented
444 0 ();
445 }
446  
447 sub makeAttribute
448 19 ▶{ my ($self, $path, $ns, $tag, $label, $do) = @_;
Subroutine makeAttribute: called CC=1 SCAR=0.0
Pod undocumented
449 17 ▶ sub { +{ kind => 'attr'
Subroutine __ANON__: called CC=1 SCAR=0.0
450 , tag => $tag
451 , occur => "becomes an attribute"
452 , $do->()
453 };
454 19 };
455 }
456  
457 sub makeAttributeDefault
458 0 ▶{ my ($self, $path, $ns, $tag, $label, $do) = @_;
Subroutine makeAttributeDefault: not called CC=1 SCAR=6.9
Pod undocumented
459 sub {
460 0 ▶ +{ kind => 'attr'
Subroutine __ANON__: not called CC=1 SCAR=6.9
461 , tag => $tag
462 , occur => "attribute $tag has default"
463 , $do->()
464 };
465 0 };
466 }
467  
468 sub makeAttributeFixed
469 0 ▶{ my ($self, $path, $ns, $tag, $label, $do, $fixed) = @_;
Subroutine makeAttributeFixed: not called CC=1 SCAR=6.9
Pod undocumented
470 0 my $value = $fixed->value;
471  
472 0 ▶ sub { +{ kind => 'attr'
Subroutine __ANON__: not called CC=1 SCAR=6.9
473 , tag => $tag
474 , occur => "attribute $tag is fixed"
475 , example => $value
476 };
477 0 };
478 }
479  
480 sub makeSubstgroup
481 2 ▶{ my ($self, $path, $type, @todo) = @_;
Subroutine makeSubstgroup: called CC=1 SCAR=0.1
Pod undocumented
482  
483 sub {
484 2 ▶ my (@example_tags, $example_nest, %tags);
Subroutine __ANON__: called CC=13 SCAR=27.6
485 2 my @do = @todo;
486 2 my $group = $do[1][0];
487  
488 2 ▶ while(@do)
Branch: 1 branch
BranchTrueFalseTotal
if (@do) 6 2 8
489 6 { my ($type, $info) = (shift @do, shift @do);
490 6 my ($label, $call) = @$info;
491 6 my $processed = $call->();
492 6 my $show = '';
493 6 ▶ if($processed->{kind} eq 'substitution group')
Branch: 2 branches
BranchTrueFalseTotal
if ($processed->{'kind'} eq 'substitution group') { } 0 6 6
elsif (my $type = $processed->{'_TYPE'}) { } 6 0 6
494 { # substr extended by subst, which already is formatted.
495 # need to extract only the indicated type info.
496 0 ▶ my $s = $processed->{struct} || [];
Condition0%0/2
$processed->{'struct'} || []
l!l
00
MC/DC0%0/1
$processed->{'struct'} || []
$processed->{'struct'}
Truth table0%0/2
A
A= $processed->{'struct'}
Aresult
11
00
497 0 ▶ /^ $label (.*)/ and $show = $1 for @$s;
Branch: 1 branch
BranchTrueFalseTotal
/^ $label (.*)/ and $show = $1 0 0 0
498 }
499 elsif(my $type = $processed->{_TYPE})
500 6 { $show = $self->prefixed($type);
501 }
502  
503 6 ▶ if($processed->{occur} && $processed->{occur} eq 'ABSTRACT')
Branch: 1 branch
BranchTrueFalseTotal
if ($processed->{'occur'} and $processed->{'occur'} eq 'ABSTRACT') { } 1 5 6
Condition66%2/3
$processed->{"occur"} and $processed->{"occur"} eq "ABSTRACT"
!ll&&!rl&&r
501
MC/DC50%1/2
$processed->{"occur"} and $processed->{"occur"} eq "ABSTRACT"
$processed->{"occur"} $processed->{"occur"} eq "ABSTRACT"
Truth table66%2/3
A and B
A= $processed->{"occur"}B= $processed->{"occur"} eq "ABSTRACT"
ABresult
0X0
100
111
504 1 { $show .= ' (abstract)';
505 }
506 else
507 { # some complication to always produce the same tag for
508 # regression tests... Instance uses a HASH...
509 5 push @example_tags, $label;
510 $example_nest ||= $processed->{kind} eq 'simple'
511 5 ▶ ? ($processed->{example} || '...') : '{...}';
Branch: 1 branch
BranchTrueFalseTotal
$processed->{'kind'} eq 'simple' ? : 1 1 2
Condition60%3/5
$example_nest ||= $processed->{"kind"} eq "simple" ? $processed->{"example"} || "..." : "{...}"
l!l&&r!l&&!r
320
$processed->{"example"} or "..."
l!l
10
MC/DC0%0/2
$example_nest ||= $processed->{"kind"} eq "simple" ? $processed->{"example"} || "..." : "{...}"
$example_nest $processed->{"kind"} eq "simple" ? $processed->{"example"} || "..." : "{...}"
MC/DC0%0/1
$processed->{"example"} or "..."
$processed->{"example"}
Truth table66%2/3
A ||= B
A= $example_nestB= $processed->{"kind"} eq "simple" ? $processed->{"example"} || "..." : "{...}"
ABresult
1X1
011
000
Truth table50%1/2
A
A= $processed->{"example"}
Aresult
11
00
512 }
513
514 6 $tags{$label} = $show;
515 }
516  
517 2 my $longest = max map length, keys %tags;
518 2 my @lines = map sprintf(" %-${longest}s %s", $_, $tags{$_}),
519 sort keys %tags;
520  
521 2 my $example_tag = (sort @example_tags)[0];
522 2 ▶ my $example = $example_tag ? "{ $example_tag => $example_nest }"
Branch: 1 branch
BranchTrueFalseTotal
$example_tag ? : 2 0 2
523 : "undef # only abstract types known";
524  
525 2 my $name = $self->prefixed($type);
526  
527 2 +{ kind => 'substitution group'
528 , tag => $group
529 , struct => [ "substitutionGroup $name", @lines ]
530 , example => $example
531 };
532 2 };
533 }
534  
535 sub makeXsiTypeSwitch($$$$)
536 1 ▶{ my ($self, $where, $elem, $default_type, $types) = @_;
Subroutine makeXsiTypeSwitch: called CC=1 SCAR=0.0
Pod undocumented
537 1 my @types = map " ".$self->prefixed($_), sort keys %$types;
538 1 my $deftype = $self->prefixed($default_type);
539  
540 1 ▶ sub { +{ kind => 'xsi:type switch'
Subroutine __ANON__: called CC=1 SCAR=0.0
541 , tag => $elem
542 , struct => [ 'xsi:type alternatives:', @types ]
543 , example => "{ XSI_TYPE => '$deftype', %data }"
544 }
545 1 };
546 }
547  
548 sub makeAnyAttribute
549 0 ▶{ my ($self, $path, $handler, $yes, $no, $process) = @_;
Subroutine makeAnyAttribute: not called CC=7 SCAR=40.3
Pod undocumented
550 0 ▶ $yes ||= []; $no ||= [];
Condition0%0/4
$yes ||= []
l!l
00
$no ||= []
l!l
00
MC/DC0%0/1
$yes ||= []
$yes
MC/DC0%0/1
$no ||= []
$no
Truth table0%0/2
A
A= $yes
Aresult
11
00
Truth table0%0/2
A
A= $no
Aresult
11
00
551 0 ▶ $yes = [ map {$self->prefixed("{$_}") || $_} @$yes];
Branch: 1 branch
BranchTrueFalseTotal
$self->prefixed("{$_}") or $_ 0 0 0
552 0 ▶ $no = [ map {$self->prefixed("{$_}") || $_} @$no];
Branch: 1 branch
BranchTrueFalseTotal
$self->prefixed("{$_}") or $_ 0 0 0
553 0 ▶ my $occurs = @$yes ? "in @$yes" : @$no ? "not in @$no" : 'in any namespace';
Branch: 2 branches
BranchTrueFalseTotal
@$yes ? : 0 0 0
@$no ? : 0 0 0
554 0 ▶ bless sub { +{kind => 'attr' , struct => "any attribute $occurs"
Subroutine __ANON__: not called CC=1 SCAR=6.9
555 0 , tag => 'ANYATTR', example => 'AnySimple'} }, 'ANY';
556 }
557  
558 sub makeAnyElement
559 0 ▶{ my ($self, $path, $handler, $yes, $no, $process, $min, $max) = @_;
Subroutine makeAnyElement: not called CC=18 SCAR=58.3
Pod undocumented
560 0 ▶ $yes ||= []; $no ||= [];
Condition0%0/4
$yes ||= []
l!l
00
$no ||= []
l!l
00
MC/DC0%0/1
$yes ||= []
$yes
MC/DC0%0/1
$no ||= []
$no
Truth table0%0/2
A
A= $yes
Aresult
11
00
Truth table0%0/2
A
A= $no
Aresult
11
00
561 0 ▶ $yes = [ map {$self->prefixed("{$_}") || $_} @$yes];
Branch: 1 branch
BranchTrueFalseTotal
$self->prefixed("{$_}") or $_ 0 0 0
562 0 ▶ $no = [ map {$self->prefixed("{$_}") || $_} @$no];
Branch: 1 branch
BranchTrueFalseTotal
$self->prefixed("{$_}") or $_ 0 0 0
563 0 ▶ my $where = @$yes ? "in @$yes" : @$no ? "not in @$no" : 'in any namespace';
Branch: 2 branches
BranchTrueFalseTotal
@$yes ? : 0 0 0
@$no ? : 0 0 0
564  
565 0 my $data = +{ kind => 'element', struct => "any element $where"
566 , tag => "ANY", example => 'Anything' };
567 0 ▶ my $occur
Branch: 3 branches
BranchTrueFalseTotal
$max eq 'unbounded' && $min == 0 ? : 0 0 0
$max ne 'unbounded' && $max == 1 && $min == 0 ? : 0 0 0
$max ne 'unbounded' && $max == 1 && $min == 1 ? : 0 0 0
Condition0%0/15
$max eq "unbounded" and $min == 0
!ll&&!rl&&r
000
$max ne "unbounded" and $max == 1 and $min == 0
!ll&&!rl&&r
000
$max ne "unbounded" and $max == 1
!ll&&!rl&&r
000
$max ne "unbounded" and $max == 1 and $min == 1
!ll&&!rl&&r
000
$max ne "unbounded" and $max == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$max eq "unbounded" and $min == 0
$max eq "unbounded" $min == 0
MC/DC0%0/3
$max ne "unbounded" and $max == 1 and $min == 0
$max ne "unbounded" $max == 1 $min == 0
MC/DC0%0/3
$max ne "unbounded" and $max == 1 and $min == 1
$max ne "unbounded" $max == 1 $min == 1
Truth table0%0/3
A and B
A= $max eq "unbounded"B= $min == 0
ABresult
0X0
100
111
Truth table0%0/4
A and B and C
A= $max ne "unbounded"B= $max == 1C= $min == 0
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= $max ne "unbounded"B= $max == 1C= $min == 1
ABCresult
0XX0
10X0
1100
1111
568 = $max eq 'unbounded' && $min==0 ? 'occurs any number of times'
569 : $max ne 'unbounded' && $max==1 && $min==0 ? 'is optional'
570 : $max ne 'unbounded' && $max==1 && $min==1 ? '' # the usual case
571 : "occurs $min <= # <= $max times";
572 0 ▶ $data->{occur} ||= $occur if $occur;
Branch: 1 branch
BranchTrueFalseTotal
if $occur 0 0 0
Condition0%0/3
$data->{"occur"} ||= $occur
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->{"occur"} ||= $occur
$data->{"occur"} $occur
Truth table0%0/3
A ||= B
A= $data->{"occur"}B= $occur
ABresult
1X1
011
000
573 0 ▶ $data->{is_array} = $max eq 'unbounded' || $max > 1;
Condition0%0/3
$max eq 'unbounded' || $max > 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$max eq 'unbounded' || $max > 1
$max eq 'unbounded' $max > 1
Truth table0%0/3
A || B
A= $max eq 'unbounded'B= $max > 1
ABresult
1X1
011
000
574  
575 0 ▶ bless sub { +$data }, 'ANY';
Subroutine __ANON__: not called CC=1 SCAR=6.9
576 }
577  
578 sub makeHook($$$$$$$)
579 3 ▶{ my ($self, $path, $r, $tag, $before, $replace, $after, $fulltype) = @_;
Subroutine makeHook: called CC=11 SCAR=31.7
Pod undocumented
580  
581 3 ▶ return $r unless $before || $replace || $after;
Branch: 1 branch
BranchTrueFalseTotal
unless $before or $replace or $after 0 3 3
Condition33%2/6
$before or $replace or $after
l!l&&r!l&&!r
300
$before or $replace
l!l&&r!l&&!r
030
MC/DC0%0/3
$before or $replace or $after
$before $replace $after
Truth table25%1/4
A or B or C
A= $beforeB= $replaceC= $after
ABCresult
1XX1
01X1
0011
0000
582  
583 3 ▶ error __x"template only supports one production (replace) hook"
Branch: 1 branch
BranchTrueFalseTotal
if $replace and @$replace > 1 0 3 3
Condition33%1/3
$replace and @$replace > 1
!ll&&!rl&&r
030
MC/DC0%0/2
$replace and @$replace > 1
$replace @$replace > 1
Truth table33%1/3
A and B
A= $replaceB= @$replace > 1
ABresult
0X0
100
111
584 if $replace && @$replace > 1;
585  
586 3 ▶ return sub {()} if $replace && grep {$_ eq 'SKIP'} @$replace;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
if $replace and grep {$_ eq "SKIP";} @$replace 0 3 3
Condition33%1/3
$replace and grep {$_ eq "SKIP";} @$replace
!ll&&!rl&&r
030
MC/DC0%0/2
$replace and grep {$_ eq "SKIP";} @$replace
$replace grep {$_ eq "SKIP";} @$replace
Truth table33%1/3
A and B
A= $replaceB= grep {$_ eq "SKIP";} @$replace
ABresult
0X0
100
111
587  
588 3 ▶ my @replace = $replace ? map {$self->_decodeReplace($path,$_)} @$replace:();
Branch: 1 branch
BranchTrueFalseTotal
$replace ? : 3 0 3
589 3 ▶ my @before = $before ? map {$self->_decodeBefore($path,$_) } @$before :();
Branch: 1 branch
BranchTrueFalseTotal
$before ? : 0 3 3
590 3 ▶ my @after = $after ? map {$self->_decodeAfter($path,$_) } @$after :();
Branch: 1 branch
BranchTrueFalseTotal
$after ? : 0 3 3
591  
592 sub
593 3 ▶ { my $doc = XML::LibXML::Document->new;
Subroutine __ANON__: called CC=7 SCAR=25.7
594 3 ▶ for(@before) { $_->($doc, $path, undef) or return }
Branch: 1 branch
BranchTrueFalseTotal
&$_($doc, $path, undef) or return 0 0 0
595  
596 3 ▶ my $xml = @replace ? $replace[0]->($doc, $path, $r) : $r->();
Branch: 1 branch
BranchTrueFalseTotal
@replace ? : 3 0 3
597 3 ▶ defined $xml or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $xml or return () 0 3 3
598  
599 3 ▶ for(@after) { $xml = $_->($doc, $path, $xml) or return }
Branch: 1 branch
BranchTrueFalseTotal
$xml = &$_($doc, $path, $xml) or return 0 0 0
600 3 $xml;
601 }
602 3 }
603  
604 sub _decodeBefore($$)
605 0 ▶{ my ($self, $path, $call) = @_;
Subroutine _decodeBefore: not called CC=2 SCAR=17.9
606 0 ▶ return $call if ref $call eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $call eq "CODE" 0 0 0
607 0 error __x"labeled before hook `{name}' undefined", name => $call;
608 }
609  
610 sub _decodeReplace($$)
611 3 ▶{ my ($self, $path, $call) = @_;
Subroutine _decodeReplace: called CC=3 SCAR=20.0
612 3 ▶ return $call if ref $call eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $call eq "CODE" 3 0 3
613  
614 0 ▶ if($call eq 'COLLAPSE')
Branch: 1 branch
BranchTrueFalseTotal
if ($call eq "COLLAPSE") 0 0 0
615 { return sub
616 0 ▶ { my ($tag, $path, $do) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
617 0 my $h = $do->();
618 0 $h->{elems} = [ { struct => [ 'content collapsed' ]
619 , kind => 'collapsed' } ];
620 0 delete $h->{attrs};
621 0 $h;
622 0 };
623 }
624  
625 # SKIP already handled
626 0 error __x"labeled replace hook `{name}' undefined", name => $call;
627 }
628  
629 sub _decodeAfter($$)
630 0 ▶{ my ($self, $path, $call) = @_;
Subroutine _decodeAfter: not called CC=2 SCAR=17.9
631 0 ▶ return $call if ref $call eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $call eq "CODE" 0 0 0
632 0 error __x"labeled after hook `{name}' undefined", name => $call;
633 }
634  
635  
636 ###
637 ### toPerl
638 ###
639  
640 sub toPerl($%)
641 16 ▶{ my ($self, $ast, %args) = @_;
Subroutine toPerl: called CC=13 SCAR=26.2
Pod undocumented
642 16 ▶ $ast or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$ast or return undef 0 16 16
643  
644 16 my @lines;
645 16 ▶ if($ast->{kind})
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->{"kind"}) 13 3 16
646 13 ▶ { my $name = $ast->{_NAME} || $ast->{tag};
Condition33%1/3
$ast->{'_NAME'} || $ast->{'tag'}
l!l&&r!l&&!r
1300
MC/DC0%0/2
$ast->{'_NAME'} || $ast->{'tag'}
$ast->{'_NAME'} $ast->{'tag'}
Truth table33%1/3
A || B
A= $ast->{'_NAME'}B= $ast->{'tag'}
ABresult
1X1
011
000
647 13 my $pref = $self->prefixed($name);
648 13 ▶ push @lines, defined $pref
Branch: 1 branch
BranchTrueFalseTotal
defined $pref ? : 13 0 13
649 ? ("# Describing $ast->{kind} $pref", "# $name")
650 : "# Describing $ast->{kind} $name";
651 }
652  
653 push @lines
654 , "#"
655 , "# Produced by ".__PACKAGE__." version $VERSION"
656 , "# on ".localtime()
657 , "#"
658 , "# BE WARNED: in most cases, the example below cannot be used without"
659 , "# interpretation. The comments will guide you."
660 , "#"
661 16 ▶ unless $args{skip_header};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"skip_header"} 0 16 16
662  
663 # add info about name-spaces
664 16 foreach my $nsdecl (grep /^xmlns\:/, sort keys %$ast)
665 1 ▶ { push @lines, sprintf "# %-15s %s", $nsdecl, $ast->{$nsdecl} || '(none)';
Condition50%1/2
$ast->{$nsdecl} || '(none)'
l!l
10
MC/DC0%0/1
$ast->{$nsdecl} || '(none)'
$ast->{$nsdecl}
Truth table50%1/2
A
A= $ast->{$nsdecl}
Aresult
11
00
666 }
667 16 ▶ push @lines, '' if @lines;
Branch: 1 branch
BranchTrueFalseTotal
if @lines 13 3 16
668
669 # produce data tree
670 16 push @lines, $self->_perlAny($ast, \%args);
671  
672 # remove leading 'type =>'
673 16 ▶ for(my $linenr = 0; $linenr < @lines; $linenr++)
Branch: 1 branch
BranchTrueFalseTotal
if ($linenr < @lines) 73 0 73
674 73 ▶ { next if $lines[$linenr] =~ m/^\s*\#/;
Branch: 1 branch
BranchTrueFalseTotal
if $lines[$linenr] =~ /^\s*\#/ 44 29 73
675 29 ▶ next unless $lines[$linenr] =~ s/.*? \=\>\s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines[$linenr] =~ s/.*? \=\>\s*// 13 16 29
676 16 ▶ $lines[$linenr] =~ m/\S/ or splice @lines, $linenr, 1;
Branch: 1 branch
BranchTrueFalseTotal
$lines[$linenr] =~ /\S/ or splice @lines, $linenr, 1 13 3 16
677 16 last;
678 }
679  
680 16 my $lines = join "\n", @lines;
681 16 $lines =~ s/\,?\s*$/\n/;
682 16 $lines;
683 }
684  
685 11 my %seen;
686 sub _perlAny($$);
687 sub _perlAny($$)
688 105 ▶{ my ($self, $ast, $args) = @_;
Subroutine _perlAny: called CC=61 SCAR=43.6
689  
690 105 my @lines;
691 105 ▶ if($ast->{_TYPE} && $args->{show_type})
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->{"_TYPE"} and $args->{"show_type"}) 54 51 105
Condition100%3/3
$ast->{"_TYPE"} and $args->{"show_type"}
!ll&&!rl&&r
321954
MC/DC100%2/2
$ast->{"_TYPE"} and $args->{"show_type"}
$ast->{"_TYPE"} $args->{"show_type"}
Truth table100%3/3
A and B
A= $ast->{"_TYPE"}B= $args->{"show_type"}
ABresult
0X0
100
111
692 54 { my $pref = $self->prefixed($ast->{_TYPE});
693 54 ▶ if($pref)
Branch: 1 branch
BranchTrueFalseTotal
if ($pref) 54 0 54
694 54 ▶ { push @lines # not perfect, but a good attempt
Branch: 1 branch
BranchTrueFalseTotal
$pref =~ /^[aiou]/i && !($pref =~ /^(uni|eu)/i) ? : 12 42 54
Condition66%2/3
$pref =~ /^[aiou]/i and not $pref =~ /^(uni|eu)/i
!ll&&!rl&&r
42012
MC/DC50%1/2
$pref =~ /^[aiou]/i and not $pref =~ /^(uni|eu)/i
$pref =~ /^[aiou]/i not $pref =~ /^(uni|eu)/i
Truth table66%2/3
A and not(B)
A= $pref =~ /^[aiou]/iB= not $pref =~ /^(uni|eu)/i
ABresult
0X0
100
111
695 , $pref =~ m/^[aiou]/i && $pref !~ m/^(uni|eu)/i
696 ? "# is an $pref" : "# is a $pref";
697 }
698 }
699  
700 105 ▶ if($ast->{struct} && $args->{show_struct})
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->{"struct"} and $args->{"show_struct"}) 56 49 105
Condition100%3/3
$ast->{"struct"} and $args->{"show_struct"}
!ll&&!rl&&r
321756
MC/DC100%2/2
$ast->{"struct"} and $args->{"show_struct"}
$ast->{"struct"} $args->{"show_struct"}
Truth table100%3/3
A and B
A= $ast->{"struct"}B= $args->{"show_struct"}
ABresult
0X0
100
111
701 56 { my $struct = $ast->{struct};
702 56 ▶ my @struct = ref $struct ? @$struct : $struct;
Branch: 1 branch
BranchTrueFalseTotal
ref $struct ? : 51 5 56
703 56 s/^/# /gm for @struct;
704 56 push @lines, @struct;
705 }
706  
707 push @lines, "# $ast->{occur}"
708 105 ▶ if $ast->{occur} && $args->{show_occur};
Branch: 1 branch
BranchTrueFalseTotal
if $ast->{"occur"} and $args->{"show_occur"} 20 85 105
Condition100%3/3
$ast->{"occur"} and $args->{"show_occur"}
!ll&&!rl&&r
76920
MC/DC100%2/2
$ast->{"occur"} and $args->{"show_occur"}
$ast->{"occur"} $args->{"show_occur"}
Truth table100%3/3
A and B
A= $ast->{"occur"}B= $args->{"show_occur"}
ABresult
0X0
100
111
709  
710 105 ▶ if($ast->{facets} && $args->{show_facets})
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->{"facets"} and $args->{"show_facets"}) 3 102 105
Condition100%3/3
$ast->{"facets"} and $args->{"show_facets"}
!ll&&!rl&&r
10023
MC/DC100%2/2
$ast->{"facets"} and $args->{"show_facets"}
$ast->{"facets"} $args->{"show_facets"}
Truth table100%3/3
A and B
A= $ast->{"facets"}B= $args->{"show_facets"}
ABresult
0X0
100
111
711 3 { my $facets = $ast->{facets};
712 3 ▶ my @facets = ref $facets ? @$facets : $facets;
Branch: 1 branch
BranchTrueFalseTotal
ref $facets ? : 3 0 3
713 3 s/^/# /gm for @facets;
714 3 push @lines, @facets;
715 }
716  
717 105 my @childs;
718 105 ▶ push @childs, @{$ast->{attrs}} if $ast->{attrs};
Branch: 1 branch
BranchTrueFalseTotal
if $ast->{"attrs"} 21 84 105
719 105 ▶ push @childs, @{$ast->{elems}} if $ast->{elems};
Branch: 1 branch
BranchTrueFalseTotal
if $ast->{"elems"} 46 59 105
720 105 ▶ push @childs, $ast->{body} if $ast->{body};
Branch: 1 branch
BranchTrueFalseTotal
if $ast->{"body"} 0 105 105
721  
722 105 my @subs;
723 105 foreach my $child (@childs)
724 89 { my @sub = $self->_perlAny($child, $args);
725 89 ▶ @sub or next;
Branch: 1 branch
BranchTrueFalseTotal
@sub or next 0 89 89
726  
727 # last line is code and gets comma
728 89 ▶ $sub[-1] =~ s/\,?\s*$/,/
Branch: 1 branch
BranchTrueFalseTotal
unless $sub[-1] =~ /\#\s/ 89 0 89
729 if $sub[-1] !~ m/\#\s/;
730  
731 89 ▶ if(ref $ast ne 'BLOCK')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ast ne "BLOCK") 46 43 89
732 46 { s/^(.)/$args->{indent}$1/ for @sub;
733 }
734  
735 # seperator blank, sometimes
736 89 ▶ unshift @sub, ''
Branch: 1 branch
BranchTrueFalseTotal
if $sub[0] =~ /^\s*[#{]/ or @subs and $subs[-1] =~ /[}\]]\,\s*$/ 68 21 89
Condition100%6/6
$sub[0] =~ /^\s*[#{]/ or @subs and $subs[-1] =~ /[}\]]\,\s*$/
l!l&&r!l&&!r
65519
@subs and $subs[-1] =~ /[}\]]\,\s*$/
!ll&&!rl&&r
10113
MC/DC100%3/3
$sub[0] =~ /^\s*[#{]/ or @subs and $subs[-1] =~ /[}\]]\,\s*$/
$sub[0] =~ /^\s*[#{]/ @subs $subs[-1] =~ /[}\]]\,\s*$/
Truth table100%4/4
A or B and C
A= $sub[0] =~ /^\s*[#{]/B= @subsC= $subs[-1] =~ /[}\]]\,\s*$/
ABCresult
1XX1
0111
00X0
0100
737 if $sub[0] =~ m/^\s*[#{]/ # }
738 || (@subs && $subs[-1] =~ m/[}\]]\,\s*$/);
739  
740 89 push @subs, @sub;
741 }
742  
743 105 ▶ if(ref $ast eq 'REP-BLOCK')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ast eq "REP-BLOCK") 3 102 105
744 { # repeated block
745 3 ▶ @subs or @subs = '';
Branch: 1 branch
BranchTrueFalseTotal
@subs or @subs = "" 0 3 3
746 3 ▶ $subs[0] =~ s/^ /{ / or $subs[0] =~ s/^\s*$/{/;
Branch: 1 branch
BranchTrueFalseTotal
$subs[0] =~ s/^ /{ / or $subs[0] =~ s/^\s*$/{/ 2 1 3
747 3 ▶ if($subs[-1] =~ m/\#\s/) { push @subs, "}," }
Branch: 1 branch
BranchTrueFalseTotal
if ($subs[-1] =~ /\#\s/) { } 0 3 3
748 3 else { $subs[-1] =~ s/$/ },/ }
749 }
750  
751 # XML does not permit difficult tags, but we still check.
752 105 ▶ my $tag = $ast->{tag} || '';
Condition100%2/2
$ast->{'tag'} || ''
l!l
1023
MC/DC100%1/1
$ast->{'tag'} || ''
$ast->{'tag'}
Truth table100%2/2
A
A= $ast->{'tag'}
Aresult
11
00
753 105 ▶ if(defined $tag && $tag !~ m/^[\w_][\w\d_]*$/)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag and not $tag =~ /^[\w_][\w\d_]*$/) 3 102 105
Condition66%2/3
defined $tag and not $tag =~ /^[\w_][\w\d_]*$/
!ll&&!rl&&r
01023
MC/DC50%1/2
defined $tag and not $tag =~ /^[\w_][\w\d_]*$/
defined $tag not $tag =~ /^[\w_][\w\d_]*$/
Truth table66%2/3
A and not(B)
A= defined $tagB= not $tag =~ /^[\w_][\w\d_]*$/
ABresult
0X0
100
111
754 3 { $tag =~ s/\\/\\\\/g;
755 3 $tag =~ s/'/\\'/g;
756 3 $tag = qq{'$tag'};
757 }
758  
759 105 ▶ my $kind = $ast->{kind} || '';
Condition100%2/2
$ast->{'kind'} || ''
l!l
7530
MC/DC100%1/1
$ast->{'kind'} || ''
$ast->{'kind'}
Truth table100%2/2
A
A= $ast->{'kind'}
Aresult
11
00
760 105 ▶ if(ref $ast eq 'REP-BLOCK')
Branch: 7 branches
BranchTrueFalseTotal
if (ref $ast eq 'REP-BLOCK') { } 3 102 105
elsif (ref $ast eq 'BLOCK') { } 22 80 102
elsif (@subs) { } 21 59 80
elsif ($kind eq 'complex' or $kind eq 'mixed') { } 0 59 59
elsif ($kind eq 'collapsed') { } 0 59 59
elsif ($kind eq 'union') { } 0 59 59
elsif (not exists $ast->{'example'}) { } 0 59 59
761 3 { s/^(.)/ $1/ for @subs;
762 3 $subs[0] =~ s/^ ?/[/;
763 3 push @lines, "$tag => ", @subs , ']';
764 }
765 elsif(ref $ast eq 'BLOCK')
766 22 { push @lines, @subs;
767 }
768 elsif(@subs)
769 21 ▶ { length $subs[0] or shift @subs;
Branch: 1 branch
BranchTrueFalseTotal
length $subs[0] or shift @subs 17 4 21
770 21 ▶ if($ast->{is_array})
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->{'is_array'}) { } 3 18 21
771 3 { s/^(.)/ $1/ for @subs;
772 3 $subs[0] =~ s/^[ ]{0,3}/[ {/;
773 3 ▶ if($subs[-1] =~ m/\#\s/) { push @subs, "}, ], " }
Branch: 1 branch
BranchTrueFalseTotal
if ($subs[-1] =~ /\#\s/) { } 0 3 3
774 3 else {$subs[-1] .= ' }, ], ' }
775 3 push @lines, "$tag =>", @subs;
776 }
777 else
778 18 { $subs[0] =~ s/^ /{ /;
779 18 ▶ if($subs[-1] =~ m/\#\s/) { push @subs, "}, " }
Branch: 1 branch
BranchTrueFalseTotal
if ($subs[-1] =~ /\#\s/) { } 0 18 18
780 18 else {$subs[-1] .= ' },' }
781 18 push @lines, "$tag =>", @subs;
782 }
783 }
784 ▶ elsif($kind eq 'complex' || $kind eq 'mixed') # empty complex-type
Condition33%1/3
$kind eq "complex" or $kind eq "mixed"
l!l&&r!l&&!r
0059
MC/DC0%0/2
$kind eq "complex" or $kind eq "mixed"
$kind eq "complex" $kind eq "mixed"
Truth table33%1/3
A or B
A= $kind eq "complex"B= $kind eq "mixed"
ABresult
1X1
011
000
785 { # if there is an "occurs", then there can always be more than one
786 0 ▶ push @lines, $tag.' => '.($ast->{occur} ? '[{},]' : '{}');
Branch: 1 branch
BranchTrueFalseTotal
$ast->{'occur'} ? : 0 0 0
787 }
788 elsif($kind eq 'collapsed') {;}
789 elsif($kind eq 'union') # union type
790 0 { foreach my $union ( @{$ast->{choice}} )
791 { # remove examples
792 0 my @l = grep { m/^#/ } $self->_perlAny($union, $args);
793 0 s/^\#/# -/ for $l[0];
794 0 s/^\#/# / for @l[1..$#l];
795 0 push @lines, @l;
796 }
797 }
798 elsif(!exists $ast->{example})
799 0 { push @lines, "$tag => 'TEMPLATE-ERROR $ast->{kind}'";
800 }
801  
802 105 my $example = $ast->{example};
803 105 ▶ if(defined $example)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $example) 59 46 105
804 59 ▶ { $example = qq{"$example"} # in quotes unless
Branch: 1 branch
BranchTrueFalseTotal
unless $example =~ /^[+-]?\d+(?:\.\d+)?$/ or $example =~ /^\$/ or $example =~ /^bless\b/ or $example =~ /^\$?[\w:]*\-\>/ or $example =~ /^\{.*\}$/ or $example =~ /^\[.*\]$/ 12 47 59
Condition93%14/15
$example =~ /^[+-]?\d+(?:\.\d+)?$/ or $example =~ /^\$/ or $example =~ /^bless\b/ or $example =~ /^\$?[\w:]*\-\>/ or $example =~ /^\{.*\}$/ or $example =~ /^\[.*\]$/
l!l&&r!l&&!r
47012
$example =~ /^[+-]?\d+(?:\.\d+)?$/ or $example =~ /^\$/ or $example =~ /^bless\b/ or $example =~ /^\$?[\w:]*\-\>/ or $example =~ /^\{.*\}$/
l!l&&r!l&&!r
44312
$example =~ /^[+-]?\d+(?:\.\d+)?$/ or $example =~ /^\$/ or $example =~ /^bless\b/ or $example =~ /^\$?[\w:]*\-\>/
l!l&&r!l&&!r
43115
$example =~ /^[+-]?\d+(?:\.\d+)?$/ or $example =~ /^\$/ or $example =~ /^bless\b/
l!l&&r!l&&!r
42116
$example =~ /^[+-]?\d+(?:\.\d+)?$/ or $example =~ /^\$/
l!l&&r!l&&!r
40217
MC/DC83%5/6
$example =~ /^[+-]?\d+(?:\.\d+)?$/ or $example =~ /^\$/ or $example =~ /^bless\b/ or $example =~ /^\$?[\w:]*\-\>/ or $example =~ /^\{.*\}$/ or $example =~ /^\[.*\]$/
$example =~ /^[+-]?\d+(?:\.\d+)?$/ $example =~ /^\$/ $example =~ /^bless\b/ $example =~ /^\$?[\w:]*\-\>/ $example =~ /^\{.*\}$/ $example =~ /^\[.*\]$/
Truth table85%6/7
A or B or C or D or E or F
A= $example =~ /^[+-]?\d+(?:\.\d+)?$/B= $example =~ /^\$/C= $example =~ /^bless\b/D= $example =~ /^\$?[\w:]*\-\>/E= $example =~ /^\{.*\}$/F= $example =~ /^\[.*\]$/
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
805 if $example !~ m/^[+-]?\d+(?:\.\d+)?$/ # numeric or
806 && $example !~ m/^\$/ # variable or
807 && $example !~ m/^bless\b/ # constructor or
808 && $example !~ m/^\$?[\w:]*\-\>/ # method call example
809 && $example !~ m/^\{.*\}$/ # anon HASH example
810 && $example !~ m/^\[.*\]$/; # anon ARRAY example
811  
812 push @lines, "$tag => "
813 59 ▶ . ($ast->{is_array} ? "[ $example, ]" : $example);
Branch: 1 branch
BranchTrueFalseTotal
$ast->{'is_array'} ? : 6 53 59
814 }
815 105 @lines;
816 }
817  
818 ###
819 ### toXML
820 ###
821  
822 sub toXML($$%)
823 2 ▶{ my ($self, $doc, $ast, %args) = @_;
Subroutine toXML: called CC=7 SCAR=20.1
Pod undocumented
824 2 my $xml = $self->_xmlAny($doc, $ast, "\n$args{indent}", \%args);
825  
826 2 ▶ UNIVERSAL::isa($xml, 'XML::LibXML::Element')
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($xml, "XML::LibXML::Element") or return $xml 0 2 2
827 or return $xml;
828  
829 # add comment
830 2 my $pkg = __PACKAGE__;
831 2 my $now = localtime();
832  
833 2 my $header = $doc->createComment( <<_HEADER . ' ' );
834  
835 BE WARNED: in most cases, the example below cannot be used without
836 interpretation. The comments will guide you.
837 Produced by $pkg version $VERSION
838 on $now
839 _HEADER
840  
841 2 ▶ unless($args{skip_header})
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"skip_header"}) 0 2 2
842 0 { $xml->insertBefore($header, $xml->firstChild);
843 0 $xml->insertBefore($doc->createTextNode("\n "), $header);
844 }
845  
846 # I use xsi:type myself, too late for the usual "used" counter
847 $ast->{'xmlns:xsi'} ||= SCHEMA2001i
848 2 ▶ if $args{show_type};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"show_type"} 1 1 2
Condition50%1/2
$ast->{"xmlns:xsi"} ||= "http://www.w3.org/2001/XMLSchema-instance"
l!l
01
MC/DC0%0/1
$ast->{"xmlns:xsi"} ||= "http://www.w3.org/2001/XMLSchema-instance"
$ast->{"xmlns:xsi"}
Truth table50%1/2
A
A= $ast->{"xmlns:xsi"}
Aresult
11
00
849  
850 # add info about name-spaces
851 2 foreach (sort keys %$ast)
852 20 ▶ { if( m/^xmlns\:(.*)/ )
Branch: 1 branch
BranchTrueFalseTotal
if (/^xmlns\:(.*)/) 6 14 20
853 6 { $xml->setNamespace($ast->{$_}, $1, 0);
854 }
855 }
856  
857 2 $xml;
858 }
859  
860 sub _xmlAny($$$$);
861 sub _xmlAny($$$$)
862 42 ▶{ my ($self, $doc, $ast, $indent, $args) = @_;
Subroutine _xmlAny: called CC=29 SCAR=33.9
863 42 my @res;
864 my $xsi = $self->_registerNSprefix('xsi', SCHEMA2001i, 1)
865 42 ▶ if $args->{show_type};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"show_type"} 21 21 42
866  
867 42 my @comment;
868 42 ▶ if($ast->{struct} && $args->{show_struct})
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->{"struct"} and $args->{"show_struct"}) 17 25 42
Condition100%3/3
$ast->{"struct"} and $args->{"show_struct"}
!ll&&!rl&&r
81717
MC/DC100%2/2
$ast->{"struct"} and $args->{"show_struct"}
$ast->{"struct"} $args->{"show_struct"}
Truth table100%3/3
A and B
A= $ast->{"struct"}B= $args->{"show_struct"}
ABresult
0X0
100
111
869 17 { my $struct = $ast->{struct};
870 17 ▶ push @comment, ref $struct ? @$struct : $struct;
Branch: 1 branch
BranchTrueFalseTotal
ref $struct ? : 17 0 17
871 }
872  
873 push @comment, $ast->{occur}
874 42 ▶ if $ast->{occur} && $args->{show_occur};
Branch: 1 branch
BranchTrueFalseTotal
if $ast->{"occur"} and $args->{"show_occur"} 5 37 42
Condition100%3/3
$ast->{"occur"} and $args->{"show_occur"}
!ll&&!rl&&r
3255
MC/DC100%2/2
$ast->{"occur"} and $args->{"show_occur"}
$ast->{"occur"} $args->{"show_occur"}
Truth table100%3/3
A and B
A= $ast->{"occur"}B= $args->{"show_occur"}
ABresult
0X0
100
111
875  
876 42 ▶ if($ast->{facets} && $args->{show_facets})
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->{"facets"} and $args->{"show_facets"}) 2 40 42
Condition100%3/3
$ast->{"facets"} and $args->{"show_facets"}
!ll&&!rl&&r
3822
MC/DC100%2/2
$ast->{"facets"} and $args->{"show_facets"}
$ast->{"facets"} $args->{"show_facets"}
Truth table100%3/3
A and B
A= $ast->{"facets"}B= $args->{"show_facets"}
ABresult
0X0
100
111
877 2 { my $facets = $ast->{facets};
878 2 ▶ push @comment, ref $facets eq 'ARRAY' ? @$facets : $facets;
Branch: 1 branch
BranchTrueFalseTotal
ref $facets eq 'ARRAY' ? : 2 0 2
879 }
880  
881 42 ▶ if(defined $ast->{kind} && $ast->{kind} eq 'union')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ast->{"kind"} and $ast->{"kind"} eq "union") 0 42 42
Condition66%2/3
defined $ast->{"kind"} and $ast->{"kind"} eq "union"
!ll&&!rl&&r
12300
MC/DC0%0/2
defined $ast->{"kind"} and $ast->{"kind"} eq "union"
defined $ast->{"kind"} $ast->{"kind"} eq "union"
Truth table66%2/3
A and B
A= defined $ast->{"kind"}B= $ast->{"kind"} eq "union"
ABresult
0X0
100
111
882 0 { push @comment, map " $_->{type}", @{$ast->{choice}};
883 }
884  
885 42 ▶ my @attrs = @{$ast->{attrs} || []};
Branch: 1 branch
BranchTrueFalseTotal
$ast->{"attrs"} or [] 34 8 42
886 42 foreach my $attr (@attrs)
887 8 { push @res, $doc->createAttribute($attr->{tag}, $attr->{example});
888 8 my ($ns, $local) = unpack_type $attr->{_TYPE};
889 8 my $prefix = $self->_registerNSprefix('', $ns, 1);
890 push @comment, "attr $attr->{tag} has type $prefix:$local"
891 8 ▶ if $args->{show_type};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"show_type"} 4 4 8
892 }
893  
894 42 my $nest_indent = $indent.$args->{indent};
895 42 ▶ if(@comment)
Branch: 1 branch
BranchTrueFalseTotal
if (@comment) 13 29 42
896 13 { my $comment = ' '.join("$nest_indent ", @comment) .' ';
897 13 push @res
898 , $doc->createTextNode($indent)
899 , $doc->createComment($comment);
900 }
901  
902 42 ▶ my @elems = @{$ast->{elems} || []};
Branch: 1 branch
BranchTrueFalseTotal
$ast->{"elems"} or [] 22 20 42
903 42 foreach my $elem (@elems)
904 40 ▶ { if(ref $elem eq 'BLOCK' || ref $elem eq 'REP-BLOCK')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $elem eq 'BLOCK' or ref $elem eq 'REP-BLOCK') { } 12 28 40
elsif ($elem->{'tag'} eq '_') { } 0 28 28
Condition100%3/3
ref $elem eq "BLOCK" or ref $elem eq "REP-BLOCK"
l!l&&r!l&&!r
10228
MC/DC100%2/2
ref $elem eq "BLOCK" or ref $elem eq "REP-BLOCK"
ref $elem eq "BLOCK" ref $elem eq "REP-BLOCK"
Truth table100%3/3
A or B
A= ref $elem eq "BLOCK"B= ref $elem eq "REP-BLOCK"
ABresult
1X1
011
000
905 12 { push @res, $self->_xmlAny($doc, $elem, $indent, $args);
906 }
907 elsif($elem->{tag} eq '_')
908 0 { push @res, $doc->createTextNode($indent.$elem->{example});
909 }
910 else
911 28 { my $node = $self->_xmlAny($doc, $elem, $nest_indent, $args);
912 28 ▶ push @res, $doc->createTextNode($indent)
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("XML::LibXML::Element") 28 0 28
913 if $node->isa('XML::LibXML::Element');
914 28 push @res, $node;
915 }
916 }
917  
918 42 (my $outdent = $indent) =~ s/$args->{indent}$//; # sorry
919  
920 42 ▶ if(my $example = $ast->{example})
Branch: 1 branch
BranchTrueFalseTotal
if (my $example = $ast->{"example"}) 22 20 42
921 22 ▶ { push @res, $doc->createTextNode
Branch: 1 branch
BranchTrueFalseTotal
@comment ? : 5 17 22
922 (@comment ? "$indent$example$outdent" : $example)
923 }
924  
925 42 ▶ if($ast->{_TYPE} && $args->{show_type})
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->{"_TYPE"} and $args->{"show_type"}) 15 27 42
Condition100%3/3
$ast->{"_TYPE"} and $args->{"show_type"}
!ll&&!rl&&r
121515
MC/DC100%2/2
$ast->{"_TYPE"} and $args->{"show_type"}
$ast->{"_TYPE"} $args->{"show_type"}
Truth table100%3/3
A and B
A= $ast->{"_TYPE"}B= $args->{"show_type"}
ABresult
0X0
100
111
926 15 { my $pref = $self->prefixed($ast->{_TYPE});
927 15 push @res, $doc->createAttribute("$xsi:type" => $pref);
928 }
929  
930 return @res
931 42 ▶ if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 12 30 42
932  
933 30 my $node = $doc->createElement($ast->{tag});
934 30 $node->addChild($_) for @res;
935 30 ▶ $node->appendText($outdent) if @elems;
Branch: 1 branch
BranchTrueFalseTotal
if @elems 8 22 30
936 30 $node;
937 }
938  
939 sub makeBlocked($$$)
940 0 ▶{ my ($self, $where, $class, $type) = @_;
Subroutine makeBlocked: not called CC=1 SCAR=6.9
Pod undocumented
941 0 panic "namespace blocking not yet supported for Templates";
942 }
943  
944  
945 11 1;
« blib/lib/XML/Compile/Schema/Instance.pm ↑ Summary blib/lib/XML/Compile.pm »