line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SVG::SpriteMaker; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
12780
|
use 5.014000; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
52
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
8
|
|
|
|
|
|
|
our @EXPORT = qw/make_sprite make_sprite_prefix/; |
9
|
|
|
|
|
|
|
our @EXPORT_OK = @EXPORT; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
383
|
use parent qw/Exporter/; |
|
1
|
|
|
|
|
197
|
|
|
1
|
|
|
|
|
4
|
|
12
|
1
|
|
|
1
|
|
49
|
use re '/s'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
59
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
63
|
|
15
|
1
|
|
|
1
|
|
4
|
use File::Basename; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
454
|
use SVG -indent => '', -elsep => ''; |
|
1
|
|
|
|
|
9889
|
|
|
1
|
|
|
|
|
9
|
|
18
|
1
|
|
|
1
|
|
1055
|
use SVG::Parser; |
|
1
|
|
|
|
|
372
|
|
|
1
|
|
|
|
|
6
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub make_sprite { |
21
|
1
|
|
|
1
|
1
|
76
|
my ($prefix, @images) = @_; |
22
|
|
|
|
|
|
|
my $sub = ref $prefix eq 'CODE' ? $prefix : sub { |
23
|
2
|
|
|
2
|
|
75
|
my $base = scalar fileparse $_[0], qr/[.].*/; |
24
|
2
|
|
|
|
|
32
|
"$prefix-$base" |
25
|
1
|
50
|
|
|
|
11
|
}; |
26
|
1
|
|
|
|
|
14
|
my $sprite = SVG->new(-inline => 1); |
27
|
1
|
|
|
|
|
272
|
my $parser = SVG::Parser->new; |
28
|
1
|
|
|
|
|
36820
|
@images = map {[ $sub->($_) => $parser->parse_file($_) ]} @images; |
|
2
|
|
|
|
|
3647
|
|
29
|
1
|
|
|
|
|
2576
|
my ($x, $mh) = (0, 0); |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
2
|
for (@images) { |
32
|
2
|
|
|
|
|
43
|
my ($img, $doc) = @$_; |
33
|
2
|
|
|
|
|
10
|
my $svg = $doc->getFirstChild; |
34
|
2
|
50
|
|
|
|
25
|
my ($w) = $svg->attr('width') =~ /([0-9.]*)/ or carp "Image $img has no width"; |
35
|
2
|
50
|
|
|
|
22
|
my ($h) = $svg->attr('height') =~ /([0-9.]*)/ or carp "Image $img has no height"; |
36
|
2
|
100
|
|
|
|
19
|
$mh = $h if $h > $mh; |
37
|
2
|
|
|
|
|
4
|
$svg->attr(x => $x); |
38
|
2
|
|
|
|
|
11
|
$svg->attr(version => undef); |
39
|
2
|
|
|
|
|
18
|
my $view = $sprite->view(id => $img, viewBox => "$x 0 $w $h"); |
40
|
2
|
|
|
|
|
85
|
$x += $w + 5; |
41
|
2
|
|
|
|
|
7
|
$view->getParent->insertAfter($svg, $view); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Keep a reference to the documents to prevent garbage collection |
45
|
1
|
|
|
|
|
24
|
$sprite->{'--images'} = \@images; |
46
|
1
|
|
|
|
|
3
|
$sprite->getFirstChild->attr(viewBox => "0 0 $x $mh"); |
47
|
1
|
|
|
|
|
48
|
$sprite |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
__END__ |