blib/lib/XML/Generator/PerlData.pm

filter: Statementstmt 67.1% 361 / 538 Branchbran 54.6% 142 / 260 Conditioncond 63.9% 39 / 61 MC/DCmcdc 41.6% 15 / 36 Subroutinesub 75.6% 31 / 41 Podpod 81.2% 26 / 32 totaltotal 63.4% 614 / 968 SCAR 74.5
CC
175
Cov
63%
init
47.7
charmap
42.0
arrayref2SAX
35.6
CRAP 1714.1
↑ Summary
1 package XML::Generator::PerlData;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use XML::SAX::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use vars qw($VERSION @ISA $NS_XMLNS $NS_XML);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # some globals
9 12 $VERSION = '0.93';
10 12 @ISA = qw( XML::SAX::Base );
11 12 $NS_XML = 'http://www.w3.org/XML/1998/namespace';
12 12 $NS_XMLNS = 'http://www.w3.org/2000/xmlns/';
13  
14 sub new {
15 11 ▶ my $proto = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
16 11 my $self = $proto->SUPER::new( @_ );
17  
18 11 my %args = @_;
19  
20 11 ▶ delete $args{Handler} if defined $args{Handler};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"Handler"} 4 7 11
21  
22 11 $self->{Namespaces} = { $NS_XMLNS => 'xmlns',
23 $NS_XML => 'xml'
24 };
25 11 $self->{DeclaredNamespaces} = {$NS_XMLNS => 'xmlns',
26 $NS_XML => 'xml'
27 };
28  
29 11 $self->{InScopeNamespaceStack} = [];
30  
31 # _Parents needed for attribute vs. element fixing;
32 11 $self->{_Parents} = [];
33  
34 11 $self->init( %args );
35 11 return $self;
36 }
37  
38 sub init {
39 17 ▶ my $self = shift;
Subroutine init: called CC=31 SCAR=38.6
Pod documented
40 17 my %args = @_;
41  
42 17 ▶ $self->{Keymap} = $args{keymap} if defined $args{keymap};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"keymap"} 1 16 17
43 17 ▶ $self->{RootName} = $args{rootname} if defined $args{rootname};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"rootname"} 0 17 17
44 17 ▶ $self->{SkipRoot} = $args{skiproot} if defined $args{skiproot};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"skiproot"} 0 17 17
45 17 ▶ $self->{DefaultElementName} = $args{defaultname} if defined $args{defaultname};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"defaultname"} 0 17 17
46 17 ▶ $self->{BindAttrs} = 1 if defined $args{bindattrs};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"bindattrs"} 0 17 17
47 17 ▶ $self->{Keymap} ||= {};
Condition100%2/2
$self->{"Keymap"} ||= {}
l!l
611
MC/DC100%1/1
$self->{"Keymap"} ||= {}
$self->{"Keymap"}
Truth table100%2/2
A
A= $self->{"Keymap"}
Aresult
11
00
48 17 ▶ $self->{RootName} ||= 'document';
Condition100%2/2
$self->{"RootName"} ||= "document"
l!l
611
MC/DC100%1/1
$self->{"RootName"} ||= "document"
$self->{"RootName"}
Truth table100%2/2
A
A= $self->{"RootName"}
Aresult
11
00
49 17 ▶ $self->{DefaultElementName} ||= 'default';
Condition100%2/2
$self->{"DefaultElementName"} ||= "default"
l!l
611
MC/DC100%1/1
$self->{"DefaultElementName"} ||= "default"
$self->{"DefaultElementName"}
Truth table100%2/2
A
A= $self->{"DefaultElementName"}
Aresult
11
00
50 17 ▶ $self->{TokenReplacementChar} ||= '_';
Condition100%2/2
$self->{"TokenReplacementChar"} ||= "_"
l!l
611
MC/DC100%1/1
$self->{"TokenReplacementChar"} ||= "_"
$self->{"TokenReplacementChar"}
Truth table100%2/2
A
A= $self->{"TokenReplacementChar"}
Aresult
11
00
51 17 ▶ $self->{Seen} ||= {};
Condition100%2/2
$self->{"Seen"} ||= {}
l!l
611
MC/DC100%1/1
$self->{"Seen"} ||= {}
$self->{"Seen"}
Truth table100%2/2
A
A= $self->{"Seen"}
Aresult
11
00
52  
53 17 ▶ if ( defined $args{namespaces} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"namespaces"}) 0 17 17
54 0 foreach my $uri ( keys( %{$args{namespaces}} )) {
55 0 $self->{Namespaces}->{"$uri"} = $args{namespaces}->{"$uri"};
56 }
57 }
58  
59 # allow perlified PIs
60 17 ▶ if ( defined( $args{processing_instructions} )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"processing_instructions"}) 1 16 17
61 1 $self->{ProcessingInstructions} = [];
62  
63 1 ▶ if ( ref( $args{processing_instructions} ) eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $args{'processing_instructions'} eq 'ARRAY') { } 1 0 1
elsif (ref $args{'processing_instructions'} eq 'HASH') { } 0 0 0
64 1 $self->{ProcessingInstructions} = $args{processing_instructions};
65 }
66 elsif ( ref( $args{processing_instructions} ) eq 'HASH' ) {
67 0 foreach my $k ( keys( %{$args{processing_instructions}} )) {
68 0 push @{$self->{ProcessingInstructions}}, ( $k => $args{processing_instructions}->{$k} );
69 }
70 }
71 }
72  
73 # let 'em change handlers if they want.
74 17 ▶ if ( defined $args{Handler} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"Handler"}) 0 17 17
75 0 $self->set_handler( $args{Handler} );
76 }
77  
78 17 ▶ if ( defined( $args{attrmap} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"attrmap"}) 1 16 17
79 1 $self->{Attrmap} = {};
80 1 ▶ while ( my ($k, $v) = ( each( %{$args{attrmap}} ) )) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args{"attrmap"};}) 1 1 2
81 1 ▶ push @{$self->{Attrmap}->{$k}}, ref( $v ) ? @{$v} : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v ? : 1 0 1
82 }
83 }
84 17 ▶ $self->{Attrmap} ||= {};
Condition100%2/2
$self->{"Attrmap"} ||= {}
l!l
611
MC/DC100%1/1
$self->{"Attrmap"} ||= {}
$self->{"Attrmap"}
Truth table100%2/2
A
A= $self->{"Attrmap"}
Aresult
11
00
85  
86 17 ▶ if ( defined( $args{namespacemap} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"namespacemap"}) 2 15 17
87 2 $self->{Namespacemap} = {};
88 2 ▶ while ( my ($k, $v) = ( each( %{$args{namespacemap}} ) )) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args{"namespacemap"};}) 4 2 6
89 4 ▶ push @{$self->{Namespacemap}->{$k}}, ref( $v ) ? @{$v} : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v ? : 2 2 4
90 }
91 }
92 17 ▶ $self->{Namespacemap} ||= {};
Condition100%2/2
$self->{"Namespacemap"} ||= {}
l!l
611
MC/DC100%1/1
$self->{"Namespacemap"} ||= {}
$self->{"Namespacemap"}
Truth table100%2/2
A
A= $self->{"Namespacemap"}
Aresult
11
00
93  
94 17 ▶ if ( defined( $args{charmap} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"charmap"}) 0 17 17
95 0 $self->{Charmap} = {};
96 0 ▶ while ( my ($k, $v) = ( each( %{$args{charmap}} ) )) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args{"charmap"};}) 0 0 0
97 0 ▶ push @{$self->{Charmap}->{$k}}, ref( $v ) ? @{$v} : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v ? : 0 0 0
98 }
99 }
100 17 ▶ $self->{Charmap} ||= {};
Condition100%2/2
$self->{"Charmap"} ||= {}
l!l
611
MC/DC100%1/1
$self->{"Charmap"} ||= {}
$self->{"Charmap"}
Truth table100%2/2
A
A= $self->{"Charmap"}
Aresult
11
00
101  
102 # Skipelements:
103 # Makes sense from an interface standpoint for the user
104 # to pass an array ref, but it makes it more efficient to
105 # implement if its a hash ref. Let's pull a little juju.
106  
107 17 my %skippers = ();
108 17 ▶ if ( $args{skipelements} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"skipelements"}) 1 16 17
109 1 %skippers = map { $_, 1} @{$args{skipelements}}
110 }
111  
112 17 $self->{Skipelements} = \%skippers;
113  
114 }
115  
116 sub parse_start {
117 6 ▶ my $self = shift;
Subroutine parse_start: called CC=6 SCAR=18.0
Pod documented
118 6 ▶ $self->init( @_ ) if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 6 6
119  
120 6 $self->start_document( {} );
121  
122 6 ▶ if ( defined( $self->{ProcessingInstructions} ) && scalar( @{$self->{ProcessingInstructions}}) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"ProcessingInstructions"} and scalar @{$self->{"ProcessingInstructions"};} > 0) 1 5 6
Condition66%2/3
defined $self->{"ProcessingInstructions"} and scalar @{$self->{"ProcessingInstructions"};} > 0
!ll&&!rl&&r
501
MC/DC50%1/2
defined $self->{"ProcessingInstructions"} and scalar @{$self->{"ProcessingInstructions"};} > 0
defined $self->{"ProcessingInstructions"} scalar @{$self->{"ProcessingInstructions"};} > 0
Truth table66%2/3
A and B
A= defined $self->{"ProcessingInstructions"}B= scalar @{$self->{"ProcessingInstructions"};} > 0
ABresult
0X0
100
111
123 1 my $pis = delete $self->{ProcessingInstructions};
124  
125 1 ▶ while ( my ( $target, $data ) = ( splice( @$pis, 0, 2)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@$pis, 0, 2)) 2 1 3
126 2 $self->parse_pi( $target, $data );
127 }
128 }
129  
130 6 ▶ unless ( defined $self->{SkipRoot} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"SkipRoot"}) 6 0 6
131 6 $self->start_element( $self->_start_details( $self->{RootName} ) );
132 6 push @{$self->{_Parents}}, $self->{RootName};
133 }
134 }
135  
136 sub parse_end {
137 6 ▶ my $self = shift;
Subroutine parse_end: called CC=6 SCAR=18.0
Pod documented
138 6 ▶ unless ( defined $self->{SkipRoot} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"SkipRoot"}) 6 0 6
139 6 $self->end_element( $self->_end_details( $self->{RootName} ) );
140 }
141  
142 6 foreach my $uri ( keys( %{$self->{DeclaredNamespaces}} )) {
143 16 ▶ next if $uri eq $NS_XMLNS;
Branch: 1 branch
BranchTrueFalseTotal
if $uri eq $XML::Generator::PerlData::NS_XMLNS 6 10 16
144 10 ▶ next if $uri eq $NS_XML;
Branch: 1 branch
BranchTrueFalseTotal
if $uri eq $XML::Generator::PerlData::NS_XML 6 4 10
145 4 ▶ next if not defined $self->{DeclaredNamespaces}->{$uri};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"DeclaredNamespaces"}{$uri} 0 4 4
146  
147 4 $self->end_prefix_mapping({ Prefix => $self->{DeclaredNamespaces}->{$uri},
148 NamespaceURI => $uri
149 });
150 }
151  
152 6 return $self->end_document();
153 }
154  
155 sub parse {
156 6 ▶ my $self = shift;
Subroutine parse: called CC=3 SCAR=11.3
Pod documented
157 6 ▶ my $wtf = shift || die "No Data Passed!";
Condition50%1/2
shift() || die('No Data Passed!')
l!l
60
MC/DC0%0/1
shift() || die('No Data Passed!')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
158 6 $self->init( @_ );
159  
160 6 my $type = $self->get_type( $wtf );
161 6 ▶ if ( defined $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) { } 6 0 6
162 6 my $processor = lc( $type ) . 'ref2SAX';
163 # process the document...
164 6 $self->parse_start;
165 6 $self->$processor( $wtf );
166 6 $self->parse_end;
167 }
168 else {
169 0 die "Data passed must be a reference.";
170 }
171 }
172  
173 sub parse_chunk {
174 0 ▶ my $self = shift;
Subroutine parse_chunk: not called CC=3 SCAR=24.8
Pod documented
175 0 ▶ my $wtf = shift || die "No Data Passed!";
Condition0%0/2
shift() || die('No Data Passed!')
l!l
00
MC/DC0%0/1
shift() || die('No Data Passed!')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
176 0 my $type = $self->get_type( $wtf );
177 0 ▶ if ( defined $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) { } 0 0 0
178 0 my $processor = lc( $type ) . 'ref2SAX';
179 0 $self->$processor( $wtf );
180 }
181 else {
182 0 die "Data passed must be a reference.";
183 }
184 }
185  
186 # Check if we have visited a given reference before
187 sub circular {
188 34 ▶ my($self, $ref) = @_;
Subroutine circular: called CC=1 SCAR=0.0
Pod undocumented
189 34 my $addr = refaddr($ref);
190 34 my $result = $self->{Seen}->{$addr};
191 34 $self->{Seen}->{$addr} = 1;
192 34 return $result;
193 }
194  
195  
196 sub hashref2SAX {
197 18 ▶ my $self = shift;
Subroutine hashref2SAX: called CC=17 SCAR=31.3
Pod undocumented
198 18 my $hashref= shift;
199  
200 18 my $char_data = '';
201  
202 18 ▶ return if $self->circular($hashref);
Branch: 1 branch
BranchTrueFalseTotal
if $self->circular($hashref) 3 15 18
203  
204 15 ELEMENT: foreach my $key (keys (%{$hashref} )) {
205 35 my $value = $hashref->{$key};
206 35 my $element_name = $self->_keymapped_name( $key );
207  
208 35 ▶ next if defined $self->{Skipelements}->{$element_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"Skipelements"}{$element_name} 1 34 35
209  
210 34 ▶ if ( defined $self->{_Parents}->[-1] and defined $self->{Attrmap}->{$self->{_Parents}->[-1]} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_Parents"}[-1] and defined $self->{"Attrmap"}{$self->{"_Parents"}[-1]}) 0 34 34
Condition33%1/3
defined $self->{"_Parents"}[-1] and defined $self->{"Attrmap"}{$self->{"_Parents"}[-1]}
!ll&&!rl&&r
0340
MC/DC0%0/2
defined $self->{"_Parents"}[-1] and defined $self->{"Attrmap"}{$self->{"_Parents"}[-1]}
defined $self->{"_Parents"}[-1] defined $self->{"Attrmap"}{$self->{"_Parents"}[-1]}
Truth table33%1/3
A and B
A= defined $self->{"_Parents"}[-1]B= defined $self->{"Attrmap"}{$self->{"_Parents"}[-1]}
ABresult
0X0
100
111
211 0 foreach my $name ( @{$self->{Attrmap}->{$self->{_Parents}->[-1]}} ) {
212 0 ▶ next ELEMENT if $name eq $element_name;
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $element_name 0 0 0
213 }
214 }
215  
216 34 ▶ if ( defined $self->{_Parents}->[-1] and defined $self->{Charmap}->{$self->{_Parents}->[-1]} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_Parents"}[-1] and defined $self->{"Charmap"}{$self->{"_Parents"}[-1]}) 0 34 34
Condition33%1/3
defined $self->{"_Parents"}[-1] and defined $self->{"Charmap"}{$self->{"_Parents"}[-1]}
!ll&&!rl&&r
0340
MC/DC0%0/2
defined $self->{"_Parents"}[-1] and defined $self->{"Charmap"}{$self->{"_Parents"}[-1]}
defined $self->{"_Parents"}[-1] defined $self->{"Charmap"}{$self->{"_Parents"}[-1]}
Truth table33%1/3
A and B
A= defined $self->{"_Parents"}[-1]B= defined $self->{"Charmap"}{$self->{"_Parents"}[-1]}
ABresult
0X0
100
111
217 0 ▶ if ( grep {$_ eq $element_name} @{$self->{Charmap}->{$self->{_Parents}->[-1]}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $element_name;} @{$self->{"Charmap"}{$self->{"_Parents"}[-1]};}) 0 0 0
218 0 $self->characters( {Data => $value });
219 0 next ELEMENT;
220 }
221 }
222  
223 34 my $type = $self->get_type( $value );
224  
225 34 ▶ if ( $type eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY') { } 7 27 34
elsif ($type eq 'HASH') { } 13 14 27
226 7 push @{$self->{_Parents}}, $element_name;
227 7 $self->arrayref2SAX( $value );
228 7 pop (@{$self->{_Parents}});
229 }
230 elsif ( $type eq 'HASH' ) {
231 # attr mojo
232 13 my %attrs = ();
233 13 ▶ if ( defined $self->{Attrmap}->{$element_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Attrmap"}{$element_name}) 1 12 13
234 1 my @attr_names = ();
235 1 ATTR: foreach my $child ( keys( %{$value} )) {
236 3 my $name = $self->_keymapped_name( $child );
237 3 ▶ if ( grep {$_ eq $name} @{$self->{Attrmap}->{$element_name}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $name;} @{$$self{"Attrmap"}{$element_name};}) 2 1 3
238 2 ▶ if ( ref( $value->{$child} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value->{$child}) 0 2 2
239 0 warn "Cannot use a reference value " . $value->{$child} . " for key '$child' as XML attribute\n";
240 0 next ATTR;
241 }
242  
243 2 $attrs{$name} = $value->{$child};
244 }
245 }
246 }
247 13 $self->start_element( $self->_start_details( $element_name, \%attrs ) );
248 13 push @{$self->{_Parents}}, $element_name;
249 13 $self->hashref2SAX( $value );
250 13 pop (@{$self->{_Parents}});
251 13 $self->end_element( $self->_end_details( $element_name ) );
252 }
253 else {
254 14 $self->start_element( $self->_start_details( $element_name ) );
255 14 $self->characters( {Data => $value} );
256 14 $self->end_element( $self->_end_details( $element_name ) );
257 }
258 }
259 }
260  
261 sub arrayref2SAX {
262 16 ▶ my $self = shift;
Subroutine arrayref2SAX: called CC=14 SCAR=35.7
Pod undocumented
263 16 my $arrayref= shift;
264 16 ▶ my $passed_name = shift || $self->{_Parents}->[-1];
Condition33%1/3
shift() || $self->{'_Parents'}[-1]
l!l&&r!l&&!r
0160
MC/DC0%0/2
shift() || $self->{'_Parents'}[-1]
shift() $self->{'_Parents'}[-1]
Truth table33%1/3
A || B
A= shift()B= $self->{'_Parents'}[-1]
ABresult
1X1
011
000
265 16 my $temp_name = $self->_keymapped_name( $passed_name );
266  
267 16 ▶ return if $self->circular($arrayref);
Branch: 1 branch
BranchTrueFalseTotal
if $self->circular($arrayref) 5 11 16
268  
269 11 my $element_name;
270 my $i;
271  
272 11 ▶ELEMENT: for ( $i = 0; $i < @{$arrayref}; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$arrayref;}) 29 11 40
273 29 ▶ if ( ref( $temp_name ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $temp_name eq 'ARRAY') { } 3 26 29
274 3 ▶ my $ntest = $temp_name->[$i] || $self->{DefaultElementName};
Condition33%1/3
$temp_name->[$i] || $self->{'DefaultElementName'}
l!l&&r!l&&!r
300
MC/DC0%0/2
$temp_name->[$i] || $self->{'DefaultElementName'}
$temp_name->[$i] $self->{'DefaultElementName'}
Truth table33%1/3
A || B
A= $temp_name->[$i]B= $self->{'DefaultElementName'}
ABresult
1X1
011
000
275 3 ▶ if ( ref( $ntest ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ntest eq 'CODE') { } 0 3 3
276 0 $element_name = &{$ntest}();
277 }
278 else {
279 3 $element_name = $self->_keymapped_name( $ntest );
280 }
281 }
282 else {
283 26 $element_name = $temp_name;
284 }
285  
286 29 ▶ next if defined $self->{Skipelements}->{$element_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"Skipelements"}{$element_name} 0 29 29
287  
288 29 my $type = $self->get_type( $arrayref->[$i] );
289  
290 29 my $value = $arrayref->[$i];
291  
292 29 ▶ if ( $type eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY') { } 8 21 29
elsif ($type eq 'HASH') { } 0 21 21
293 8 push @{$self->{_Parents}}, $element_name;
294 8 $self->arrayref2SAX( $value );
295 8 pop (@{$self->{_Parents}});
296 }
297 elsif ( $type eq 'HASH' ) {
298 # attr mojo
299 0 my %attrs = ();
300 0 ▶ if ( defined $self->{Attrmap}->{$element_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Attrmap"}{$element_name}) 0 0 0
301 0 my @attr_names = ();
302 0 ATTR: foreach my $child ( keys( %{$value} )) {
303 0 my $name = $self->_keymapped_name( $child );
304 0 ▶ if ( grep {$_ eq $name} @{$self->{Attrmap}->{$element_name}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $name;} @{$$self{"Attrmap"}{$element_name};}) 0 0 0
305 0 ▶ if ( ref( $value->{$child} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value->{$child}) 0 0 0
306 0 warn "Cannot use a reference value " . $value->{$child} . " for key '$child' as XML attribute\n";
307 0 next ATTR;
308 }
309  
310 0 $attrs{$name} = $value->{$child};
311 }
312 }
313 }
314 0 $self->start_element( $self->_start_details( $element_name, \%attrs ) );
315 0 push @{$self->{_Parents}}, $element_name;
316 0 $self->hashref2SAX( $arrayref->[$i] );
317 0 pop (@{$self->{_Parents}});
318 0 $self->end_element( $self->_end_details( $element_name ) );
319 }
320 else {
321 21 $self->start_element( $self->_start_details( $element_name ) );
322 21 $self->characters( {Data => $arrayref->[$i]} );
323 21 $self->end_element( $self->_end_details( $element_name ) );
324 }
325 }
326 }
327  
328 sub get_type {
329 71 ▶ my $self = shift;
Subroutine get_type: called CC=8 SCAR=23.2
Pod undocumented
330 71 my $wtf = shift;
331  
332 71 my $type = ref( $wtf );
333 71 ▶ if ( $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 36 35 71
334 36 ▶ if ( $type eq 'ARRAY' or $type eq 'HASH' or $type eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'ARRAY' or $type eq 'HASH' or $type eq 'SCALAR') { } 33 3 36
Condition83%5/6
$type eq "ARRAY" or $type eq "HASH" or $type eq "SCALAR"
l!l&&r!l&&!r
3303
$type eq "ARRAY" or $type eq "HASH"
l!l&&r!l&&!r
16173
MC/DC66%2/3
$type eq "ARRAY" or $type eq "HASH" or $type eq "SCALAR"
$type eq "ARRAY" $type eq "HASH" $type eq "SCALAR"
Truth table75%3/4
A or B or C
A= $type eq "ARRAY"B= $type eq "HASH"C= $type eq "SCALAR"
ABCresult
1XX1
01X1
0011
0000
335 33 return $type;
336 }
337 else {
338 # we were passed an object, yuk.
339 # props to barrie slaymaker for the tip here... mine was much fuglier. ;-)
340 3 ▶ if ( UNIVERSAL::isa( $wtf, "HASH" ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($wtf, 'HASH')) { } 3 0 3
elsif (UNIVERSAL::isa($wtf, 'ARRAY')) { } 0 0 0
elsif (UNIVERSAL::isa($wtf, 'SCALAR')) { } 0 0 0
341 3 return 'HASH';
342 }
343 elsif ( UNIVERSAL::isa( $wtf, "ARRAY" ) ) {
344 0 return 'ARRAY';
345 }
346 elsif ( UNIVERSAL::isa( $wtf, "SCALAR" ) ) {
347 0 return 'SCALAR';
348 }
349 else {
350 0 die "Unhandlable reference passed: $type \n";
351 }
352 }
353  
354 }
355 else {
356 35 return '_plain';
357 }
358 }
359  
360 ###
361 # Interface helpers
362 ###
363  
364 sub add_namespace {
365 4 ▶ my $self = shift;
Subroutine add_namespace: called CC=3 SCAR=13.5
Pod documented
366 4 my %args = @_;
367 4 ▶ unless ( defined $args{prefix} and defined $args{uri} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"prefix"} and defined $args{"uri"}) 0 4 4
Condition33%1/3
defined $args{"prefix"} and defined $args{"uri"}
!ll&&!rl&&r
004
MC/DC0%0/2
defined $args{"prefix"} and defined $args{"uri"}
defined $args{"prefix"} defined $args{"uri"}
Truth table33%1/3
A and B
A= defined $args{"prefix"}B= defined $args{"uri"}
ABresult
0X0
100
111
368 0 warn "Invalid arguments passed to add_namespace, skipping.";
369 0 return;
370 }
371 4 $self->{Namespaces}->{"$args{uri}"} = $args{prefix};
372 }
373  
374 sub namespacemap {
375 9 ▶ my $self = shift;
Subroutine namespacemap: called CC=6 SCAR=18.5
Pod documented
376 9 my %nsmap;
377 9 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 1 8 9
378 1 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 1 1
379 0 %nsmap = %{$_[0]};
380 }
381 else {
382 1 %nsmap = @_;
383 }
384  
385 1 ▶ while ( my ($k, $v) = each ( %nsmap ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %nsmap) 3 1 4
386 3 ▶ if ( ref( $v ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) { } 0 3 3
387 0 $self->{Namespacemap}->{$k} = $v;
388 }
389 else {
390 3 $self->{Namespacemap}->{$k} = [ $v ];
391 }
392 }
393 }
394  
395 9 ▶ return wantarray ? %{$self->{Namespacemap}} : $self->{Namespacemap};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 7 9
396 }
397  
398 sub add_namespacemap {
399 2 ▶ my $self = shift;
Subroutine add_namespacemap: called CC=2 SCAR=6.9
Pod documented
400 2 my %args = @_;
401  
402 2 foreach my $uri ( keys( %args )) {
403 2 push @{$self->{Namespacemap}->{"$uri"}}, $args{$uri};
404 }
405 }
406  
407 sub delete_namespacemap {
408 2 ▶ my $self = shift;
Subroutine delete_namespacemap: called CC=8 SCAR=21.1
Pod undocumented
409 2 my @mapped;
410 2 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 2 0 2
411 2 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 2 2
412 0 @mapped = @{$_[0]};
413 }
414 else {
415 2 @mapped = @_;
416 }
417 2 foreach my $name ( @mapped ) {
418 2 foreach my $uri ( keys( %{$self->{Namespacemap}} )) {
419 8 my $i;
420 8 ▶ for ($i = 0; $i < scalar @{$self->{Namespacemap}->{$uri}}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"Namespacemap"}{$uri};}) 8 8 16
421 8 ▶ splice @{$self->{Namespacemap}->{$uri}}, $i, 1 if $self->{Namespacemap}->{$uri}->[$i] eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Namespacemap"}{$uri}[$i] eq $name 2 6 8
422 }
423 8 ▶ delete $self->{Namespacemap}->{$uri} unless scalar @{$self->{Namespacemap}->{$uri}} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->{"Namespacemap"}{$uri};} > 0 1 7 8
424 }
425 }
426 }
427 }
428  
429 sub attrmap {
430 7 ▶ my $self = shift;
Subroutine attrmap: called CC=6 SCAR=18.5
Pod documented
431 7 my %attrmap;
432 7 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 1 6 7
433 1 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 1 1
434 0 %attrmap = %{$_[0]};
435 }
436 else {
437 1 %attrmap = @_;
438 }
439  
440 1 ▶ while ( my ($k, $v) = each( %attrmap )) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %attrmap) 3 1 4
441 3 ▶ if ( ref( $v ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) { } 0 3 3
442 0 $self->{Attrmap}->{$k} = $v;
443 }
444 else {
445 3 $self->{Attrmap}->{$k} = [ $v ];
446 }
447 }
448 }
449  
450 7 ▶ return wantarray ? %{$self->{Attrmap}} : $self->{Attrmap};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 5 7
451 }
452  
453 sub add_attrmap {
454 1 ▶ my $self = shift;
Subroutine add_attrmap: called CC=5 SCAR=17.6
Pod documented
455 1 my %attrmap;
456 1 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 1 0 1
457 1 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 1 1
458 0 %attrmap = %{$_[0]};
459 }
460 else {
461 1 %attrmap = @_;
462 }
463  
464 1 ▶ while ( my ($k, $v) = each ( %attrmap ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %attrmap) 1 1 2
465 1 ▶ if ( ref( $v ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) { } 0 1 1
466 0 $self->{Attrmap}->{$k} = $v;
467 }
468 else {
469 1 $self->{Attrmap}->{$k} = [ $v ];
470 }
471 }
472 }
473 }
474  
475 sub delete_attrmap {
476 1 ▶ my $self = shift;
Subroutine delete_attrmap: called CC=5 SCAR=17.8
Pod documented
477 1 my @mapped;
478 1 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 1 0 1
479 1 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 1 1
480 0 @mapped = @{$_[0]};
481 }
482 else {
483 1 @mapped = @_;
484 }
485 1 foreach my $name ( @mapped ) {
486 1 ▶ delete $self->{Attrmap}->{$name} if $self->{Attrmap}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Attrmap"}{$name} 1 0 1
487 }
488 }
489 }
490  
491 sub charmap {
492 0 ▶ my $self = shift;
Subroutine charmap: not called CC=6 SCAR=37.4
Pod documented
493 0 my %charmap;
494 0 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 0 0 0
495 0 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
496 0 %charmap = %{$_[0]};
497 }
498 else {
499 0 %charmap = @_;
500 }
501  
502 0 ▶ while ( my ($k, $v) = each( %charmap )) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %charmap) 0 0 0
503 0 ▶ if ( ref( $v ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) { } 0 0 0
504 0 $self->{Charmap}->{$k} = $v;
505 }
506 else {
507 0 $self->{Charmap}->{$k} = [ $v ];
508 }
509 }
510 }
511  
512 0 ▶ return wantarray ? %{$self->{Charmap}} : $self->{Charmap};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
513 }
514  
515 sub add_charmap {
516 0 ▶ my $self = shift;
Subroutine add_charmap: not called CC=5 SCAR=34.0
Pod documented
517 0 my %charmap;
518 0 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 0 0 0
519 0 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
520 0 %charmap = %{$_[0]};
521 }
522 else {
523 0 %charmap = @_;
524 }
525  
526 0 ▶ while ( my ($k, $v) = each ( %charmap ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %charmap) 0 0 0
527 0 ▶ if ( ref( $v ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) { } 0 0 0
528 0 $self->{Charmap}->{$k} = $v;
529 }
530 else {
531 0 $self->{Charmap}->{$k} = [ $v ];
532 }
533 }
534 }
535 }
536  
537 sub delete_charmap {
538 0 ▶ my $self = shift;
Subroutine delete_charmap: not called CC=5 SCAR=34.0
Pod documented
539 0 my @mapped;
540 0 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 0 0 0
541 0 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
542 0 @mapped = @{$_[0]};
543 }
544 else {
545 0 @mapped = @_;
546 }
547 0 foreach my $name ( @mapped ) {
548 0 ▶ delete $self->{Charmap}->{$name} if $self->{Charmap}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Charmap"}{$name} 0 0 0
549 }
550 }
551 }
552  
553 sub add_keymap {
554 2 ▶ my $self = shift;
Subroutine add_keymap: called CC=4 SCAR=15.0
Pod documented
555 2 my %keymap;
556 2 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 2 0 2
557 2 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 2 2
558 0 %keymap = %{$_[0]};
559 }
560 else {
561 2 %keymap = @_;
562 }
563  
564 2 foreach my $name ( keys( %keymap )) {
565 2 $self->{Keymap}->{$name} = $keymap{$name};
566 }
567 }
568 }
569  
570 sub delete_keymap {
571 1 ▶ my $self = shift;
Subroutine delete_keymap: called CC=5 SCAR=17.8
Pod documented
572 1 my @mapped;
573 1 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 1 0 1
574 1 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 1 1
575 0 @mapped = @{$_[0]};
576 }
577 else {
578 1 @mapped = @_;
579 }
580 1 foreach my $name ( @mapped ) {
581 1 ▶ delete $self->{Keymap}->{$name} if $self->{Keymap}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Keymap"}{$name} 1 0 1
582 }
583 }
584 }
585  
586 sub add_skipelements {
587 0 ▶ my $self = shift;
Subroutine add_skipelements: not called CC=4 SCAR=30.0
Pod documented
588 0 my @skippers;
589 0 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 0 0 0
590 0 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
591 0 @skippers = @{$_[0]};
592 }
593 else {
594 0 @skippers = @_;
595 }
596 0 foreach my $name ( @skippers ) {
597 0 $self->{Skipelements}->{$name} = 1;
598 }
599 }
600 }
601  
602 sub delete_skipelements {
603 0 ▶ my $self = shift;
Subroutine delete_skipelements: not called CC=5 SCAR=34.0
Pod documented
604 0 my @skippers;
605 0 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 0 0 0
606 0 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
607 0 @skippers = @{$_[0]};
608 }
609 else {
610 0 @skippers = @_;
611 }
612 0 foreach my $name ( @skippers ) {
613 0 ▶ delete $self->{Skipelements}->{$name} if $self->{Skipelements}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Skipelements"}{$name} 0 0 0
614 }
615 }
616 }
617  
618 sub rootname {
619 3 ▶ my ($self, $rootname) = @_;
Subroutine rootname: called CC=2 SCAR=6.9
Pod documented
620  
621 # ubu: add a check to warn them if the processing has already begun?
622 3 ▶ if ( defined $rootname ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rootname) 1 2 3
623 1 $self->{RootName} = $rootname;
624 }
625  
626 3 return $self->{RootName};
627 }
628  
629 sub bindattrs {
630 0 ▶ my $self = shift;
Subroutine bindattrs: not called CC=3 SCAR=24.8
Pod documented
631 0 my $flag = shift;
632 0 ▶ if ( defined($flag) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $flag) 0 0 0
633 0 ▶ if ($flag == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag == 0) { } 0 0 0
634 0 $self->{BindAttrs} = undef;
635 }
636 else {
637 0 $self->{BindAttrs} = 1;
638 }
639 }
640  
641 0 return $self->{BindAttrs};
642  
643 }
644  
645 sub defaultname {
646 3 ▶ my ($self, $dname) = @_;
Subroutine defaultname: called CC=2 SCAR=6.9
Pod documented
647  
648 3 ▶ if ( defined $dname ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dname) 1 2 3
649 1 $self->{DefaultElementName} = $dname;
650 }
651 3 return $self->{DefaultElementName};
652 }
653  
654 sub keymap {
655 7 ▶ my $self = shift;
Subroutine keymap: called CC=4 SCAR=14.1
Pod documented
656 7 my %keymap;
657 7 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 1 6 7
658 1 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 1 1
659 0 %keymap = %{$_[0]};
660 }
661 else {
662 1 %keymap = @_;
663 }
664 1 $self->{Keymap} = \%keymap;
665 }
666  
667 7 ▶ return wantarray ? %{$self->{Keymap}} : $self->{Keymap};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 5 7
668 }
669  
670 sub skipelements {
671 0 ▶ my $self = shift;
Subroutine skipelements: not called CC=5 SCAR=34.0
Pod documented
672 0 my @skippers;
673 0 ▶ if ( scalar( @_ ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0) 0 0 0
674 0 ▶ if ( ref( $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
675 0 @skippers = @{$_[0]};
676 }
677 else {
678 0 @skippers = @_;
679 }
680 0 my %skippers = map { $_, 1} @skippers;
681 0 $self->{Skipelements} = \%skippers;
682 }
683  
684 0 ▶ my @skippers_out = keys %{$self->{Skipelements}} || ();
Condition0%0/3
keys %{$$self{'Skipelements'};} || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
keys %{$$self{'Skipelements'};} || ()
keys %{$$self{'Skipelements'};} ()
Truth table0%0/3
A || B
A= keys %{$$self{'Skipelements'};}B= ()
ABresult
1X1
011
000
685  
686 0 ▶ return wantarray ? @skippers_out : \@skippers_out;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
687 }
688  
689 #XXX
690 sub parse_pi {
691 2 ▶ my $self = shift;
Subroutine parse_pi: called CC=5 SCAR=18.3
Pod undocumented
692 2 my ( $target, $data_in ) = @_;
693  
694 2 my $data_out = '';
695  
696 2 my $ref = $self->get_type( $data_in );
697  
698 2 ▶ if ( $ref eq 'SCALAR' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ref eq 'SCALAR') { } 0 2 2
elsif ($ref eq 'ARRAY') { } 0 2 2
elsif ($ref eq 'HASH') { } 2 0 2
699 0 $data_out = $$data_in;
700 }
701 elsif ( $ref eq 'ARRAY' ) {
702 0 $data_out = join ' ', @{$data_in};
703 }
704 elsif ( $ref eq 'HASH' ) {
705 2 foreach my $k (keys( %{$data_in} )) {
706 4 $data_out .= qq|$k="| . $data_in->{$k} . qq|" |;
707 }
708 }
709 else {
710 0 $data_out = $data_in;
711 }
712  
713 2 $self->processing_instruction({ Target => $target, Data => $data_out });
714 }
715  
716 ###
717 # Convenience helpers to make 'stream style' friendly
718 ###
719  
720 sub start_tag {
721 0 ▶ my $self = shift;
Subroutine start_tag: not called CC=1 SCAR=6.9
Pod documented
722 0 my $element_name = shift;
723 0 my %attrs = @_;
724 0 $self->start_element( $self->_start_details( $element_name, \%attrs ) );
725 0 push @{$self->{_Parents}}, $element_name;
726  
727 }
728  
729 sub end_tag {
730 0 ▶ my ($self, $tagname) = @_;
Subroutine end_tag: not called CC=1 SCAR=6.9
Pod documented
731 0 $self->end_element( $self->_end_details( $tagname ) );
732 0 pop (@{$self->{_Parents}});
733 }
734  
735 ####
736 # Internal Helpers
737 ###
738  
739 sub _keymapped_name {
740 57 ▶ my ($self, $name) = @_;
Subroutine _keymapped_name: called CC=5 SCAR=20.9
741 57 my $element_name;
742 57 ▶ if ( defined $self->{Keymap}->{$name} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'Keymap'}{$name}) { } 4 53 57
elsif (defined $self->{'Keymap'}{'*'}) { } 0 53 53
743 4 my $temp_name = $self->{Keymap}->{$name};
744  
745 4 ▶ if ( ref( $temp_name ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $temp_name eq 'CODE') { } 0 4 4
746 0 $element_name = &{$temp_name}( $name );
747 }
748 else {
749 4 $element_name = $temp_name;
750 }
751 }
752 elsif ( defined $self->{Keymap}->{'*'} ) {
753 0 my $temp_name = $self->{Keymap}->{'*'};
754  
755 0 ▶ if ( ref( $temp_name ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $temp_name eq 'CODE') { } 0 0 0
756 0 $element_name = &{$temp_name}( $name );
757 }
758 else {
759 0 $element_name = $temp_name;
760 }
761 }
762 else {
763 53 $element_name = $name;
764 }
765 }
766  
767 sub _start_details {
768 54 ▶ my $self = shift;
Subroutine _start_details: called CC=10 SCAR=23.4
769 54 my ($element_name, $attrs) = @_;
770 54 my %real_attrs;
771 54 foreach my $attr (keys(%{$attrs})) {
772 2 my $uri;
773 my $prefix;
774 2 my $qname;
775 2 my $lname;
776  
777 2 ▶ if ( defined $self->{BindAttrs} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'BindAttrs'}) { } 0 2 2
778 0 ($uri, $prefix, $qname, $lname) = $self->_namespace_fixer( $attr );
779 }
780 else {
781 2 $lname = $self->_name_fixer( $attr );
782 2 $qname = $lname;
783 }
784  
785 2 ▶ my $key_uri = $uri || "";
Condition50%1/2
$uri || ''
l!l
02
MC/DC0%0/1
$uri || ''
$uri
Truth table50%1/2
A
A= $uri
Aresult
11
00
786 $real_attrs{"\{$key_uri\}$lname"} = {
787 Name => $qname,
788 LocalName => $lname,
789 Prefix => $prefix,
790 NamespaceURI => $uri,
791 2 Value => $attrs->{$attr} };
792  
793 }
794  
795 54 ▶ if ( scalar( keys( %{$self->{Namespaces}} )) > scalar( keys( %{$self->{DeclaredNamespaces}} )) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$$self{"Namespaces"};} > scalar keys %{$$self{"DeclaredNamespaces"};}) 2 52 54
796 2 my @unseen_uris = grep { not defined $self->{DeclaredNamespaces}->{$_} } keys( %{$self->{Namespaces}} );
797 2 foreach my $uri ( @unseen_uris ) {
798 4 my $qname;
799 my $prefix;
800 4 my $lname;
801 4 my $key_uri;
802 4 my $ns_uri;
803  
804 # this, like the Java version of SAX2, explicitly follows production 5.2 of the
805 # W3C Namespaces rec.-- specifically:
806 # http://www.w3.org/TR/1999/REC-xml-names-19990114/#defaulting
807  
808 4 ▶ if ( $self->{Namespaces}->{$uri} eq '#default' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'Namespaces'}{$uri} eq '#default') { } 0 4 4
809 0 $qname = 'xmlns';
810 0 $lname = 'xmlns';
811 0 $prefix = undef;
812 0 $key_uri = "";
813 0 $ns_uri = undef;
814 }
815 else {
816 4 $lname = $self->{Namespaces}->{$uri};
817 4 $prefix = 'xmlns';
818 4 $qname = $prefix . ':' . $lname;
819 #$key_uri = "";
820 4 $key_uri = $NS_XMLNS;
821 4 $ns_uri = $NS_XMLNS;
822 }
823 4 $real_attrs{"\{$key_uri\}$lname"} = {
824 Name => $qname,
825 LocalName => $lname,
826 Prefix => $prefix,
827 NamespaceURI => $ns_uri,
828 Value => $uri };
829  
830 # internal
831 4 $self->{DeclaredNamespaces}->{$uri} = $prefix;
832  
833 # fire events if needed.
834 4 ▶ if ( defined $prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prefix) 4 0 4
835 4 $self->start_prefix_mapping( { Prefix => $self->{Namespaces}->{$uri},
836 NamespaceURI => $uri
837 });
838 }
839 }
840 }
841  
842 54 my ($uri, $prefix, $qname, $lname) = $self->_namespace_fixer( $element_name );
843 54 my %element = (LocalName => $lname,
844 Name => $qname,
845 Prefix => $prefix,
846 NamespaceURI => $uri,
847 Attributes => \%real_attrs,
848 );
849  
850 54 ▶ if ( defined $uri and grep { $element_name eq $_ } @{$self->{Namespacemap}->{$uri}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $uri and grep {$element_name eq $_;} @{$$self{"Namespacemap"}{$uri};}) 5 49 54
Condition100%3/3
defined $uri and grep {$element_name eq $_;} @{$$self{"Namespacemap"}{$uri};}
!ll&&!rl&&r
30195
MC/DC100%2/2
defined $uri and grep {$element_name eq $_;} @{$$self{"Namespacemap"}{$uri};}
defined $uri grep {$element_name eq $_;} @{$$self{"Namespacemap"}{$uri};}
Truth table100%3/3
A and B
A= defined $uriB= grep {$element_name eq $_;} @{$$self{"Namespacemap"}{$uri};}
ABresult
0X0
100
111
851 5 push @{$self->{InScopeNamespaceStack}}, [$uri, $prefix];
852 }
853  
854 54 return \%element;
855 }
856  
857 sub _end_details {
858 54 ▶ my $self = shift;
Subroutine _end_details: called CC=3 SCAR=11.0
859 54 my ($element_name) = @_;
860 54 my ( $uri, $prefix, $qname, $lname ) = $self->_namespace_fixer( $element_name );
861 54 my %element = (LocalName => $lname,
862 Name => $qname,
863 Prefix => $prefix,
864 NamespaceURI => $uri,
865 );
866  
867 54 ▶ if ( defined $uri and grep { $element_name eq $_ } @{$self->{Namespacemap}->{$uri}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $uri and grep {$element_name eq $_;} @{$$self{"Namespacemap"}{$uri};}) 5 49 54
Condition100%3/3
defined $uri and grep {$element_name eq $_;} @{$$self{"Namespacemap"}{$uri};}
!ll&&!rl&&r
30195
MC/DC100%2/2
defined $uri and grep {$element_name eq $_;} @{$$self{"Namespacemap"}{$uri};}
defined $uri grep {$element_name eq $_;} @{$$self{"Namespacemap"}{$uri};}
Truth table100%3/3
A and B
A= defined $uriB= grep {$element_name eq $_;} @{$$self{"Namespacemap"}{$uri};}
ABresult
0X0
100
111
868 5 pop @{$self->{InScopeNamespaceStack}};
869 }
870  
871 54 return \%element;
872 }
873  
874 sub _namespace_fixer {
875 108 ▶ my ( $self, $node_name ) = @_;
Subroutine _namespace_fixer: called CC=9 SCAR=22.3
876 108 my $prefix;
877 my $qname;
878 108 my $uri;
879 108 my $lname = $self->_name_fixer( $node_name );
880  
881 108 foreach my $ns ( keys( %{$self->{Namespacemap}} )) {
882 64 ▶ if ( grep { $node_name eq $_ } @{$self->{Namespacemap}->{"$ns"}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$node_name eq $_;} @{$self->{"Namespacemap"}{"$ns"};}) 10 54 64
883 10 $uri = $ns;
884 }
885 }
886  
887 108 ▶ if ( defined( $uri ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $uri) { } 10 98 108
888 10 $prefix = $self->{Namespaces}->{"$uri"};
889 10 ▶ if ( $prefix eq '#default' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix eq '#default') { } 0 10 10
890 0 $prefix = undef;
891 }
892 else {
893 10 $qname = $prefix . ':' . $lname;
894 }
895 10 ▶ $qname ||= $lname;
Condition33%1/3
$qname ||= $lname
l!l&&r!l&&!r
1000
MC/DC0%0/2
$qname ||= $lname
$qname $lname
Truth table33%1/3
A ||= B
A= $qnameB= $lname
ABresult
1X1
011
000
896 }
897 else {
898 98 ▶ if ( defined $self->{InScopeNamespaceStack}->[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"InScopeNamespaceStack"}[-1]) 38 60 98
899 38 ($uri, $prefix) = @{$self->{InScopeNamespaceStack}->[-1]};
900 38 ▶ if ( $prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix) 38 0 38
901 38 $qname = $prefix . ':' . $lname;
902 }
903 }
904 }
905 108 ▶ $qname ||= $lname;
Condition66%2/3
$qname ||= $lname
l!l&&r!l&&!r
48600
MC/DC0%0/2
$qname ||= $lname
$qname $lname
Truth table66%2/3
A ||= B
A= $qnameB= $lname
ABresult
1X1
011
000
906 108 return ($uri, $prefix, $qname, $lname);
907 }
908  
909  
910 sub _name_fixer {
911 115 ▶ my ($self, $name) = @_;
Subroutine _name_fixer: called CC=1 SCAR=0.0
912 # UNICODE WARNING
913 115 $name =~ s|^[^a-zA-Z_:]{1}|_|g;
914 115 $name =~ tr|a-zA-Z0-9._:-|_|c;
915  
916 115 return $name;
917 }
918  
919 12 1;
920 __END__
↑ Summary