Compile/Translate/Template.pm

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