File Coverage

blib/lib/Audio/File/Tag.pm
Criterion Covered Total %
statement 52 63 82.5
branch 17 20 85.0
condition 1 6 16.6
subroutine 11 15 73.3
pod 13 13 100.0
total 94 117 80.3


line stmt bran cond sub pod time code
1             package Audio::File::Tag;
2              
3 1     1   6 use strict;
  1         2  
  1         32  
4 1     1   6 use warnings;
  1         2  
  1         1057  
5              
6             our $VERSION = '0.03';
7              
8             =head1 NAME
9              
10             Audio::File::Tag - abstracts the tag of an audio file
11              
12             =head1 DESCRIPTION
13              
14             Audio::File::Tag is the base class for other file format independant tag classes
15             like Audio::File::Flac::Tag or Audio::File::Ogg::Tag. You shouldn't use this
16             class yourself exept you're writing an own file format dependant subclass.
17              
18             =head1 METHODS
19              
20             =head2 new
21              
22             Constructor. Creates a new Audio::File::Tag object. You shouldn't use this
23             method yourself. It is called by the filetype-dependant subclasses of
24             Audio::File::Type automatically.
25              
26             =cut
27              
28             sub new {
29 3     3 1 8 my($class, $filename) = @_;
30 3   33     19 $class = ref $class || $class;
31 3         15 my $self = { filename => $filename };
32 3         10 bless $self, $class;
33 3 50       18 $self->init(@_) or return;
34 3         27 return $self;
35             }
36              
37             =head2 init
38              
39             Initializes the object. It's called by the constructor and empty by default.
40             It's ought to be overwritten by subclasses.
41              
42             =cut
43              
44 0     0 1 0 sub init {
45              
46             }
47              
48             =head2 title
49              
50             Using title() you can get or set the tags title field. If called without any
51             argument it'll return the current content of the title field. If you call
52             title() with an scalar argument it will set the title field to what the argument
53             contains. The methods artist(), album(), comment(), genre(), year(), track() and total()
54             are called in the same way.
55              
56             =cut
57              
58             sub title {
59 6     6 1 42 my $self = shift;
60 6 100       22 if( @_ ) {
61 3         15 $self->{title} = shift;
62 3         8 return 1;
63             }
64              
65 3         18 return $self->{title};
66             }
67              
68             =head2 artist
69              
70             Set/get the artist field in the files tag.
71              
72             =cut
73              
74             sub artist {
75 6     6 1 25 my $self = shift;
76 6 100       19 if( @_ ) {
77 3         9 $self->{artist} = shift;
78 3         8 return 1;
79             }
80              
81 3         16 return $self->{artist};
82             }
83              
84             =head2 album
85              
86             Set/get the album field in the files tag.
87              
88             =cut
89              
90             sub album {
91 6     6 1 23 my $self = shift;
92 6 100       21 if( @_ ) {
93 3         7 $self->{album} = shift;
94 3         9 return 1;
95             }
96              
97 3         17 return $self->{album};
98             }
99              
100             =head2 comment
101              
102             Set/get the comment field in the files tag.
103              
104             =cut
105              
106             sub comment {
107 6     6 1 152 my $self = shift;
108 6 100       30 if( @_ ) {
109 3         8 $self->{comment} = shift;
110 3         9 return 1;
111             }
112              
113 3         21 return $self->{comment};
114             }
115              
116             =head2 genre
117              
118             Set/get the genre field in the files tag.
119              
120             =cut
121              
122             sub genre {
123 6     6 1 26 my $self = shift;
124 6 100       19 if( @_ ) {
125 3         7 $self->{genre} = shift;
126 3         7 return 1;
127             }
128              
129 3         22 return $self->{genre};
130             }
131              
132             =head2 year
133              
134             Set/get the year field in the files tag.
135              
136             =cut
137              
138             sub year {
139 6     6 1 24 my $self = shift;
140 6 100       19 if( @_ ) {
141 3         12 $self->{year} = shift;
142 3         9 return 1;
143             }
144              
145 3         19 return $self->{year};
146              
147             }
148              
149             =head2 track
150              
151             Set/get the track field in the files tag.
152              
153             =cut
154              
155             sub track {
156 6     6 1 27 my $self = shift;
157 6 100       17 if( @_ ) {
158 3         11 $self->{track} = shift;
159 3         7 return 1;
160             }
161            
162 3         23 return $self->{track} + 0;
163              
164             }
165              
166             =head2 total
167              
168             Set/get the total number of tracks.
169              
170             =cut
171              
172             sub total {
173 6     6 1 21 my $self = shift;
174 6 100       20 if ( @_ ) {
175 3         6 $self->{total} = shift;
176 3         8 return 1;
177             }
178              
179 3         18 return $self->{total} + 0;
180             }
181              
182             =head2 all
183              
184             Set/get all tags. To set the tags pass a hash reference with the names of the
185             tags as keys and the tag values as hash values. Returns a hash reference if no
186             argument is specified.
187              
188             =cut
189              
190             sub all {
191 0     0 1   my $self = shift;
192              
193 0 0         if (@_) {
194 0           my $tags = shift;
195 0           $self->$_($tags->{$_}) for keys %{$tags};
  0            
196 0           return 1;
197             }
198              
199             return {
200 0           title => $self->title(),
201             artist => $self->artist(),
202             album => $self->album(),
203             comment => $self->comment(),
204             genre => $self->genre(),
205             year => $self->year(),
206             track => $self->track(),
207             total => $self->total()
208             };
209             }
210              
211             =head2 is_empty
212              
213             Returns whether all tag fields are empty or not.
214              
215             =cut
216              
217             sub is_empty {
218 0     0 1   my $self = shift;
219 0   0       return ($self->title() &&
220             $self->artist() &&
221             $self->album() &&
222             $self->comment() &&
223             $self->genre() &&
224             $self->year() &&
225             $self->track() &&
226             $self->total());
227             }
228              
229             =head2 save
230              
231             Saves the changed tag information. Not yet implemented.
232              
233             =cut
234              
235 0     0 1   sub save {
236              
237             }
238              
239             1;
240              
241             =head1 TODO
242              
243             =over 4
244              
245             =item Implement writing tags
246              
247             =back
248              
249             =head1 AUTHOR
250              
251             Florian Ragwitz
252              
253             =head1 COPYRIGHT AND LICENSE
254              
255             Copyright (C) Florian Ragwitz
256              
257             This program is free software; you can redistribute it and/or modify
258             it under the terms of the GNU General Public License as published by
259             the Free Software Foundation; either version 2 of the License, or
260             (at your option) any later version.
261              
262             This program is distributed in the hope that it will be useful,
263             but WITHOUT ANY WARRANTY; without even the implied warranty of
264             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
265             GNU Library General Public License for more details.
266              
267             You should have received a copy of the GNU General Public License
268             along with this program; if not, write to the Free Software
269             Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
270              
271             =cut