File Coverage

blib/lib/AudioFile/Info/Ogg/Vorbis/Header.pm
Criterion Covered Total %
statement 28 30 93.3
branch 4 6 66.7
condition n/a
subroutine 7 8 87.5
pod 1 1 100.0
total 40 45 88.9


line stmt bran cond sub pod time code
1             #
2             # $Id$
3             #
4              
5             =head1 NAME
6            
7             AudioFile::Info::Ogg::Vorbis::Header - Perl extension to get info from
8             Ogg Vorbis files.
9            
10             =head1 DESCRIPTION
11            
12             Extracts data from an Ogg Vorbis file using the CPAN module
13             Ogg::Vorbis::Header.
14            
15             See L<AudioFile::Info> for more details.
16            
17             =cut
18              
19             package AudioFile::Info::Ogg::Vorbis::Header;
20              
21 3     3   200755 use 5.006;
  3         10  
  3         47  
22 3     3   9 use strict;
  3         2  
  3         47  
23 3     3   9 use warnings;
  3         3  
  3         63  
24 3     3   9 use Carp;
  3         3  
  3         121  
25              
26 3     3   759 use Ogg::Vorbis::Header;
  3         18327  
  3         629  
27             # nasty Inline kludge
28             # needed as this module is never "used", only "required"
29             require Inline;
30             Inline->init;
31              
32             our $VERSION = sprintf "%d", '$Revision$ ' =~ /(\d+)/;
33              
34             my %data = (artist => 'artist',
35                         title => 'title',
36                         album => 'album',
37                         track => 'tracknumber',
38                         year => 'date',
39                         genre => 'genre');
40              
41             sub new {
42 3     3 1 206   my $class = shift;
43 3         7   my $file = shift;
44 3         20   my $obj = Ogg::Vorbis::Header->new($file);
45              
46 3         1085   bless { obj => $obj }, $class;
47             }
48              
49 0     0   0 sub DESTROY {}
50              
51             sub AUTOLOAD {
52 24     24   2790   our $AUTOLOAD;
53              
54 24         131   my ($pkg, $sub) = $AUTOLOAD =~ /(.*)::(\w+)/;
55              
56 24 50       69   croak "Invalid attribute '$sub'" unless $data{$sub};
57              
58 24 100       52   if ($_[1]) {
59 6 50       55     if (grep { $_ eq $data{$sub} } $_[0]->{obj}->comment_tags) {
  57         373  
60 0         0       $_[0]->{obj}->edit_comment($data{$sub}, $_[1]);
61                 } else {
62 6         63       $_[0]->{obj}->add_comments($data{$sub}, $_[1]);
63                 }
64 6         11620     $_[0]->{obj}->write_vorbis;
65               }
66              
67 24         244   return ($_[0]->{obj}->comment($data{$sub}))[0];
68             }
69              
70             1;
71             __END__
72            
73             =head1 METHODS
74            
75             =head2 new
76            
77             Creates a new object of class AudioFile::Info::Ogg::Vorbis::Header. Usually
78             called by AudioFile::Info::new.
79            
80             =head1 AUTHOR
81            
82             Dave Cross, E<lt>dave@dave.org.ukE<gt>
83            
84             =head1 COPYRIGHT AND LICENSE
85            
86             Copyright 2003 by Dave Cross
87            
88             This library is free software; you can redistribute it and/or modify
89             it under the same terms as Perl itself.
90            
91             =cut
92