File Coverage

blib/lib/AudioFile/Info/MP3/ID3Lib.pm
Criterion Covered Total %
statement 36 37 97.3
branch 4 10 40.0
condition n/a
subroutine 7 8 87.5
pod 1 1 100.0
total 48 56 85.7


line stmt bran cond sub pod time code
1             package AudioFile::Info::MP3::ID3Lib;
2              
3 3     3   238230 use 5.006;
  3         8  
  3         48  
4 3     3   9 use strict;
  3         3  
  3         43  
5 3     3   8 use warnings;
  3         3  
  3         73  
6 3     3   8 use Carp;
  3         4  
  3         116  
7              
8 3     3   464 use MP3::ID3Lib;
  3         8224  
  3         593  
9              
10             my %data = (artist => 'TPE1',
11                         title => 'TIT2',
12                         album => 'TALB',
13                         track => 'TRCK',
14                         year => 'TYER',
15                         genre => 'TCON');
16              
17             sub new {
18 3     3 1 198   my $class = shift;
19 3         4   my $file = shift;
20 3         14   my $obj = MP3::ID3Lib->new($file);
21              
22 3         4069   bless { obj => $obj }, $class;
23             }
24              
25 0     0   0 sub DESTROY {}
26              
27             sub AUTOLOAD {
28 23     23   4546   our $AUTOLOAD;
29              
30 23         99   my ($pkg, $sub) = $AUTOLOAD =~ /(.+)::(\w+)/;
31              
32 23 50       47   die "Invalid attribute $sub" unless exists $data{$sub};
33              
34 23 100       207   if ($_[1]) {
35 6         10     my $attr = $_[1];
36 6         5     my $found;
37 6         5     for (@{$_[0]->{obj}->frames}) {
  6         26  
38 21 0       175       if($_->code eq $data{$sub}) {
39 6         33 $found = 1;
40 6         22 $_->set($attr);
41 6         35         last;
42                   }
43                 }
44              
45 6 50       9     $_[0]->{obj}->add_frame($data{$sub}, $attr) unless $found;
46 6         23     $_[0]->{obj}->commit;
47               }
48              
49 23         439   for (@{$_[0]->{obj}->frames}) {
  23         122  
50 78 0       747     return $_->value if $_->code eq $data{$sub};
51               }
52             }
53              
54              
55             1;
56             __END__
57            
58             =head1 NAME
59            
60             AudioFile::Info::MP3::ID3Lib - Perl extension to get info from MP3 files.
61            
62             =head1 DESCRIPTION
63            
64             This is a plugin for AudioFile::Info which uses MP3::ID3Lib to get
65             data about MP files.
66            
67             See L<AudioFile::Info> for more details.
68            
69             =head1 METHODS
70            
71             =head2 new
72            
73             Creates a new object of class AudioFile::Info::MP3::ID3Lib. Usually called
74             by AudioFile::Info::new.
75            
76             =head1 AUTHOR
77            
78             Dave Cross, E<lt>dave@dave.org.ukE<gt>
79            
80             =head1 COPYRIGHT AND LICENSE
81            
82             Copyright 2003 by Dave Cross
83            
84             This library is free software; you can redistribute it and/or modify
85             it under the same terms as Perl itself.
86            
87             =cut
88