]>
Commit | Line | Data |
---|---|---|
83d20a45 CS |
1 | # |
2 | # This file is part of Audio::MPD::Common | |
3 | # Copyright (c) 2007 Jerome Quelin, all rights reserved. | |
4 | # | |
5 | # This program is free software; you can redistribute it and/or modify | |
6 | # it under the same terms as Perl itself. | |
7 | # | |
8 | # | |
9 | ||
10 | package Audio::MPD::Common::Item; | |
11 | ||
12 | use strict; | |
13 | use warnings; | |
14 | use Audio::MPD::Common::Item::Directory; | |
15 | use Audio::MPD::Common::Item::Playlist; | |
16 | use Audio::MPD::Common::Item::Song; | |
17 | ||
18 | #our ($VERSION) = '$Rev: 5645 $' =~ /(\d+)/; | |
19 | ||
20 | # | |
21 | # constructor. | |
22 | # | |
23 | sub new { | |
24 | my ($pkg, %params) = @_; | |
25 | ||
26 | # transform keys in lowercase. | |
27 | my %lowcase; | |
28 | @lowcase{ keys %params } = values %params; | |
29 | ||
30 | return Audio::MPD::Common::Item::Song->new(\%lowcase) if exists $params{file}; | |
31 | return Audio::MPD::Common::Item::Directory->new(\%lowcase) if exists $params{directory}; | |
32 | return Audio::MPD::Common::Item::Playlist->new(\%lowcase) if exists $params{playlist}; | |
33 | } | |
34 | ||
35 | 1; | |
36 | ||
37 | __END__ | |
38 | ||
39 | ||
40 | =head1 NAME | |
41 | ||
42 | Audio::MPD::Common::Item - a generic collection item | |
43 | ||
44 | ||
45 | =head1 SYNOPSIS | |
46 | ||
47 | my $item = Audio::MPD::Common::Item->new( %params ); | |
48 | ||
49 | ||
50 | =head1 DESCRIPTION | |
51 | ||
52 | C<Audio::MPD::Common::Item> is a virtual class representing a generic | |
53 | item of mpd's collection. It can be either a song, a directory or a playlist. | |
54 | ||
55 | Depending on the params given to C<new>, it will create and return an | |
56 | C<Audio::MPD::Common::Item::Song>, an C<Audio::MPD::Common::Item::Directory> | |
57 | or an C<Audio::MPD::Common::Playlist> object. Currently, the | |
58 | discrimination is done on the existence of the C<file> key of C<%params>. | |
59 | ||
60 | ||
61 | =head1 PUBLIC METHODS | |
62 | ||
63 | Note that the only sub worth it in this class is the constructor: | |
64 | ||
65 | =over 4 | |
66 | ||
67 | =item new( key => val [, key => val [, ...] ] ) | |
68 | ||
69 | Create and return either an C<Audio::MPD::Common::Item::Song>, an | |
70 | C<Audio::MPD::Common::Item::Directory> or an C<Audio::MPD::Common::Playlist> | |
71 | object, depending on the existence of a key C<file>, C<directory> or | |
72 | C<playlist> (respectively). | |
73 | ||
74 | =back | |
75 | ||
76 | ||
77 | =head1 SEE ALSO | |
78 | ||
79 | =over 4 | |
80 | ||
81 | =item L<Audio::MPD> | |
82 | ||
83 | =item L<POE::Component::Client::MPD> | |
84 | ||
85 | =back | |
86 | ||
87 | ||
88 | =head1 AUTHOR | |
89 | ||
90 | Jerome Quelin, C<< <jquelin at cpan.org> >> | |
91 | ||
92 | ||
93 | =head1 COPYRIGHT & LICENSE | |
94 | ||
95 | Copyright (c) 2007 Jerome Quelin, all rights reserved. | |
96 | ||
97 | This program is free software; you can redistribute it and/or modify | |
98 | it under the same terms as Perl itself. | |
99 | ||
100 | =cut |