lib/XML/SAX/SVGTransformer.pm

filter: Statementstmt 84.1% 201 / 239 Branchbran 63.2% 67 / 106 Conditioncond 52.8% 28 / 53 MC/DCmcdc 28.1% 9 / 32 Subroutinesub 92.3% 24 / 26 Podpod 100% 5 / 5 totaltotal 72.4% 334 / 461 SCAR 51.5
CC
76
Cov
74%
_parse_transform
64.6
_scale
22.4
_ops_to_transform
16.5
CRAP 173.2
« blib/lib/XML/SAX/SVGTransformer.pm ↑ Summary
1 package XML::SAX::SVGTransformer;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base 'XML::SAX::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Math::Matrix;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Math::Trig qw/deg2rad/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.03';
10 2 our $GroupId = 'SVGTransformer';
11  
12 2 my $IdMatrix = Math::Matrix->id(4);
13  
14 sub start_document {
15 3 ▶ my $self = shift;
Subroutine start_document: called CC=1 SCAR=0.0
Pod documented
16 3 $self->SUPER::start_document(@_);
17 3 $self->{_stack} = [];
18 3 $self->{_ops} = [];
19 3 $self->{_stash} = {};
20 }
21  
22 sub start_element {
23 13 ▶ my $self = shift;
Subroutine start_element: called CC=10 SCAR=23.1
Pod documented
24 13 my $elem = $_[0];
25 13 my $name = lc $elem->{LocalName};
26 13 ▶ if ($name eq 'svg' && !$self->_seen($name)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'svg' and not $self->_seen($name)) { } 3 10 13
elsif ($self->_stash('svg') and not $self->_stash('grouped')) { } 3 14 17
Condition66%2/3
$name eq "svg" and not $self->_seen($name)
!ll&&!rl&&r
1003
MC/DC50%1/2
$name eq "svg" and not $self->_seen($name)
$name eq "svg" not $self->_seen($name)
Truth table66%2/3
A and not(B)
A= $name eq "svg"B= not $self->_seen($name)
ABresult
0X0
100
111
27 3 $self->_stash(svg => $elem);
28 3 return;
29 ▶ } elsif ($self->_stash('svg') && !$self->_stash('grouped')) {
Condition66%2/3
$self->_stash("svg") and not $self->_stash("grouped")
!ll&&!rl&&r
703
MC/DC50%1/2
$self->_stash("svg") and not $self->_stash("grouped")
$self->_stash("svg") not $self->_stash("grouped")
Truth table66%2/3
A and not(B)
A= $self->_stash("svg")B= not $self->_stash("grouped")
ABresult
0X0
100
111
30 3 my $svg = $self->_stash('svg');
31 3 my $group;
32 3 ▶ if ($name eq 'g' && (_attr($elem, 'id') || '') eq $self->_group_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'g' and (_attr($elem, 'id') || '') eq $self->_group_id) { } 1 2 3
Condition80%4/5
$name eq "g" and (_attr($elem, "id") || "") eq $self->_group_id
!ll&&!rl&&r
021
_attr($elem, 'id') || ''
l!l
12
MC/DC50%1/2
$name eq "g" and (_attr($elem, "id") || "") eq $self->_group_id
$name eq "g" _attr($elem, 'id')
Truth table66%2/3
A and B
A= $name eq "g"B= _attr($elem, 'id')
ABresult
0X0
100
111
33 1 $group = $elem;
34 } else {
35 2 ▶ my $name = $svg->{Prefix} ? "$svg->{Prefix}:g" : "g";
Branch: 1 branch
BranchTrueFalseTotal
$svg->{'Prefix'} ? : 0 2 2
36 $group = {
37 LocalName => 'g',
38 Name => $name,
39 Prefix => $svg->{Prefix},
40 NamespaceURI => $svg->{NamespaceURI},
41 2 Attributes => {
42 '{}id' => {
43 Name => 'id',
44 Value => $self->_group_id,
45 },
46 '{}transform' => {
47 Name => 'transform',
48 Value => '',
49 },
50 },
51 };
52  
53 2 $self->_stash(added_group => 1);
54 }
55  
56 3 $self->_update_tags($svg, $group);
57 3 $self->_stash(grouped => 1);
58 3 $self->_stash(svg => undef);
59 3 ▶ return unless $self->_stash('added_group');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_stash("added_group") 1 2 3
60 }
61 9 $self->_push($name);
62 9 $self->SUPER::start_element(@_);
63 }
64  
65 sub comment {
66 1 ▶ my ($self, $comment) = @_;
Subroutine comment: called CC=2 SCAR=7.4
Pod documented
67 1 ▶ if ($self->{_stash}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_stash"}) 1 0 1
68 1 $self->{_comment} = $comment->{Data};
69 1 return;
70 }
71 0 $self->SUPER::comment($comment);
72 }
73  
74 sub end_element {
75 13 ▶ my $self = shift;
Subroutine end_element: called CC=7 SCAR=19.7
Pod documented
76 13 my $elem = $_[0];
77 13 my $name = lc $elem->{LocalName};
78 13 ▶ my $prev = $self->{_stack}[-1] || '';
Condition50%1/2
$self->{'_stack'}[-1] || ''
l!l
130
MC/DC0%0/1
$self->{'_stack'}[-1] || ''
$self->{'_stack'}[-1]
Truth table50%1/2
A
A= $self->{'_stack'}[-1]
Aresult
11
00
79 13 ▶ if ($name eq 'svg') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "svg") 3 10 13
80 3 ▶ if ($self->_seen($name) == 1 && $self->_stash('added_group') && $prev eq 'g') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_seen($name) == 1 and $self->_stash("added_group") and $prev eq "g") 2 1 3
Condition66%4/6
$self->_seen($name) == 1 and $self->_stash("added_group") and $prev eq "g"
!ll&&!rl&&r
102
$self->_seen($name) == 1 and $self->_stash("added_group")
!ll&&!rl&&r
012
MC/DC33%1/3
$self->_seen($name) == 1 and $self->_stash("added_group") and $prev eq "g"
$self->_seen($name) == 1 $self->_stash("added_group") $prev eq "g"
Truth table50%2/4
A and B and C
A= $self->_seen($name) == 1B= $self->_stash("added_group")C= $prev eq "g"
ABCresult
0XX0
10X0
1100
1111
81 2 $self->_pop($prev);
82 2 ▶ my $name = $elem->{Prefix} ? "$elem->{Prefix}:g" : 'g';
Branch: 1 branch
BranchTrueFalseTotal
$elem->{'Prefix'} ? : 0 2 2
83 $self->SUPER::end_element({
84 LocalName => 'g',
85 Name => $name,
86 Prefix => $elem->{Prefix},
87 NamespaceURI => $elem->{NamespaceURI},
88 2 });
89 }
90 }
91 13 $self->_pop($name);
92 13 $self->SUPER::end_element(@_);
93 }
94  
95 0 ▶sub info { shift->{_info} || {} }
Subroutine info: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"_info"} or {} 0 0 0
96  
97 sub _update_tags {
98 3 ▶ my ($self, $svg, $group) = @_;
Subroutine _update_tags: called CC=3 SCAR=11.0
99  
100 3 my $svg_width = _attr($svg, 'width');
101 3 my $svg_height = _attr($svg, 'height');
102 3 my $svg_viewbox = _attr($svg, 'viewBox');
103 3 my $svg_version = _attr($svg, 'version');
104  
105 3 my $transform = _attr($group, 'transform');
106  
107 3 my $view;
108 3 @$view{qw/min_x min_y max_x max_y tx ty/} = (0, 0, 0, 0, 0, 0);
109  
110 3 ▶ $svg_viewbox = $self->{_comment} if $self->{_comment};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_comment"} 2 1 3
111  
112 3 ▶ if ($svg_viewbox) {
Branch: 1 branch
BranchTrueFalseTotal
if ($svg_viewbox) { } 3 0 3
113 3 @$view{qw/min_x min_y max_x max_y/} = _split($svg_viewbox);
114 } else {
115 0 $view->{max_x} = _numify($svg_width);
116 0 $view->{max_y} = _numify($svg_height);
117 }
118 3 _translate($view);
119  
120 3 my $scale = _scale($view, @$self{qw/Width Height/});
121 3 push @{$self->{_ops}}, ['scale', @$scale];
122  
123 3 $self->_parse_transform($transform);
124  
125 3 my $matrix = $self->_parse_transform($self->{Transform});
126  
127 3 $view = _to_hash($matrix * _to_matrix($view));
128 3 _translate($view);
129  
130 3 push @{$self->{_ops}}, ['translate', @$view{qw/tx ty/}];
131  
132 3 _attr($svg, 'width', $view->{max_x});
133 3 _attr($svg, 'height', $view->{max_y});
134 3 _attr($svg, 'viewBox', "0 0 $view->{max_x} $view->{max_y}");
135  
136 3 _attr($group, 'transform', $self->_ops_to_transform);
137  
138 3 $self->_push('svg');
139 3 $self->_push('g');
140 3 $self->SUPER::start_element($svg);
141 3 $self->SUPER::comment({Data => $svg_viewbox});
142 3 $self->SUPER::start_element($group);
143  
144 $self->{_info} = {
145 width => $view->{max_x},
146 height => $view->{max_y},
147 3 version => $svg_version,
148 };
149 }
150  
151 sub _parse_transform {
152 6 ▶ my ($self, $transform) = @_;
Subroutine _parse_transform: called CC=21 SCAR=41.7
153  
154 6 my @ops = @{$self->{_ops}};
155 6 ▶ if ($transform) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transform) 3 3 6
156 3 my @parts = (lc $transform) =~ /(\w+(?:\([^)]*\))?)/g;
157 3 for my $op (reverse @parts) {
158 4 my ($name, $arg) = $op =~ /^(\w+)(?:\(([^)]*)\))?$/;
159 4 my @args = _split($arg);
160 4 ▶ if ($name eq 'rotate') {
Branch: 4 branches
BranchTrueFalseTotal
if ($name eq 'rotate') { } 3 1 4
elsif ($name eq 'flipx') { } 0 1 1
elsif ($name eq 'flipy') { } 0 1 1
elsif ($name eq 'matrix') { } 0 1 1
161 3 ▶ if (@ops && $ops[-1][0] eq 'rotate') {
Branch: 1 branch
BranchTrueFalseTotal
if (@ops and $ops[-1][0] eq 'rotate') { } 1 2 3
Condition66%2/3
@ops and $ops[-1][0] eq "rotate"
!ll&&!rl&&r
021
MC/DC50%1/2
@ops and $ops[-1][0] eq "rotate"
@ops $ops[-1][0] eq "rotate"
Truth table66%2/3
A and B
A= @opsB= $ops[-1][0] eq "rotate"
ABresult
0X0
100
111
162 1 $ops[-1][1] += $args[0];
163 1 $ops[-1][1] %= 360;
164 } else {
165 2 push @ops, ['rotate', @args];
166 }
167 } elsif ($name eq 'flipx') {
168 0 my $m = Math::Matrix->diagonal(-1, 1, -1, 1);
169 0 ▶ if (@ops && $ops[-1][0] eq 'matrix') {
Branch: 1 branch
BranchTrueFalseTotal
if (@ops and $ops[-1][0] eq 'matrix') { } 0 0 0
Condition0%0/3
@ops and $ops[-1][0] eq "matrix"
!ll&&!rl&&r
000
MC/DC0%0/2
@ops and $ops[-1][0] eq "matrix"
@ops $ops[-1][0] eq "matrix"
Truth table0%0/3
A and B
A= @opsB= $ops[-1][0] eq "matrix"
ABresult
0X0
100
111
170 0 $ops[-1][1] *= $m;
171 } else {
172 0 push @ops, ['matrix', $m];
173 }
174 } elsif ($name eq 'flipy') {
175 0 my $m = Math::Matrix->diagonal(1, -1, 1, -1);
176 0 ▶ if (@ops && $ops[-1][0] eq 'matrix') {
Branch: 1 branch
BranchTrueFalseTotal
if (@ops and $ops[-1][0] eq 'matrix') { } 0 0 0
Condition0%0/3
@ops and $ops[-1][0] eq "matrix"
!ll&&!rl&&r
000
MC/DC0%0/2
@ops and $ops[-1][0] eq "matrix"
@ops $ops[-1][0] eq "matrix"
Truth table0%0/3
A and B
A= @opsB= $ops[-1][0] eq "matrix"
ABresult
0X0
100
111
177 0 $ops[-1][1] *= $m;
178 } else {
179 0 push @ops, ['matrix', $m];
180 }
181 } elsif ($name eq 'matrix') {
182 0 my $m = Math::Matrix->new([
183 [$args[0], $args[2], 0, 0],
184 [$args[1], $args[3], 0, 0],
185 [0, 0, $args[0], $args[2]],
186 [0, 0, $args[1], $args[3]],
187 ]);
188 0 ▶ if (@ops && $ops[-1] eq 'matrix') {
Branch: 1 branch
BranchTrueFalseTotal
if (@ops and $ops[-1] eq 'matrix') { } 0 0 0
Condition0%0/3
@ops and $ops[-1] eq "matrix"
!ll&&!rl&&r
000
MC/DC0%0/2
@ops and $ops[-1] eq "matrix"
@ops $ops[-1] eq "matrix"
Truth table0%0/3
A and B
A= @opsB= $ops[-1] eq "matrix"
ABresult
0X0
100
111
189 0 $ops[-1][1] *= $m;
190 } else {
191 0 push @ops, ['matrix', $m];
192 }
193 }
194 }
195 3 $self->{_ops} = \@ops;
196 }
197  
198 6 my $matrix = $IdMatrix->clone;
199 6 for my $op (@ops) {
200 9 my ($name, @args) = @$op;
201 9 ▶ if ($name eq 'rotate') {
Branch: 3 branches
BranchTrueFalseTotal
if ($name eq 'rotate') { } 3 6 9
elsif ($name eq 'matrix') { } 0 6 6
elsif ($name eq 'scale') { } 6 0 6
202 3 ▶ my $angle = deg2rad($args[0] || 0);
Condition50%1/2
$args[0] || 0
l!l
30
MC/DC0%0/1
$args[0] || 0
$args[0]
Truth table50%1/2
A
A= $args[0]
Aresult
11
00
203 3 my $sin = sin $angle;
204 3 my $cos = cos $angle;
205 3 my $m = Math::Matrix->new([
206 [$cos, -$sin, 0, 0],
207 [$sin, $cos, 0, 0],
208 [0, 0, $cos, -$sin],
209 [0, 0, $sin, $cos],
210 ]);
211 3 $matrix *= $m;
212 3 ▶ if ($matrix->equal($IdMatrix)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matrix->equal($IdMatrix)) 0 3 3
213 0 $matrix = $IdMatrix->clone;
214 }
215 } elsif ($name eq 'matrix') {
216 0 $matrix *= $args[0];
217 } elsif ($name eq 'scale') {
218 6 $matrix *= Math::Matrix->new(
219 [$args[0], 0, 0, 0],
220 [0, $args[1], 0, 0],
221 [0, 0, $args[0], 0],
222 [0, 0, 0, $args[1]],
223 );
224 }
225 }
226 6 return $matrix;
227 }
228  
229 sub _ops_to_transform {
230 3 ▶ my $self = shift;
Subroutine _ops_to_transform: called CC=12 SCAR=28.1
231 3 my @transform;
232 3 for my $op (@{$self->{_ops}}) {
233 8 my ($name, @args) = @$op;
234 8 ▶ if ($name eq 'rotate') {
Branch: 4 branches
BranchTrueFalseTotal
if ($name eq 'rotate') { } 2 6 8
elsif ($name eq 'matrix') { } 0 6 6
elsif ($name eq 'scale') { } 3 3 6
elsif ($name eq 'translate') { } 3 0 3
235 2 ▶ next if !$args[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $args[0] 0 2 2
236 2 push @transform, "rotate($args[0])";
237 } elsif ($name eq 'matrix') {
238 0 ▶ next if $args[0]->equal($IdMatrix);
Branch: 1 branch
BranchTrueFalseTotal
if $args[0]->equal($IdMatrix) 0 0 0
239 0 my $flatten = join ' ', _flatten($args[0]);
240 0 push @transform, "matrix($flatten)";
241 } elsif ($name eq 'scale') {
242 3 ▶ next if $args[0] == 1 && $args[1] == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $args[0] == 1 and $args[1] == 1 2 1 3
Condition66%2/3
$args[0] == 1 and $args[1] == 1
!ll&&!rl&&r
102
MC/DC50%1/2
$args[0] == 1 and $args[1] == 1
$args[0] == 1 $args[1] == 1
Truth table66%2/3
A and B
A= $args[0] == 1B= $args[1] == 1
ABresult
0X0
100
111
243 1 push @transform, "scale($args[0] $args[1])";
244 } elsif ($name eq 'translate') {
245 3 ▶ next if !$args[0] && !$args[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $args[0] or $args[1] 0 3 3
Condition33%1/3
$args[0] or $args[1]
l!l&&r!l&&!r
300
MC/DC0%0/2
$args[0] or $args[1]
$args[0] $args[1]
Truth table33%1/3
A or B
A= $args[0]B= $args[1]
ABresult
1X1
011
000
246 3 push @transform, "translate($args[0] $args[1])";
247 }
248 }
249 3 join ' ', reverse @transform;
250 }
251  
252 sub _numify {
253 17 ▶ my $number = shift or return 0;
Subroutine _numify: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
my $number = shift() or return 0 3 14 17
254 14 $number =~ tr/0-9.eE\-//cd;
255 14 $number += 0;
256 14 $number =~ s/\.0+$//;
257 14 ▶ $number || 0;
Branch: 1 branch
BranchTrueFalseTotal
$number or 0 0 14 14
258 }
259  
260 sub _split {
261 7 ▶ my $value = shift;
Subroutine _split: called CC=2 SCAR=7.0
262 7 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 7 7
263 7 map { _numify($_) } split /(?:\s+|\s*,\s*)/, $value;
264 }
265  
266 sub _flatten {
267 0 ▶ my $matrix = shift;
Subroutine _flatten: not called CC=1 SCAR=6.9
268 0 my $array = $matrix->as_array;
269 0 my @values = map { _numify($_) } (
270 $array->[0][0],
271 $array->[1][0],
272 $array->[0][1],
273 $array->[1][1],
274 $array->[0][2] + $array->[0][3],
275 $array->[1][2] + $array->[1][3],
276 );
277 0 @values;
278 }
279  
280 sub _translate {
281 6 ▶ my $set = shift;
Subroutine _translate: called CC=5 SCAR=16.2
282  
283 6 ▶ if ($set->{min_x} && $set->{min_x} < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set->{"min_x"} and $set->{"min_x"} < 0) 5 1 6
Condition66%2/3
$set->{"min_x"} and $set->{"min_x"} < 0
!ll&&!rl&&r
105
MC/DC50%1/2
$set->{"min_x"} and $set->{"min_x"} < 0
$set->{"min_x"} $set->{"min_x"} < 0
Truth table66%2/3
A and B
A= $set->{"min_x"}B= $set->{"min_x"} < 0
ABresult
0X0
100
111
284 5 $set->{max_x} -= $set->{min_x};
285 5 $set->{tx} -= $set->{min_x};
286 5 $set->{min_x} = 0;
287 }
288 6 ▶ if ($set->{min_y} && $set->{min_y} < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set->{"min_y"} and $set->{"min_y"} < 0) 1 5 6
Condition66%2/3
$set->{"min_y"} and $set->{"min_y"} < 0
!ll&&!rl&&r
501
MC/DC50%1/2
$set->{"min_y"} and $set->{"min_y"} < 0
$set->{"min_y"} $set->{"min_y"} < 0
Truth table66%2/3
A and B
A= $set->{"min_y"}B= $set->{"min_y"} < 0
ABresult
0X0
100
111
289 1 $set->{max_y} -= $set->{min_y};
290 1 $set->{ty} -= $set->{min_y};
291 1 $set->{min_y} = 0;
292 }
293 }
294  
295 sub _to_matrix {
296 3 ▶ my $set = shift;
Subroutine _to_matrix: called CC=1 SCAR=0.0
297 Math::Matrix->new([
298 [@$set{qw/min_x max_x min_x max_x/}],
299 [@$set{qw/min_y min_y max_y max_y/}],
300 [@$set{qw/tx tx tx tx/}],
301 3 [@$set{qw/ty ty ty ty/}],
302 ]);
303 }
304  
305 sub _to_hash {
306 3 ▶ my $matrix = shift;
Subroutine _to_hash: called CC=1 SCAR=0.0
307 3 my %hash;
308 3 @hash{qw/min_x min_y max_x max_y tx ty/} = (0, 0, 0, 0, 0, 0);
309 3 my $x = $matrix->getrow(0);
310 3 my $y = $matrix->getrow(1);
311 3 my $tx = $matrix->getrow(2);
312 3 my $ty = $matrix->getrow(3);
313 3 $hash{min_x} = $x->min->as_array->[0][0];
314 3 $hash{max_x} = $x->max->as_array->[0][0];
315 3 $hash{min_y} = $y->min->as_array->[0][0];
316 3 $hash{max_y} = $y->max->as_array->[0][0];
317 3 $hash{tx} = $tx->min->as_array->[0][0];
318 3 $hash{ty} = $ty->min->as_array->[0][0];
319 3 \%hash;
320 }
321  
322 sub _scale {
323 3 ▶ my ($set, $x, $y) = @_;
Subroutine _scale: called CC=9 SCAR=31.1
324  
325 3 my ($scale_x, $scale_y) = (1, 1);
326 3 ▶ if ($x && $y) {
Branch: 3 branches
BranchTrueFalseTotal
if ($x and $y) { } 0 3 3
elsif ($x) { } 1 2 3
elsif ($y) { } 0 2 2
Condition66%2/3
$x and $y
!ll&&!rl&&r
210
MC/DC0%0/2
$x and $y
$x $y
Truth table66%2/3
A and B
A= $xB= $y
ABresult
0X0
100
111
327 0 ▶ if ($set->{max_x}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set->{"max_x"}) 0 0 0
328 0 $scale_x = $x / $set->{max_x};
329 }
330 0 ▶ if ($set->{max_y}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set->{"max_y"}) 0 0 0
331 0 $scale_y = $y / $set->{max_y};
332 }
333 } elsif ($x) {
334 1 ▶ if ($set->{max_x}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set->{"max_x"}) 1 0 1
335 1 $scale_x = $x / $set->{max_x};
336 }
337 1 $scale_y = $scale_x;
338 } elsif ($y) {
339 0 ▶ if ($set->{max_y}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set->{"max_y"}) 0 0 0
340 0 $scale_y = $y / $set->{max_y};
341 }
342 0 $scale_x = $scale_y;
343 }
344 3 return [$scale_x, $scale_y];
345 }
346  
347 sub _push {
348 15 ▶ my ($self, $name) = @_;
Subroutine _push: called CC=1 SCAR=0.0
349 15 push @{$self->{_stack}}, $name;
350 }
351  
352 sub _pop {
353 15 ▶ my ($self, $name) = @_;
Subroutine _pop: called CC=2 SCAR=7.6
354 15 my $popped = pop @{$self->{_stack}};
355 15 ▶ if ($name ne $popped) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name ne $popped) 0 15 15
356 0 die "Broken! expected: $name got: $popped left:" . join(",", @{$self->{_stack}});
357 }
358 15 $popped;
359 }
360  
361 sub _seen {
362 6 ▶ my ($self, $name) = @_;
Subroutine _seen: called CC=2 SCAR=6.9
363 6 my $count = grep { $_ eq $name } @{$self->{_stack}};
364 6 ▶ return $count || 0;
Condition100%2/2
$count || 0
l!l
33
MC/DC100%1/1
$count || 0
$count
Truth table100%2/2
A
A= $count
Aresult
11
00
365 }
366  
367 sub _group_id {
368 5 ▶ my $self = shift;
Subroutine _group_id: called CC=2 SCAR=7.6
369 5 ▶ if ($self->{SessionId}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'SessionId'}) { } 0 5 5
370 0 join '-', $GroupId, $self->{SessionId};
371 } else {
372 5 $GroupId;
373 }
374 }
375  
376 sub _stash {
377 33 ▶ my $self = shift;
Subroutine _stash: called CC=2 SCAR=6.9
378 33 my $key = shift;
379 33 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 11 22 33
380 11 $self->{_stash}{$key} = shift;
381 }
382 33 $self->{_stash}{$key};
383 }
384  
385 sub _attr {
386 30 ▶ my $elem = shift;
Subroutine _attr: called CC=7 SCAR=20.3
387 30 my $name = shift;
388 30 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 12 18 30
389 12 my $value = shift;
390 12 ▶ if (defined $value && $value ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value ne '') { } 12 0 12
Condition33%1/3
defined $value and $value ne ""
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $value and $value ne ""
defined $value $value ne ""
Truth table33%1/3
A and B
A= defined $valueB= $value ne ""
ABresult
0X0
100
111
391 12 ▶ if (!exists $elem->{Attributes}{"{}$name"}{Name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $elem->{"Attributes"}{"{}$name"}{"Name"}) 4 8 12
392 4 $elem->{Attributes}{"{}$name"}{Name} = $name;
393 }
394 12 return $elem->{Attributes}{"{}$name"}{Value} = $value;
395 } else {
396 0 delete $elem->{Attributes}{"{}$name"};
397 0 return;
398 }
399 } else {
400 18 ▶ return unless exists $elem->{Attributes};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $elem->{"Attributes"} 0 18 18
401 18 ▶ return unless exists $elem->{Attributes}{"{}$name"};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $elem->{"Attributes"}{"{}$name"} 9 9 18
402 9 return $elem->{Attributes}{"{}$name"}{Value};
403 }
404 }
405  
406 2 1;
407  
408 __END__
« blib/lib/XML/SAX/SVGTransformer.pm ↑ Summary