File Coverage

blib/lib/MP3/Tag/ImageSize.pm
Criterion Covered Total %
statement 19 30 63.3
branch 1 6 16.6
condition n/a
subroutine 7 10 70.0
pod 0 2 0.0
total 27 48 56.2


line stmt bran cond sub pod time code
1             package MP3::Tag::ImageSize;
2              
3 6     6   21 use strict;
  6         4  
  6         132  
4 6     6   17 use File::Basename;
  6         7  
  6         283  
5             #use File::Spec;
6 6     6   19 use vars qw /$VERSION @ISA/;
  6         6  
  6         1418  
7              
8             $VERSION="0.01";
9             @ISA = 'MP3::Tag::__hasparent';
10              
11             =pod
12              
13             =head1 NAME
14              
15             MP3::Tag::ImageSize - extract size info from image files via L.
16              
17             =head1 SYNOPSIS
18              
19             my $db = MP3::Tag::ImageSize->new($filename); # Name of multimedia file
20              
21             see L
22              
23             =head1 DESCRIPTION
24              
25             MP3::Tag::ImageSize is designed to be called from the MP3::Tag module.
26              
27             It implements width(), height() and mime_type() methods (sizes in pixels).
28              
29             They return C if C is not available, or does not return valid data.
30              
31             =head1 SEE ALSO
32              
33             L, L
34              
35             =cut
36              
37              
38             # Constructor
39              
40             sub new_with_parent {
41 85     85 0 143 my ($class, $f, $p, $e, %seen, @cue) = (shift, shift, shift);
42 85 50       274 $f = $f->filename if ref $f;
43 85         224 bless [$f], $class;
44             }
45              
46             sub new {
47 0     0 0 0 my ($class, $f) = (shift, shift);
48 0         0 $class->new_with_parent($f, undef, @_);
49             }
50              
51             # Destructor
52              
53       0     sub DESTROY {}
54              
55             my @fields = qw( 0 0 width height img_type mime_type );
56             for my $elt ( 2, 3, 4, 5 ) { # i_bitdepth
57             my $r = sub (;$) {
58 0     0   0 my $self = shift;
59 0 0       0 unless ($self->[1]) {
60 0         0 my ($w, $h, $t) = eval { require Image::Size;
  0         0  
61 0         0 Image::Size::imgsize($self->[0]) };
62 0 0       0 defined $w or @$self[1..4] = (1,undef,undef,undef), return;
63 0         0 my $tt = "image/\L$t";
64 0         0 @$self[1..5] = (1, $w, $h, $t, $tt);
65             }
66 0         0 return $self->[$elt];
67             };
68 6     6   52 no strict 'refs';
  6         7  
  6         276  
69             *{$fields[$elt]} = $r;
70             }
71              
72             for my $elt ( qw( title track artist album year genre comment ) ) {
73 6     6   21 no strict 'refs';
  6         5  
  6         301  
74 116     116   262 *$elt = sub (;$) { return };
75             }
76              
77             1;