[project @ 6204]
[poe-component-client-mpd.git] / lib / POE / Component / Client / MPD / Playlist.pm
blob0b68eac933e44f7dac46cc5d6f29d794cca76708
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 POE::Component::Client::MPD::Playlist;
20 use strict;
21 use warnings;
23 use POE;
24 use POE::Component::Client::MPD::Message;
25 use base qw[ Class::Accessor::Fast ];
27 # -- Playlist: retrieving information
30 # event: pl.as_items()
32 # Return an array of C<POCOCM::Item::Song>s, one for each of the
33 # songs in the current playlist.
35 sub _onpub_as_items {
36 my $msg = POE::Component::Client::MPD::Message->new( {
37 _from => $_[SENDER]->ID,
38 _request => $_[STATE],
39 _answer => $SEND,
40 _commands => [ 'playlistinfo' ],
41 _cooking => $AS_ITEMS,
42 } );
43 $_[KERNEL]->yield( '_send', $msg );
48 # event: pl.items_changed_since( $plversion )
50 # Return a list with all the songs (as POCOM::Item::Song objects) added to
51 # the playlist since playlist $plversion.
53 sub _onpub_items_changed_since {
54 my $plid = $_[ARG0];
55 my $msg = POE::Component::Client::MPD::Message->new( {
56 _from => $_[SENDER]->ID,
57 _request => $_[STATE],
58 _answer => $SEND,
59 _commands => [ "plchanges $plid" ],
60 _cooking => $AS_ITEMS,
61 } );
62 $_[KERNEL]->yield( '_send', $msg );
66 # -- Playlist: adding / removing songs
69 # event: pl.add( $path, $path, ... )
71 # Add the songs identified by $path (relative to MPD's music directory) to
72 # the current playlist.
73 # No return event.
75 sub _onpub_add {
76 my @pathes = @_[ARG0 .. $#_]; # args of the poe event
77 my @commands = ( # build the commands
78 'command_list_begin',
79 map( qq[add "$_"], @pathes ),
80 'command_list_end',
82 my $msg = POE::Component::Client::MPD::Message->new( {
83 _from => $_[SENDER]->ID,
84 _request => $_[STATE],
85 _answer => $DISCARD,
86 _commands => \@commands,
87 _cooking => $RAW,
88 } );
89 $_[KERNEL]->yield( '_send', $msg );
94 # event: pl.delete( $number, $number, ... )
96 # Remove song $number (starting from 0) from the current playlist.
97 # No return event.
99 sub _onpub_delete {
100 my @numbers = @_[ARG0 .. $#_]; # args of the poe event
101 my @commands = ( # build the commands
102 'command_list_begin',
103 map( qq[delete $_], reverse sort {$a<=>$b} @numbers ),
104 'command_list_end',
106 my $msg = POE::Component::Client::MPD::Message->new( {
107 _from => $_[SENDER]->ID,
108 _request => $_[STATE],
109 _answer => $DISCARD,
110 _commands => \@commands,
111 _cooking => $RAW,
112 } );
113 $_[KERNEL]->yield( '_send', $msg );
118 # event: clear()
120 # Remove all the songs from the current playlist.
122 sub _onpub_clear {
123 my $msg = POE::Component::Client::MPD::Message->new( {
124 _from => $_[SENDER]->ID,
125 _request => $_[STATE],
126 _answer => $DISCARD,
127 _commands => [ 'clear' ],
128 _cooking => $RAW,
129 } );
130 $_[KERNEL]->yield( '_send', $msg );
135 # -- Playlist: changing playlist order
136 # -- Playlist: managing playlists
140 __END__
142 =head1 NAME
144 POE::Component::Client::MPD::Playlist - module handling playlist commands
147 =head1 DESCRIPTION
149 C<POCOCM::Playlist> is responsible for handling playlist-related commands.
150 To achieve those commands, send the corresponding event to the POCOCM
151 session you created: it will be responsible for dispatching the event
152 where it is needed.
155 =head1 PUBLIC EVENTS
157 The following is a list of general purpose events accepted by POCOCM.
160 =head2 Retrieving information
162 =head2 Adding / removing songs
164 =head2 Changing playlist order
166 =head2 Managing playlists
169 =head1 SEE ALSO
171 For all related information (bug reporting, mailing-list, pointers to
172 MPD and POE, etc.), refer to C<POE::Component::Client::MPD>'s pod,
173 section C<SEE ALSO>
176 =head1 AUTHOR
178 Jerome Quelin, C<< <jquelin at cpan.org> >>
181 =head1 COPYRIGHT & LICENSE
183 Copyright 2007 Jerome Quelin, all rights reserved.
185 This program is free software; you can redistribute it and/or modify
186 it under the terms of the GNU General Public License as published by
187 the Free Software Foundation; either version 2 of the License, or
188 (at your option) any later version.
190 This program is distributed in the hope that it will be useful,
191 but WITHOUT ANY WARRANTY; without even the implied warranty of
192 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
193 GNU General Public License for more details.
195 You should have received a copy of the GNU General Public License
196 along with this program; if not, write to the Free Software
197 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
199 =cut