DB/DataTypes/Album.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 92 CC 11 SCAR 25.0
CC
11
Cov
0%
artists
20.0
bitrates
20.0
years
20.0
CRAP 12.2
1 package Audio::DB::DataTypes::Album;
2  
3 use strict 'vars';
4 use Audio::DB::Util::Rearrange;
5 use Audio::DB::DataTypes::Song; # Needs access to fetch album-wide data contained in songs
6  
7  
8 # Data accessors for Album objects
9  
10 sub album { return shift->{album}; }
11 sub album_id { return shift->{album_id}; }
12  
13 sub artists {
14 my $self = shift;
15 my %seen;
16 my @artists = @{$self->{artists}};
17 @artists = map {$_->artist} $self->songs unless @artists;
18 my @unique = grep {!$seen{$_}++} @artists;
19 wantarray ? @unique : (@unique > 1) ? 'various' : $unique[0];
20 }
21  
22 sub songs {
23 my $self = shift;
24 return @{$self->{songs}};
25 }
26  
27 # Call in array context to retrievve all unique bitrates
28 # call in scalar context to retrive predominant bitrate or "various"
29 # if multiple bitrates exist
30 sub bitrates {
31 my $self = shift;
32 my %seen;
33 my @bitrates = @{$self->{bitrates}};
34 @bitrates = map {$_->bitrate} $self->songs unless @bitrates;
35 my @unique = grep {!$seen{$_}++} @bitrates;
36 wantarray ? @unique : (@unique > 1) ? 'various' : $unique[0];
37 }
38  
39 sub years {
40 my $self = shift;
41 my %seen;
42 my @years = @{$self->{years}};
43 @years = map {$_->year} $self->songs unless @years;
44 my @unique = grep {!$seen{$_}++} @years;
45 wantarray ? @unique : (@unique > 1) ? 'various' : $unique[0];
46 }
47  
48 sub songs {
49 my $self = shift;
50 my @songs = @{$self->{songs}};
51 wantarray ? @songs : scalar @songs;
52 }
53  
54 # Add a song to the object
55 sub add_song {
56 my ($self,$song) = @_;
57 push (@{$self->{songs}},$song);
58 }
59  
60 # Add a group of songs to the object
61 sub add_songs {
62 my ($self,$songs) = @_;
63 @{$self->{songs}} = @$songs;
64 }
65  
66  
67 1;