blib/lib/Mac/iTunes/Library/Item.pm

filter: Statementstmt 99.6% 274 / 275 Branchbran 83.1% 173 / 208 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 97.6% 42 / 43 Podpod 97.2% 35 / 36 totaltotal 93.2% 524 / 562 CC 106 SCAR 24.7
CC
106
Cov
93%
new
38.0
trackID
3.0
name
3.0
CRAP 11.9
« lib/Mac/iTunes/Library.pm ↑ Summary lib/Mac/iTunes/Library/Playlist.pm »
1 package Mac::iTunes::Library::Item;
2  
3 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 require Exporter;
9 4 our @ISA = qw(Exporter);
10 4 our %EXPORT_TAGS = ( 'all' => [ qw() ] );
11 4 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
12 4 our @EXPORT = qw( );
13  
14 4 our $VERSION = '1.0';
15  
16 =head1 NAME
17  
18 Mac::iTunes::Library::Item - Perl extension for representing an item
19 (song, URL, video) within an iTunes library.
20  
21 =head1 SYNOPSIS
22  
23 use Mac::iTunes::Library::Item;
24  
25 my $item = Mac::iTunes::Library::Item->new(
26 'Track ID' => 1,
27 'Name' => 'The Fooiest Song',
28 'Artist' => 'The Bar Band',
29 );
30 $item->genre('Ska');
31 print "We are the " . $item->artist() . " and we play " .
32 $item->genre() . " music\n";
33 print "Enjoy our hit song " . $item->name() . "\n";
34  
35 =head1 DESCRIPTION
36  
37 A data structure for representing an item (song, URL, video) within an iTunes
38 library. Use this along with Mac::iTunes::Library to create an iTunes library
39 from which other information can be gleaned.
40  
41 =head1 EXPORT
42  
43 None by default.
44  
45 =head1 METHODS
46  
47 =head2 new()
48  
49 Creates a new Mac::iTunes::Library::Item object that can store all of the data
50 of an iTunes library item.
51  
52 my $rec = Mac::iTunes::Library::Item->new();
53  
54 The constructor can also be called initializing any number of the attributes of
55 an item
56  
57 my $rec = Mac::iTunes::Library::Item->new(
58 'Track ID' => '73',
59 'Name' => 'Josie',
60 'Artist' => 'blink-182',
61 'Album Artist' => 'blink-182',
62 'Composer' => 'blink-182',
63 'Album' => 'Dude Ranch',
64 'Grouping' => 'Alternative Rock, 00s Rock'
65 'Genre' => 'Pop Punk',
66 'Kind' => 'MPEG audio file',
67 'Size' => 31337,
68 'Total Time' => 31337,
69 'Year' => '2007',
70 'Date Modified' => '2007-01-01T01:01:01Z',
71 'Date Added' => '2007-01-01T01:01:01Z',
72 'Bit Rate' => 256,
73 'Sample Rate' => 44100,
74 'Play Count' => 1,
75 'Play Date' => -1167613261,
76 'Play Date UTC' => '2007-01-01T01:01:01Z',
77 'Skip Count' => 1,
78 'Skip Count UTC' => '2007-01-01T01:01:01Z',
79 'Rating' => 50,
80 'Album Rating' => 50,
81 'Album Rating Computed' => 1,
82 'Compilation' => 1,
83 'Persistent ID' => 'DAC2FC501CCA2031',
84 'Track Type' => 'File',
85 'Location' => 'file://localhost/Users/dinomite/Music/blink-182/Dude%20Ranch/Josie.mp3',
86 'File Folder Count' => 4,
87 'Library Folder Count' => 1
88 );
89  
90 =cut
91  
92 5 ▶sub new {
Subroutine new: called CC=38 SCAR=36.4
Pod documented
93 5 my $class = shift;
94 5 my %params = @_;
95  
96 # Initialize
97 5 my $self = {
98 'Track ID' => undef,
99 'Name' => undef,
100 'Artist' => undef,
101 'Album Artist' => undef,
102 'Composer' => undef,
103 'Album' => undef,
104 'Grouping' => undef,
105 'Genre' => undef,
106 'Kind' => undef,
107 'Size' => undef,
108 'Total Time' => undef,
109 'Year' => undef,
110 'Date Modified' => undef,
111 'Date Added' => undef,
112 'Bit Rate' => undef,
113 'Comments' => undef,
114 'Sample Rate' => undef,
115 'Play Count' => undef,
116 'Play Date' => undef,
117 'Play Date UTC' => undef,
118 'Release Date' => undef,
119 'Skip Count' => undef,
120 'Skip Count UTC' => undef,
121 'Rating' => undef,
122 'Album Rating' => undef,
123 'Album Rating Computed' => undef,
124 'Compilation' => undef,
125 'Persistent ID' => undef,
126 'Track Type' => undef,
127 'iTunesU' => undef,
128 'Location' => undef,
129 'File Folder Count' => undef,
130 'Library Folder Count' => undef,
131 'Track Count' => undef,
132 'Track Number' => undef,
133 };
134  
135 5 bless $self, $class;
136  
137 # Deal with parameters
138 5 foreach my $param (keys %params) {
139 39 ▶ next unless (defined $param);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param 0 39 39
140  
141 39 ▶ if ($param eq 'Track ID') { trackID($self, $params{'Track ID'}) }
Branch: 35 branches
BranchTrueFalseTotal
if ($param eq 'Track ID') { } 5 34 39
elsif ($param eq 'Name') { } 1 33 34
elsif ($param eq 'Artist') { } 1 32 33
elsif ($param eq 'Album Artist') { } 1 31 32
elsif ($param eq 'Composer') { } 1 30 31
elsif ($param eq 'Album') { } 1 29 30
elsif ($param eq 'Grouping') { } 1 28 29
elsif ($param eq 'Genre') { } 1 27 28
elsif ($param eq 'Kind') { } 1 26 27
elsif ($param eq 'Size') { } 1 25 26
elsif ($param eq 'Total Time') { } 1 24 25
elsif ($param eq 'Year') { } 1 23 24
elsif ($param eq 'Date Modified') { } 1 22 23
elsif ($param eq 'Date Added') { } 1 21 22
elsif ($param eq 'Bit Rate') { } 1 20 21
elsif ($param eq 'Comments') { } 1 19 20
elsif ($param eq 'Sample Rate') { } 1 18 19
elsif ($param eq 'Play Count') { } 1 17 18
elsif ($param eq 'Play Date') { } 1 16 17
elsif ($param eq 'Play Date UTC') { } 1 15 16
elsif ($param eq 'Release Date') { } 1 14 15
elsif ($param eq 'Skip Count') { } 1 13 14
elsif ($param eq 'Skip Date') { } 1 12 13
elsif ($param eq 'Rating') { } 1 11 12
elsif ($param eq 'Album Rating') { } 1 10 11
elsif ($param eq 'Album Rating Computed') { } 1 9 10
elsif ($param eq 'Compilation') { } 1 8 9
elsif ($param eq 'Persistent ID') { } 1 7 8
elsif ($param eq 'Track Type') { } 1 6 7
elsif ($param eq 'iTunesU') { } 1 5 6
elsif ($param eq 'Location') { } 1 4 5
elsif ($param eq 'File Folder Count') { } 1 3 4
elsif ($param eq 'Library Folder Count') { } 1 2 3
elsif ($param eq 'Track Count') { } 1 1 2
elsif ($param eq 'Track Number') { } 1 0 1
142 1 elsif ($param eq 'Name') { name($self, $params{'Name'}) }
143 1 elsif ($param eq 'Artist') { artist($self, $params{'Artist'}) }
144 1 elsif ($param eq 'Album Artist') { albumArtist($self, $params{'Album Artist'}) }
145 1 elsif ($param eq 'Composer') { composer($self, $params{'Composer'}) }
146 1 elsif ($param eq 'Album') { album($self, $params{'Album'}) }
147 1 elsif ($param eq 'Grouping') { grouping($self, $params{'Grouping'}) }
148 1 elsif ($param eq 'Genre') { genre($self, $params{'Genre'}) }
149 1 elsif ($param eq 'Kind') { kind($self, $params{'Kind'}) }
150 1 elsif ($param eq 'Size') { size($self, $params{'Size'}) }
151 1 elsif ($param eq 'Total Time') { totalTime($self, $params{'Total Time'}) }
152 1 elsif ($param eq 'Year') { year($self, $params{'Year'}) }
153 1 elsif ($param eq 'Date Modified') { dateModified($self, $params{'Date Modified'}) }
154 1 elsif ($param eq 'Date Added') { dateAdded($self, $params{'Date Added'}) }
155 1 elsif ($param eq 'Bit Rate') { bitRate($self, $params{'Bit Rate'}) }
156 1 elsif ($param eq 'Comments') { comments($self, $params{'Comments'}) }
157 1 elsif ($param eq 'Sample Rate') { sampleRate($self, $params{'Sample Rate'}) }
158 1 elsif ($param eq 'Play Count') { playCount($self, $params{'Play Count'}) }
159 1 elsif ($param eq 'Play Date') { playDate($self, $params{'Play Date'}) }
160 1 elsif ($param eq 'Play Date UTC') { playDateUTC($self, $params{'Play Date UTC'}) }
161 1 elsif ($param eq 'Release Date') { releaseDate($self, $params{'Release Date'}) }
162 1 elsif ($param eq 'Skip Count') { skipCount($self, $params{'Skip Count'}) }
163 1 elsif ($param eq 'Skip Date') { skipDate($self, $params{'Skip Date'}) }
164 1 elsif ($param eq 'Rating') { rating($self, $params{'Rating'}) }
165 1 elsif ($param eq 'Album Rating') { albumRating($self, $params{'Album Rating'}) }
166 1 elsif ($param eq 'Album Rating Computed') { albumRatingComputed($self, $params{'Album Rating Computed'}) }
167 1 elsif ($param eq 'Compilation') { compilation($self, $params{'Compilation'}) }
168 1 elsif ($param eq 'Persistent ID') { persistentID($self, $params{'Persistent ID'}) }
169 1 elsif ($param eq 'Track Type') { trackType($self, $params{'Track Type'}) }
170 1 elsif ($param eq 'iTunesU') { iTunesU($self, $params{'iTunesU'}) }
171 1 elsif ($param eq 'Location') { location($self, $params{'Location'}) }
172 1 elsif ($param eq 'File Folder Count') { fileFolderCount($self, $params{'File Folder Count'}) }
173 1 elsif ($param eq 'Library Folder Count') { libraryFolderCount($self, $params{'Library Folder Count'}) }
174 1 elsif ($param eq 'Track Count') { trackCount($self, $params{'Track Count'}) }
175 1 elsif ($param eq 'Track Number') { trackNumber($self, $params{'Track Number'}) }
176 0 else { print "Param that I can't handle: $param\n" }
177 }
178  
179 5 return $self;
180 } #new
181  
182 # Clean up
183 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
184 # Nothing to do.
185 } #DESTROY
186  
187 =head2 trackID( $id )
188  
189 Get/set the Track ID attribute for this item.
190  
191 =cut
192  
193 10 ▶sub trackID {
Subroutine trackID: called CC=3 SCAR=11.0
Pod documented
194 10 my $self = shift;
195  
196 10 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 5 10
197 5 my $id = shift;
198 5 ▶ return carp "$id isn't a valid Track ID" unless _checkNum($id);
Branch: 1 branch
BranchTrueFalseTotal
unless _checkNum($id) 0 5 5
199 5 $self->{'Track ID'} = $id;
200 }
201  
202 10 return $self->{'Track ID'};
203 } #trackID
204  
205 # Get/set the Name for this item
206 2 ▶sub name {
Subroutine name: called CC=3 SCAR=11.0
Pod undocumented
207 2 my $self = shift;
208  
209 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
210 1 my $name = shift;
211 1 ▶ return carp "$name isn't a valid Name" unless ($name =~ /.*/);
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /.*/ 0 1 1
212 1 $self->{'Name'} = $name;
213 }
214  
215 2 return $self->{'Name'};
216 } #name
217  
218 =head2 artist( $artist )
219  
220 Get/set the Artist attribute for this item.
221  
222 =cut
223  
224 2 ▶sub artist {
Subroutine artist: called CC=3 SCAR=11.0
Pod documented
225 2 my $self = shift;
226  
227 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
228 1 my $artist = shift;
229 1 ▶ return carp "$artist isn't a valid Artist" unless ($artist =~ /.*/);
Branch: 1 branch
BranchTrueFalseTotal
unless $artist =~ /.*/ 0 1 1
230 1 $self->{'Artist'} = $artist;
231 }
232  
233 2 return $self->{'Artist'};
234 } #artist
235  
236 =head2 albumArtist( $albumArtist )
237  
238 Get/set the Album Artist attribute for this item.
239  
240 =cut
241  
242 2 ▶sub albumArtist {
Subroutine albumArtist: called CC=3 SCAR=11.0
Pod documented
243 2 my $self = shift;
244  
245 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
246 1 my $albumArtist = shift;
247 1 ▶ return carp "$albumArtist isn't a valid Album Artist"
Branch: 1 branch
BranchTrueFalseTotal
unless $albumArtist =~ /.*/ 0 1 1
248 unless ($albumArtist =~ /.*/);
249 1 $self->{'Album Artist'} = $albumArtist;
250 }
251  
252 2 return $self->{'Album Artist'};
253 } #albumArtist
254  
255 =head2 composer( $composer )
256  
257 Get/set the Composer attribute for this item.
258  
259 =cut
260  
261 2 ▶sub composer {
Subroutine composer: called CC=3 SCAR=11.0
Pod documented
262 2 my $self = shift;
263  
264 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
265 1 my $composer = shift;
266 1 ▶ return carp "$composer isn't a valid Composer"
Branch: 1 branch
BranchTrueFalseTotal
unless $composer =~ /.*/ 0 1 1
267 unless ($composer =~ /.*/);
268 1 $self->{'Composer'} = $composer;
269 }
270  
271 2 return $self->{'Composer'};
272 } #composer
273  
274 =head2 album( $album )
275  
276 Get/set the Album attribute for this item.
277  
278 =cut
279  
280 2 ▶sub album {
Subroutine album: called CC=3 SCAR=11.0
Pod documented
281 2 my $self = shift;
282  
283 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
284 1 my $album = shift;
285 1 ▶ return carp "$album isn't a valid Album" unless ($album =~ /.*/);
Branch: 1 branch
BranchTrueFalseTotal
unless $album =~ /.*/ 0 1 1
286 1 $self->{'Album'} = $album;
287 }
288  
289 2 return $self->{'Album'};
290 } #album
291  
292 =head2 grouping( $grouping )
293  
294 Get/set the Grouping attribute for this item.
295  
296 Note: Grouping is intended to be used as a collection of music items below
297 the level of an album (such as on a classical music release) where items
298 are individual movements of a larger work. They are more commonly
299 used as a comma delimited list of tags to build smart playlists.
300  
301 =cut
302  
303 2 ▶sub grouping {
Subroutine grouping: called CC=3 SCAR=11.0
Pod documented
304 2 my $self = shift;
305  
306 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
307 1 my $grouping = shift;
308 1 ▶ return carp "$grouping isn't a valid Grouping" unless ($grouping =~ /.*/);
Branch: 1 branch
BranchTrueFalseTotal
unless $grouping =~ /.*/ 0 1 1
309 1 $self->{'Grouping'} = $grouping;
310 }
311  
312 2 return $self->{'Grouping'};
313 } #grouping
314  
315 =head2 genre( $genre )
316  
317 Get/set the Genre attribute for this item.
318  
319 =cut
320  
321 2 ▶sub genre {
Subroutine genre: called CC=3 SCAR=11.0
Pod documented
322 2 my $self = shift;
323  
324 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
325 1 my $genre = shift;
326 1 ▶ return carp "$genre isn't a valid Genre" unless ($genre =~ /.*/);
Branch: 1 branch
BranchTrueFalseTotal
unless $genre =~ /.*/ 0 1 1
327 1 $self->{'Genre'} = $genre;
328 }
329  
330 2 return $self->{'Genre'};
331 } #genre
332  
333 =head2 kind( $kind )
334  
335 Get/set the Kind ("MPEG audio file", etc.) attribute for this item.
336  
337 =cut
338  
339 2 ▶sub kind {
Subroutine kind: called CC=3 SCAR=11.0
Pod documented
340 2 my $self = shift;
341  
342 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
343 1 my $kind = shift;
344 1 ▶ return carp "$kind isn't a valid Kind"
Branch: 1 branch
BranchTrueFalseTotal
unless $kind =~ /(MPEG|AAC|MPEG-4|Audible) ?(audio|video)? (file|stream)/ 0 1 1
345 unless ($kind =~ /(MPEG|AAC|MPEG-4|Audible) ?(audio|video)? (file|stream)/);
346 1 $self->{'Kind'} = $kind;
347 }
348  
349 2 return $self->{'Kind'};
350 } #kind
351  
352 =head2 size( $size )
353  
354 Get/set the Size attribute for this item.
355  
356 =cut
357  
358 2 ▶sub size {
Subroutine size: called CC=3 SCAR=11.0
Pod documented
359 2 my $self = shift;
360  
361 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
362 1 my $size = shift;
363 1 ▶ return carp "$size isn't a valid Size" unless _checkNum($size);
Branch: 1 branch
BranchTrueFalseTotal
unless _checkNum($size) 0 1 1
364 1 $self->{'Size'} = $size;
365 }
366  
367 2 return $self->{'Size'};
368 } #size
369  
370 =head2 totalTime( $totalTime )
371  
372 Get/set the Total Time attribute for this item.
373  
374 =cut
375  
376 2 ▶sub totalTime {
Subroutine totalTime: called CC=3 SCAR=11.0
Pod documented
377 2 my $self = shift;
378  
379 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
380 1 my $totalTime = shift;
381 1 ▶ return carp "$totalTime isn't a valid Total Time"
Branch: 1 branch
BranchTrueFalseTotal
unless _checkNum($totalTime) 0 1 1
382 unless _checkNum($totalTime);
383 1 $self->{'Total Time'} = $totalTime;
384 }
385  
386 2 return $self->{'Total Time'};
387 } #totalTime
388  
389 =head2 year( $year )
390  
391 Get/set the Year attribute for this item.
392  
393 =cut
394  
395 2 ▶sub year {
Subroutine year: called CC=3 SCAR=11.0
Pod documented
396 2 my $self = shift;
397  
398 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
399 1 my $year = shift;
400 1 ▶ return carp "$year isn't a valid Year" unless ($year =~ /\d{4}/);
Branch: 1 branch
BranchTrueFalseTotal
unless $year =~ /\d{4}/ 0 1 1
401 1 $self->{'Year'} = $year;
402 }
403  
404 2 return $self->{'Year'};
405 } #year
406  
407 =head2 dateModified( $dateModified )
408  
409 Get/set the Date Modified attribute for this item.
410  
411 =cut
412  
413 2 ▶sub dateModified {
Subroutine dateModified: called CC=3 SCAR=11.0
Pod documented
414 2 my $self = shift;
415  
416 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
417 1 my $dateModified = shift;
418 1 ▶ return carp "$dateModified isn't a valid Date Modified"
Branch: 1 branch
BranchTrueFalseTotal
unless _checkDate($dateModified) 0 1 1
419 unless _checkDate($dateModified);
420 1 $self->{'Date Modified'} = $dateModified;
421 }
422  
423 2 return $self->{'Date Modified'};
424 } #dateModified
425  
426 =head2 dateAdded( $dateAdded )
427  
428 Get/set the Date Added attribute for this item.
429  
430 =cut
431  
432 2 ▶sub dateAdded {
Subroutine dateAdded: called CC=3 SCAR=11.0
Pod documented
433 2 my $self = shift;
434  
435 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
436 1 my $dateAdded = shift;
437 1 ▶ return carp "$dateAdded isn't a valid Date Added"
Branch: 1 branch
BranchTrueFalseTotal
unless _checkDate($dateAdded) 0 1 1
438 unless _checkDate($dateAdded);
439 1 $self->{'Date Added'} = $dateAdded;
440 }
441  
442 2 return $self->{'Date Added'};
443 } #dateAdded
444  
445 =head2 bitRate( $bitRate )
446  
447 Get/set the Date Added attribute for this item.
448  
449 =cut
450  
451 2 ▶sub bitRate {
Subroutine bitRate: called CC=3 SCAR=11.0
Pod documented
452 2 my $self = shift;
453  
454 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
455 1 my $bitRate = shift;
456 1 ▶ return carp "$bitRate isn't a valid Bit Rate"
Branch: 1 branch
BranchTrueFalseTotal
unless $bitRate =~ /\d{2,3}/ 0 1 1
457 unless ($bitRate =~ /\d{2,3}/);
458 1 $self->{'Bit Rate'} = $bitRate;
459 }
460  
461 2 return $self->{'Bit Rate'};
462 } #bitRate
463  
464 =head2 comments( $comments )
465  
466 Get/set the Comments attribute for this item.
467  
468 =cut
469  
470 2 ▶sub comments {
Subroutine comments: called CC=3 SCAR=11.0
Pod documented
471 2 my $self = shift;
472  
473 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
474 1 my $comments = shift;
475 1 ▶ return carp "$comments isn't a valid Comments" unless ($comments =~ /.*/);
Branch: 1 branch
BranchTrueFalseTotal
unless $comments =~ /.*/ 0 1 1
476 1 $self->{'Comments'} = $comments;
477 }
478  
479 2 return $self->{'Comments'};
480 } #comment
481  
482 =head2 sampleRate( $sampleRate )
483  
484 Get/set the Sample Rate attribute for this item.
485  
486 =cut
487  
488 2 ▶sub sampleRate {
Subroutine sampleRate: called CC=3 SCAR=11.0
Pod documented
489 2 my $self = shift;
490  
491 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
492 1 my $sampleRate = shift;
493 1 ▶ return carp "$sampleRate isn't a valid Sample Rate"
Branch: 1 branch
BranchTrueFalseTotal
unless $sampleRate =~ /\d{5}/ 0 1 1
494 unless ($sampleRate =~ /\d{5}/);
495 1 $self->{'Sample Rate'} = $sampleRate;
496 }
497  
498 2 return $self->{'Sample Rate'};
499 } #sampleRate
500  
501 =head2 playCount( $playCount )
502  
503 Get/set the Play Count attribute for this item.
504  
505 =cut
506  
507 2 ▶sub playCount {
Subroutine playCount: called CC=3 SCAR=11.0
Pod documented
508 2 my $self = shift;
509  
510 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
511 1 my $playCount = shift;
512 1 ▶ return carp "$playCount isn't a valid Play Count"
Branch: 1 branch
BranchTrueFalseTotal
unless $playCount =~ /\d{1,2}/ 0 1 1
513 unless ($playCount =~ /\d{1,2}/);
514 1 $self->{'Play Count'} = $playCount;
515 }
516  
517 2 return $self->{'Play Count'};
518 } #playCount
519  
520 =head2 playDate( $playDate )
521  
522 Get/set the Play Date attribute for this item.
523  
524 =cut
525  
526 2 ▶sub playDate {
Subroutine playDate: called CC=3 SCAR=11.0
Pod documented
527 2 my $self = shift;
528  
529 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
530 1 my $playDate = shift;
531 1 ▶ return carp "$playDate isn't a valid Play Date"
Branch: 1 branch
BranchTrueFalseTotal
unless $playDate =~ /-\d{10}/ 0 1 1
532 unless ($playDate =~ /-\d{10}/);
533 1 $self->{'Play Date'} = $playDate;
534 }
535  
536 2 return $self->{'Play Date'};
537 } #playDate
538  
539 =head2 playDateUTC( $playDateUTC )
540  
541 Get/set the Play Date UTC attribute for this item.
542  
543 =cut
544  
545 2 ▶sub playDateUTC {
Subroutine playDateUTC: called CC=3 SCAR=11.0
Pod documented
546 2 my $self = shift;
547  
548 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
549 1 my $playDateUTC = shift;
550 1 ▶ return carp "$playDateUTC isn't a valid Play Date UTC"
Branch: 1 branch
BranchTrueFalseTotal
unless _checkDate($playDateUTC) 0 1 1
551 unless _checkDate($playDateUTC);
552 1 $self->{'Play Date UTC'} = $playDateUTC;
553 }
554  
555 2 return $self->{'Play Date UTC'};
556 } #playDateUTC
557  
558 =head2 releaseDate( $releaseDate )
559  
560 Get/set the Release Date attribute for this item.
561  
562 =cut
563  
564 2 ▶sub releaseDate {
Subroutine releaseDate: called CC=3 SCAR=11.0
Pod documented
565 2 my $self = shift;
566  
567 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
568 1 my $releaseDate = shift;
569 1 ▶ return carp "$releaseDate isn't a valid Release Date"
Branch: 1 branch
BranchTrueFalseTotal
unless _checkDate($releaseDate) 0 1 1
570 unless _checkDate($releaseDate);
571 1 $self->{'Release Date'} = $releaseDate;
572 }
573  
574 2 return $self->{'Release Date'};
575 } #releaseDate
576  
577 =head2 skipCount( $skipCount )
578  
579 Get/set the Skip Count attribute for this item.
580  
581 =cut
582  
583 2 ▶sub skipCount {
Subroutine skipCount: called CC=3 SCAR=11.0
Pod documented
584 2 my $self = shift;
585  
586 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
587 1 my $skipCount = shift;
588 1 ▶ return carp "$skipCount isn't a valid Skip Count"
Branch: 1 branch
BranchTrueFalseTotal
unless $skipCount =~ /\d{1,2}/ 0 1 1
589 unless ($skipCount =~ /\d{1,2}/);
590 1 $self->{'Skip Count'} = $skipCount;
591 }
592  
593 2 return $self->{'Skip Count'};
594 } #skipCount
595  
596 =head2 skipDate( $skipDate )
597  
598 Get/set the Skip Date attribute for this item.
599  
600 =cut
601  
602 2 ▶sub skipDate {
Subroutine skipDate: called CC=3 SCAR=11.0
Pod documented
603 2 my $self = shift;
604  
605 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
606 1 my $skipDate = shift;
607 1 ▶ return carp "$skipDate isn't a valid Skip Date"
Branch: 1 branch
BranchTrueFalseTotal
unless _checkDate($skipDate) 0 1 1
608 unless _checkDate($skipDate);
609 1 $self->{'Skip Date'} = $skipDate;
610 }
611  
612 2 return $self->{'Skip Date'};
613 } #skipDate
614  
615 =head2 rating( $rating )
616  
617 Get/set the Rating attribute for this item.
618  
619 =cut
620  
621 2 ▶sub rating {
Subroutine rating: called CC=3 SCAR=11.0
Pod documented
622 2 my $self = shift;
623  
624 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
625 1 my $rating = shift;
626 1 ▶ return carp "$rating isn't a valid Rating"
Branch: 1 branch
BranchTrueFalseTotal
unless $rating =~ /\d{1,3}/ 0 1 1
627 unless ($rating =~ /\d{1,3}/);
628 1 $self->{'Rating'} = $rating;
629 }
630  
631 2 return $self->{'Rating'};
632 } #rating
633  
634 =head2 albumRating( $albumRating )
635  
636 Get/set the Album Rating attribute for this item.
637  
638 =cut
639  
640 2 ▶sub albumRating {
Subroutine albumRating: called CC=3 SCAR=11.0
Pod documented
641 2 my $self = shift;
642  
643 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
644 1 my $albumRating = shift;
645 1 ▶ return carp "$albumRating isn't a valid Album Rating"
Branch: 1 branch
BranchTrueFalseTotal
unless $albumRating =~ /\d{1,3}/ 0 1 1
646 unless ($albumRating =~ /\d{1,3}/);
647 1 $self->{'Album Rating'} = $albumRating;
648 }
649  
650 2 return $self->{'Album Rating'};
651 } #albumRating
652  
653 =head2 albumRatingComputed( $albumRatingComputed )
654  
655 Get/set the Album Rating Computed attribute for this item.
656  
657 =cut
658  
659 2 ▶sub albumRatingComputed {
Subroutine albumRatingComputed: called CC=2 SCAR=6.9
Pod documented
660 2 my $self = shift;
661  
662 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
663 1 my $albumRatingComputed = shift;
664 1 $self->{'Album Rating Computed'} = $albumRatingComputed;
665 }
666  
667 2 return $self->{'Album Rating Computed'};
668 } #albumRatingComputed
669  
670 =head2 compilation( $albumRatingComputed )
671  
672 Get/set the Compilation attribute for this item.
673  
674 =cut
675  
676 2 ▶sub compilation {
Subroutine compilation: called CC=2 SCAR=6.9
Pod documented
677 2 my $self = shift;
678  
679 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
680 1 my $compilation = shift;
681 1 $self->{'Compilation'} = $compilation;
682 }
683  
684 2 return $self->{'Compilation'};
685 } #compilation
686  
687 =head2 persistentID( $persistentID )
688  
689 Get/set the Persistent ID attribute for this item.
690  
691 =cut
692  
693 2 ▶sub persistentID {
Subroutine persistentID: called CC=3 SCAR=11.0
Pod documented
694 2 my $self = shift;
695  
696 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
697 1 my $persistentID = shift;
698 1 ▶ return carp "$persistentID isn't a valid Persistent ID"
Branch: 1 branch
BranchTrueFalseTotal
unless $persistentID =~ /\w{16}/ 0 1 1
699 unless ($persistentID =~ /\w{16}/);
700 1 $self->{'Persistent ID'} = $persistentID;
701 }
702  
703 2 return $self->{'Persistent ID'};
704 } #persistentID
705  
706 =head2 trackType( $trackType )
707  
708 Get/set the Track Type attribute for this item.
709  
710 =cut
711  
712 2 ▶sub trackType {
Subroutine trackType: called CC=3 SCAR=11.0
Pod documented
713 2 my $self = shift;
714  
715 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
716 1 my $trackType = shift;
717 1 ▶ return carp "$trackType isn't a valid Track Type"
Branch: 1 branch
BranchTrueFalseTotal
unless $trackType =~ /(File|URL)/ 0 1 1
718 unless ($trackType =~ /(File|URL)/);
719 1 $self->{'Track Type'} = $trackType;
720 }
721  
722 2 return $self->{'Track Type'};
723 } #trackType
724  
725 =head2 iTunesU( $trackType )
726  
727 Get/set the iTunesU attribute for this item.
728  
729 =cut
730  
731 2 ▶sub iTunesU {
Subroutine iTunesU: called CC=3 SCAR=11.0
Pod documented
732 2 my $self = shift;
733  
734 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
735 1 my $iTunesU = shift;
736 1 ▶ return carp "$iTunesU isn't a valid iTunesU"
Branch: 1 branch
BranchTrueFalseTotal
unless $iTunesU =~ /(Y|N)/ 0 1 1
737 unless ($iTunesU =~ /(Y|N)/);
738 1 $self->{'iTunesU'} = $iTunesU;
739 }
740  
741 2 return $self->{'iTunesU'};
742 } #iTunesU
743  
744  
745 =head2 location( $location )
746  
747 Get/set the Location attribute for this item.
748  
749 =cut
750  
751 2 ▶sub location {
Subroutine location: called CC=3 SCAR=11.0
Pod documented
752 2 my $self = shift;
753  
754 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
755 1 my $location = shift;
756 1 ▶ return carp "$location isn't a valid Location"
Branch: 1 branch
BranchTrueFalseTotal
unless $location =~ /.*/ 0 1 1
757 unless ($location =~ /.*/);
758 1 $self->{'Location'} = $location;
759 }
760  
761 2 return $self->{'Location'};
762 } #location
763  
764 =head2 fileFolderCount( $fileFolderCount )
765  
766 Get/set the File Folder Count attribute for this item.
767  
768 =cut
769 # Get/set the File Folder Count for this item
770 2 ▶sub fileFolderCount {
Subroutine fileFolderCount: called CC=3 SCAR=11.0
Pod documented
771 2 my $self = shift;
772  
773 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
774 1 my $fileFolderCount = shift;
775 1 ▶ return carp "$fileFolderCount isn't a valid File Folder Count"
Branch: 1 branch
BranchTrueFalseTotal
unless _checkNum($fileFolderCount) 0 1 1
776 unless _checkNum($fileFolderCount);
777 1 $self->{'File Folder Count'} = $fileFolderCount;
778 }
779  
780 2 return $self->{'File Folder Count'};
781 } #fileFolderCount
782  
783 =head2 libraryFolderCount( $libraryFolderCount )
784  
785 Get/set the Library Folder Count attribute for this item.
786  
787 =cut
788  
789 2 ▶sub libraryFolderCount {
Subroutine libraryFolderCount: called CC=3 SCAR=11.0
Pod documented
790 2 my $self = shift;
791  
792 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
793 1 my $libraryFolderCount = shift;
794 1 ▶ return carp "$libraryFolderCount isn't a valid Library Folder Count"
Branch: 1 branch
BranchTrueFalseTotal
unless _checkNum($libraryFolderCount) 0 1 1
795 unless _checkNum($libraryFolderCount);
796 1 $self->{'Library Folder Count'} = $libraryFolderCount;
797 }
798  
799 2 return $self->{'Library Folder Count'};
800 } #libraryFolderCount
801  
802  
803 =head2 trackCount( $trackCount )
804  
805 Get/set the Track Count attribute for this item.
806  
807 =cut
808  
809 2 ▶sub trackCount {
Subroutine trackCount: called CC=3 SCAR=11.0
Pod documented
810 2 my $self = shift;
811  
812 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
813 1 my $trackCount = shift;
814 1 ▶ return carp "$trackCount isn't a valid Track Count"
Branch: 1 branch
BranchTrueFalseTotal
unless _checkNum($trackCount) 0 1 1
815 unless _checkNum($trackCount);
816 1 $self->{'Track Count'} = $trackCount;
817 }
818  
819 2 return $self->{'Track Count'};
820 } #trackCount
821  
822  
823 =head2 trackNumber( $trackNumber )
824  
825 Get/set the Track Number attribute for this item.
826  
827 =cut
828  
829 2 ▶sub trackNumber {
Subroutine trackNumber: called CC=3 SCAR=11.0
Pod documented
830 2 my $self = shift;
831  
832 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
833 1 my $trackNumber = shift;
834 1 ▶ return carp "$trackNumber isn't a valid Track Number"
Branch: 1 branch
BranchTrueFalseTotal
unless _checkNum($trackNumber) 0 1 1
835 unless _checkNum($trackNumber);
836 1 $self->{'Track Number'} = $trackNumber;
837 }
838  
839 2 return $self->{'Track Number'};
840 } #trackNumber
841  
842  
843 ##### Support methods #####
844 # Is it a number?
845 11 ▶sub _checkNum {
Subroutine _checkNum: called CC=1 SCAR=0.0
846 11 my $digit = shift;
847  
848 11 return $digit =~ /\d*/;
849 } #_checkNum
850  
851 # Is it a date?
852 5 ▶sub _checkDate {
Subroutine _checkDate: called CC=1 SCAR=0.0
853 5 my $date = shift;
854  
855 5 return $date =~ /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/;
856 } #_checkDate
857  
858  
859 4 1;
860  
861 =head1 SEE ALSO
862  
863 L<Mac::iTunes::Library>, L<Mac::iTunes::Library::Playlist>,
864 L<Mac::iTunes::Library::XML>
865  
866 =head1 AUTHOR
867  
868 Drew Stephens <drew@dinomite.net>, http://dinomite.net
869  
870 =head1 CONTRIBUTORS
871  
872 =over 4
873  
874 =item *
875  
876 Mark Allen <mrallen1@yahoo.com>
877  
878 =item *
879  
880 Michael G Schwern <mschwern@cpan.org>
881  
882 =item *
883  
884 David Rostcheck <davidr@thisisdavidr.net>
885  
886 =back
887  
888 =head1 SOURCE REPOSITORY
889  
890 http://mac-itunes.googlecode.com
891  
892 =head1 SVN INFO
893  
894 $Revision: 90 $
895  
896 =head1 COPYRIGHT AND LICENSE
897  
898 Copyright (C) 2007-2008 by Drew Stephens
899  
900 This library is free software; you can redistribute it and/or modify
901 it under the same terms as Perl itself, either Perl version 5.8.8 or,
902 at your option, any later version of Perl 5 you may have available.
903  
904 =cut
905 __END__
« lib/Mac/iTunes/Library.pm ↑ Summary lib/Mac/iTunes/Library/Playlist.pm »