blib/lib/URI/Title/Image.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 71 CC 6 SCAR 22.9
CC
6
Cov
0%
pnginfo
20.0
title
12.0
types
2.0
CRAP 9.8
1 package URI::Title::Image;
2 $URI::Title::Image::VERSION = '1.903';
3 use warnings;
4 use strict;
5  
6 use Image::Size;
7  
8 sub types {(
9 'image/gif',
10 'image/jpg',
11 'image/jpeg',
12 'image/png',
13 'image/x-png',
14 )}
15  
16 sub pnginfo {
17 my ($data_ref) = @_;
18 my ($x, $y, $title) = (0, 0, '');
19 if ( eval { require Image::ExifTool } ) {
20 my $info = Image::ExifTool::ImageInfo($data_ref);
21 ($x, $y, $title) = ($info->{ImageWidth}, $info->{ImageHeight}, $info->{Title});
22 }
23 elsif( eval { require Image::PNG::Libpng } ) {
24 my $png = Image::PNG::Libpng::read_from_scalar($$data_ref);
25 $x = $png->get_image_width();
26 $y = $png->get_image_height();
27 my $text_chunks = $png->get_text();
28 for (@$text_chunks) {
29 if ($_->{key} eq "Title") {
30 $title = $_->{text};
31 last;
32 }
33 }
34 }
35 else {
36 ($x, $y) = imgsize($data_ref);
37 }
38 return ($x, $y, $title);
39 }
40  
41 sub title {
42 my ($class, $url, $data, $type) = @_;
43  
44 $type =~ s!^[^/]*/!!;
45 $type =~ s!^x-!!;
46 my $title = "";
47 my $x = 0;
48 my $y = 0;
49 if ( $type =~ /png/ ) {
50 ($x, $y, $title) = pnginfo(\$data);
51 }
52 else {
53 ($x, $y) = imgsize(\$data);
54 }
55 $title ||= ( split m{/}, $url )[-1];
56 return $x && $y
57 ? "$title ($type ${x}x${y})"
58 : "$title ($type)";
59 }
60  
61 1;
62  
63 __END__