lib/XML/SAX/SVGTransformer.pm

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