File Coverage

blib/lib/Audio/MPD/Common/Item.pm
Criterion Covered Total %
statement 25 25 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 38 39 97.4


line stmt bran cond sub pod time code
1             #
2             # This file is part of Audio-MPD-Common
3             #
4             # This software is copyright (c) 2007 by Jerome Quelin.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9 1     1   668 use 5.008;
  1         3  
10 1     1   4 use strict;
  1         2  
  1         20  
11 1     1   3 use warnings;
  1         2  
  1         54  
12              
13             package Audio::MPD::Common::Item;
14             # ABSTRACT: a generic collection item
15             $Audio::MPD::Common::Item::VERSION = '2.003';
16 1     1   579 use Audio::MPD::Common::Item::Directory;
  1         3  
  1         42  
17 1     1   709 use Audio::MPD::Common::Item::Playlist;
  1         3  
  1         38  
18 1     1   732 use Audio::MPD::Common::Item::Song;
  1         5  
  1         234  
19              
20              
21             # -- constructor
22              
23              
24             sub new {
25 7     7 1 609 my ($pkg, %params) = @_;
26              
27             # transform keys in lowercase, remove dashes "-"
28 7         12 my %lowcase;
29 7         26 @lowcase{ map { s/-/_/; lc } keys %params } = values %params;
  46         65  
  46         124  
30              
31 7 100       66 return Audio::MPD::Common::Item::Song->new(\%lowcase) if exists $params{file};
32 2 100       24 return Audio::MPD::Common::Item::Directory->new(\%lowcase) if exists $params{directory};
33 1 50       21 return Audio::MPD::Common::Item::Playlist->new(\%lowcase) if exists $params{playlist};
34             }
35              
36             1;
37              
38             __END__
39              
40             =pod
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             Audio::MPD::Common::Item - a generic collection item
47              
48             =head1 VERSION
49              
50             version 2.003
51              
52             =head1 SYNOPSIS
53              
54             my $item = Audio::MPD::Common::Item->new( %params );
55              
56             =head1 DESCRIPTION
57              
58             L<Audio::MPD::Common::Item> is a virtual class representing a generic
59             item of mpd's collection. It can be either a song, a directory or a playlist.
60              
61             Depending on the params given to C<new>, it will create and return an
62             L<Audio::MPD::Common::Item::Song>, an L<Audio::MPD::Common::Item::Directory>
63             or an L<Audio::MPD::Common::Playlist> object. Currently, the
64             discrimination is done on the existence of the C<file> key of C<%params>.
65              
66             =head1 METHODS
67              
68             =head2 my $item = Audio::MPD::Common::Item->new( %params );
69              
70             Create and return either an L<Audio::MPD::Common::Item::Song>, an
71             L<Audio::MPD::Common::Item::Directory> or an L<Audio::MPD::Common::Playlist>
72             object, depending on the existence of a key C<file>, C<directory> or
73             C<playlist> (respectively).
74              
75             =head1 AUTHOR
76              
77             Jerome Quelin
78              
79             =head1 COPYRIGHT AND LICENSE
80              
81             This software is copyright (c) 2007 by Jerome Quelin.
82              
83             This is free software; you can redistribute it and/or modify it under
84             the same terms as the Perl 5 programming language system itself.
85              
86             =cut