[project @ 5597]
[audio-mpd.git] / lib / Audio / MPD / Item.pm
blobc01b588961a8e459ea7f74da5a0834b40fe65308
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License
13 # along with this program; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 package Audio::MPD::Item;
20 use strict;
21 use warnings;
22 use Carp;
23 use Audio::MPD::Item::Directory;
24 use Audio::MPD::Item::Song;
28 # constructor.
30 sub new {
31 my ($pkg, %params) = @_;
32 croak "new is a class method - can't call it on a ref\n" if ref $pkg;
34 # transform keys in lowercase.
35 my %lowcase;
36 @lowcase{ map { lc } keys %params } = values %params;
38 my $item = exists $params{file} ?
39 Audio::MPD::Item::Song->new(\%lowcase) :
40 Audio::MPD::Item::Directory->new(\%lowcase);
41 return $item;
46 __END__
49 =head1 NAME
51 Audio::MPD::Item - a generic collection item
54 =head1 SYNOPSIS
56 my $item = Audio::MPD::Item->new( %params );
59 =head1 DESCRIPTION
61 C<Audio::MPD::Item> is a virtual class representing a generic item of mpd's
62 collection. It can be either a song or a directory. Depending on the params
63 given to C<new>, it will create and return an C<Audio::MPD::Item::Song> or an
64 C<Audio::MPD::Item::Directory> object. Currently, the discrimination is done
65 on the existence of the C<file> key of C<%params>.
68 =head1 PUBLIC METHODS
70 Note that the only sub worth it in this class is the constructor:
72 =over 4
74 =item new( key => val [, key => val [, ...] ] )
76 Create and return either an C<Audio::MPD::Item::Song> or an
77 C<Audio::MPD::Item::Directory> object.
79 =back
82 =head1 SEE ALSO
84 You can find more information on the mpd project on its homepage at
85 L<http://www.musicpd.org>, or its wiki L<http://mpd.wikia.com>.
87 Regarding this Perl module, you can report bugs on CPAN via
88 L<http://rt.cpan.org/Public/Bug/Report.html?Queue=Audio-MPD>.
90 Audio::MPD development takes place on <audio-mpd@googlegroups.com>: feel free
91 to join us. (use L<http://groups.google.com/group/audio-mpd> to sign in). Our
92 subversion repository is located at L<https://svn.musicpd.org>.
95 =head1 AUTHORS
97 Jerome Quelin <jquelin@cpan.org>
100 =head1 COPYRIGHT AND LICENSE
102 Copyright (c) 2007 Jerome Quelin <jquelin@cpan.org>
105 This program is free software; you can redistribute it and/or modify
106 it under the terms of the GNU General Public License as published by
107 the Free Software Foundation; either version 2 of the License, or
108 (at your option) any later version.
110 This program is distributed in the hope that it will be useful,
111 but WITHOUT ANY WARRANTY; without even the implied warranty of
112 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113 GNU General Public License for more details.
115 =cut