« blib/lib/POE/Component/Client/MPD/Playlist.pm
↑ Summary
blib/lib/POE/Component/Client/MPD/Test.pm »
| 1 | # | ||||||||||||
| 2 | # This file is part of POE-Component-Client-MPD | ||||||||||||
| 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 | 16 | ▶ | use 5.010; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 16 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 16 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | package POE::Component::Client::MPD::Collection; | ||||||||||||
| 14 | # ABSTRACT: module handling collection commands | ||||||||||||
| 15 | 16 | $POE::Component::Client::MPD::Collection::VERSION = '2.000'; | |||||||||||
| 16 | 16 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 16 | ▶ | use MooseX::Has::Sugar; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 16 | ▶ | use POE; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | 16 | ▶ | use POE::Component::Client::MPD::Message; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | |||||||||||||
| 22 | 16 | has mpd => ( ro, required, weak_ref, );# isa=>'POE::Component::Client::MPD' ); | |||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | # -- Collection: retrieving songs & directories | ||||||||||||
| 26 | |||||||||||||
| 27 | |||||||||||||
| 28 | sub _do_all_items { | ||||||||||||
| 29 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_all_items: not called CC=2 SCAR=17.9
| |||||||||||||
| 30 | 0 | ▶ | my $path = $msg->params->[0] // ''; # FIXME: padre// | ||||||||||
|
Condition0%0/2
$msg->params->[0] // ""
MC/DC0%0/1
$msg->params->[0] // ""
$msg->params->[0]
Truth table0%0/2
A
A= $msg->params->[0]
| |||||||||||||
| 31 | |||||||||||||
| 32 | 0 | $msg->_set_commands ( [ qq{listallinfo "$path"} ] ); | |||||||||||
| 33 | 0 | $msg->_set_cooking ( 'as_items' ); | |||||||||||
| 34 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | |||||||||||||
| 38 | |||||||||||||
| 39 | sub _do_all_items_simple { | ||||||||||||
| 40 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_all_items_simple: not called CC=2 SCAR=17.9
| |||||||||||||
| 41 | 0 | ▶ | my $path = $msg->params->[0] // ''; # FIXME: padre// | ||||||||||
|
Condition0%0/2
$msg->params->[0] // ""
MC/DC0%0/1
$msg->params->[0] // ""
$msg->params->[0]
Truth table0%0/2
A
A= $msg->params->[0]
| |||||||||||||
| 42 | |||||||||||||
| 43 | 0 | $msg->_set_commands ( [ qq{listall "$path"} ] ); | |||||||||||
| 44 | 0 | $msg->_set_cooking ( 'as_items' ); | |||||||||||
| 45 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | |||||||||||||
| 49 | |||||||||||||
| 50 | sub _do_items_in_dir { | ||||||||||||
| 51 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_items_in_dir: not called CC=2 SCAR=17.9
| |||||||||||||
| 52 | 0 | ▶ | my $path = $msg->params->[0] // ''; # FIXME: padre// | ||||||||||
|
Condition0%0/2
$msg->params->[0] // ""
MC/DC0%0/1
$msg->params->[0] // ""
$msg->params->[0]
Truth table0%0/2
A
A= $msg->params->[0]
| |||||||||||||
| 53 | |||||||||||||
| 54 | 0 | $msg->_set_commands ( [ qq{lsinfo "$path"} ] ); | |||||||||||
| 55 | 0 | $msg->_set_cooking ( 'as_items' ); | |||||||||||
| 56 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | # -- Collection: retrieving the whole collection | ||||||||||||
| 62 | |||||||||||||
| 63 | # event: coll.all_songs() | ||||||||||||
| 64 | # FIXME? | ||||||||||||
| 65 | |||||||||||||
| 66 | |||||||||||||
| 67 | sub _do_all_albums { | ||||||||||||
| 68 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_all_albums: not called CC=1 SCAR=6.9
| |||||||||||||
| 69 | |||||||||||||
| 70 | 0 | $msg->_set_commands ( [ 'list album' ] ); | |||||||||||
| 71 | 0 | $msg->_set_cooking ( 'strip_first' ); | |||||||||||
| 72 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | |||||||||||||
| 76 | |||||||||||||
| 77 | sub _do_all_artists { | ||||||||||||
| 78 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_all_artists: not called CC=1 SCAR=6.9
| |||||||||||||
| 79 | |||||||||||||
| 80 | 0 | $msg->_set_commands ( [ 'list artist' ] ); | |||||||||||
| 81 | 0 | $msg->_set_cooking ( 'strip_first' ); | |||||||||||
| 82 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | |||||||||||||
| 86 | |||||||||||||
| 87 | sub _do_all_titles { | ||||||||||||
| 88 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_all_titles: not called CC=1 SCAR=6.9
| |||||||||||||
| 89 | |||||||||||||
| 90 | 0 | $msg->_set_commands ( [ 'list title' ] ); | |||||||||||
| 91 | 0 | $msg->_set_cooking ( 'strip_first' ); | |||||||||||
| 92 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 93 | } | ||||||||||||
| 94 | |||||||||||||
| 95 | |||||||||||||
| 96 | |||||||||||||
| 97 | sub _do_all_files { | ||||||||||||
| 98 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_all_files: not called CC=1 SCAR=6.9
| |||||||||||||
| 99 | |||||||||||||
| 100 | 0 | $msg->_set_commands ( [ 'list filename' ] ); | |||||||||||
| 101 | 0 | $msg->_set_cooking ( 'strip_first' ); | |||||||||||
| 102 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | |||||||||||||
| 106 | # -- Collection: picking songs | ||||||||||||
| 107 | |||||||||||||
| 108 | |||||||||||||
| 109 | sub _do_song { | ||||||||||||
| 110 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_song: not called CC=1 SCAR=6.9
| |||||||||||||
| 111 | 0 | my $what = $msg->params->[0]; | |||||||||||
| 112 | |||||||||||||
| 113 | 0 | $msg->_set_commands ( [ qq{find filename "$what"} ] ); | |||||||||||
| 114 | 0 | $msg->_set_cooking ( 'as_items' ); | |||||||||||
| 115 | 0 | $msg->_set_transform( 'as_scalar' ); | |||||||||||
| 116 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 117 | } | ||||||||||||
| 118 | |||||||||||||
| 119 | |||||||||||||
| 120 | |||||||||||||
| 121 | sub _do_songs_with_filename_partial { | ||||||||||||
| 122 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_songs_with_filename_partial: not called CC=1 SCAR=6.9
| |||||||||||||
| 123 | 0 | my $what = $msg->params->[0]; | |||||||||||
| 124 | |||||||||||||
| 125 | 0 | $msg->_set_commands ( [ qq{search filename "$what"} ] ); | |||||||||||
| 126 | 0 | $msg->_set_cooking ( 'as_items' ); | |||||||||||
| 127 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 128 | } | ||||||||||||
| 129 | |||||||||||||
| 130 | |||||||||||||
| 131 | # -- Collection: songs, albums & artists relations | ||||||||||||
| 132 | |||||||||||||
| 133 | |||||||||||||
| 134 | sub _do_albums_by_artist { | ||||||||||||
| 135 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_albums_by_artist: not called CC=1 SCAR=6.9
| |||||||||||||
| 136 | 0 | my $what = $msg->params->[0]; | |||||||||||
| 137 | |||||||||||||
| 138 | 0 | $msg->_set_commands ( [ qq{list album "$what"} ] ); | |||||||||||
| 139 | 0 | $msg->_set_cooking ( 'strip_first' ); | |||||||||||
| 140 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 141 | } | ||||||||||||
| 142 | |||||||||||||
| 143 | |||||||||||||
| 144 | |||||||||||||
| 145 | sub _do_songs_by_artist { | ||||||||||||
| 146 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_songs_by_artist: not called CC=1 SCAR=6.9
| |||||||||||||
| 147 | 0 | my $what = $msg->params->[0]; | |||||||||||
| 148 | |||||||||||||
| 149 | 0 | $msg->_set_commands ( [ qq{find artist "$what"} ] ); | |||||||||||
| 150 | 0 | $msg->_set_cooking ( 'as_items' ); | |||||||||||
| 151 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 152 | } | ||||||||||||
| 153 | |||||||||||||
| 154 | |||||||||||||
| 155 | |||||||||||||
| 156 | sub _do_songs_by_artist_partial { | ||||||||||||
| 157 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_songs_by_artist_partial: not called CC=1 SCAR=6.9
| |||||||||||||
| 158 | 0 | my $what = $msg->params->[0]; | |||||||||||
| 159 | |||||||||||||
| 160 | 0 | $msg->_set_commands ( [ qq{search artist "$what"} ] ); | |||||||||||
| 161 | 0 | $msg->_set_cooking ( 'as_items' ); | |||||||||||
| 162 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 163 | } | ||||||||||||
| 164 | |||||||||||||
| 165 | |||||||||||||
| 166 | |||||||||||||
| 167 | sub _do_songs_from_album { | ||||||||||||
| 168 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_songs_from_album: not called CC=1 SCAR=6.9
| |||||||||||||
| 169 | 0 | my $what = $msg->params->[0]; | |||||||||||
| 170 | |||||||||||||
| 171 | 0 | $msg->_set_commands ( [ qq{find album "$what"} ] ); | |||||||||||
| 172 | 0 | $msg->_set_cooking ( 'as_items' ); | |||||||||||
| 173 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 174 | } | ||||||||||||
| 175 | |||||||||||||
| 176 | |||||||||||||
| 177 | |||||||||||||
| 178 | sub _do_songs_from_album_partial { | ||||||||||||
| 179 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_songs_from_album_partial: not called CC=1 SCAR=6.9
| |||||||||||||
| 180 | 0 | my $what = $msg->params->[0]; | |||||||||||
| 181 | |||||||||||||
| 182 | 0 | $msg->_set_commands ( [ qq{search album "$what"} ] ); | |||||||||||
| 183 | 0 | $msg->_set_cooking ( 'as_items' ); | |||||||||||
| 184 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 185 | } | ||||||||||||
| 186 | |||||||||||||
| 187 | |||||||||||||
| 188 | |||||||||||||
| 189 | sub _do_songs_with_title { | ||||||||||||
| 190 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_songs_with_title: not called CC=1 SCAR=6.9
| |||||||||||||
| 191 | 0 | my $what = $msg->params->[0]; | |||||||||||
| 192 | |||||||||||||
| 193 | 0 | $msg->_set_commands ( [ qq{find title "$what"} ] ); | |||||||||||
| 194 | 0 | $msg->_set_cooking ( 'as_items' ); | |||||||||||
| 195 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 196 | } | ||||||||||||
| 197 | |||||||||||||
| 198 | |||||||||||||
| 199 | |||||||||||||
| 200 | sub _do_songs_with_title_partial { | ||||||||||||
| 201 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||
|
Subroutine
_do_songs_with_title_partial: not called CC=1 SCAR=6.9
| |||||||||||||
| 202 | 0 | my $what = $msg->params->[0]; | |||||||||||
| 203 | |||||||||||||
| 204 | 0 | $msg->_set_commands ( [ qq{search title "$what"} ] ); | |||||||||||
| 205 | 0 | $msg->_set_cooking ( 'as_items' ); | |||||||||||
| 206 | 0 | $self->mpd->_send_to_mpd( $msg ); | |||||||||||
| 207 | } | ||||||||||||
| 208 | |||||||||||||
| 209 | |||||||||||||
| 210 | 16 | ▶ | no Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 211 | 16 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 212 | 16 | 1; | |||||||||||
| 213 | |||||||||||||
| 214 | __END__ | ||||||||||||
| 215 | |||||||||||||
| 216 | =pod | ||||||||||||
| 217 | |||||||||||||
| 218 | =head1 NAME | ||||||||||||
| 219 | |||||||||||||
| 220 | POE::Component::Client::MPD::Collection - module handling collection commands | ||||||||||||
| 221 | |||||||||||||
| 222 | =head1 VERSION | ||||||||||||
| 223 | |||||||||||||
| 224 | version 2.000 | ||||||||||||
| 225 | |||||||||||||
| 226 | =head1 DESCRIPTION | ||||||||||||
| 227 | |||||||||||||
| 228 | L<POE::Component::Client::MPD::Collection> is responsible for handling | ||||||||||||
| 229 | general purpose commands. They are in a dedicated module to achieve | ||||||||||||
| 230 | easier code maintenance. | ||||||||||||
| 231 | |||||||||||||
| 232 | To achieve those commands, send the corresponding event to the | ||||||||||||
| 233 | L<POE::Component::Client::MPD> session you created: it will be | ||||||||||||
| 234 | responsible for dispatching the event where it is needed. Under no | ||||||||||||
| 235 | circumstance should you call directly subs or methods from this | ||||||||||||
| 236 | module directly. | ||||||||||||
| 237 | |||||||||||||
| 238 | Read L<POE::Component::Client::MPD>'s pod to learn how to deal with | ||||||||||||
| 239 | answers from those commands. | ||||||||||||
| 240 | |||||||||||||
| 241 | Following is a list of collection-related events accepted by POCOCM. | ||||||||||||
| 242 | |||||||||||||
| 243 | =head1 RETRIEVING SONGS & DIRECTORIES | ||||||||||||
| 244 | |||||||||||||
| 245 | =head2 coll.all_items( [$path] ) | ||||||||||||
| 246 | |||||||||||||
| 247 | Return all L<Audio::MPD::Common::Item>s (both songs & directories) | ||||||||||||
| 248 | currently known by mpd. | ||||||||||||
| 249 | |||||||||||||
| 250 | If C<$path> is supplied (relative to mpd root), restrict the retrieval to | ||||||||||||
| 251 | songs and dirs in this directory. | ||||||||||||
| 252 | |||||||||||||
| 253 | =head2 coll.all_items_simple( [$path] ) | ||||||||||||
| 254 | |||||||||||||
| 255 | Return all L<Audio::MPD::Common::Item>s (both songs & directories) | ||||||||||||
| 256 | currently known by mpd. | ||||||||||||
| 257 | |||||||||||||
| 258 | If C<$path> is supplied (relative to mpd root), restrict the retrieval | ||||||||||||
| 259 | to songs and dirs in this directory. | ||||||||||||
| 260 | |||||||||||||
| 261 | B</!\ Warning>: the L<Audio::MPD::Common::Item::Song> objects will only | ||||||||||||
| 262 | have their attribute file filled. Any other attribute will be empty, so | ||||||||||||
| 263 | don't use this sub for any other thing than a quick scan! | ||||||||||||
| 264 | |||||||||||||
| 265 | =head2 coll.items_in_dir( [$path] ) | ||||||||||||
| 266 | |||||||||||||
| 267 | Return the items in the given C<$path>. If no C<$path> supplied, do it on mpd's | ||||||||||||
| 268 | root directory. | ||||||||||||
| 269 | |||||||||||||
| 270 | Note that this sub does not work recusrively on all directories. | ||||||||||||
| 271 | |||||||||||||
| 272 | =head1 RETRIEVING THE WHOLE COLLECTION | ||||||||||||
| 273 | |||||||||||||
| 274 | =head2 coll.all_albums( ) | ||||||||||||
| 275 | |||||||||||||
| 276 | Return the list of all albums (strings) currently known by mpd. | ||||||||||||
| 277 | |||||||||||||
| 278 | =head2 coll.all_artists( ) | ||||||||||||
| 279 | |||||||||||||
| 280 | Return the list of all artists (strings) currently known by mpd. | ||||||||||||
| 281 | |||||||||||||
| 282 | =head2 coll.all_titles( ) | ||||||||||||
| 283 | |||||||||||||
| 284 | Return the list of all titles (strings) currently known by mpd. | ||||||||||||
| 285 | |||||||||||||
| 286 | =head2 coll.all_files( ) | ||||||||||||
| 287 | |||||||||||||
| 288 | Return a mpd_result event with the list of all filenames (strings) | ||||||||||||
| 289 | currently known by mpd. | ||||||||||||
| 290 | |||||||||||||
| 291 | =head1 PICKING A SONG | ||||||||||||
| 292 | |||||||||||||
| 293 | =head2 coll.song( $path ) | ||||||||||||
| 294 | |||||||||||||
| 295 | Return the L<Audio::MPD::Common::Item::Song> which correspond to | ||||||||||||
| 296 | C<$path>. | ||||||||||||
| 297 | |||||||||||||
| 298 | =head2 coll.songs_with_filename_partial( $string ) | ||||||||||||
| 299 | |||||||||||||
| 300 | Return the L<Audio::MPD::Common::Item::Song>s containing C<$string> in | ||||||||||||
| 301 | their path. | ||||||||||||
| 302 | |||||||||||||
| 303 | =head1 SONGS, ALBUMS & ARTISTS RELATIONS | ||||||||||||
| 304 | |||||||||||||
| 305 | =head2 coll.albums_by_artist( $artist ) | ||||||||||||
| 306 | |||||||||||||
| 307 | Return all albums (strings) performed by C<$artist> or where C<$artist> | ||||||||||||
| 308 | participated. | ||||||||||||
| 309 | |||||||||||||
| 310 | =head2 coll.songs_by_artist( $artist ) | ||||||||||||
| 311 | |||||||||||||
| 312 | Return all L<Audio::MPD::Common::Item::Song>s performed by C<$artist>. | ||||||||||||
| 313 | |||||||||||||
| 314 | =head2 coll.songs_by_artist_partial( $artist ) | ||||||||||||
| 315 | |||||||||||||
| 316 | Return all L<Audio::MPD::Common::Item::Song>s performed by C<$artist>. | ||||||||||||
| 317 | |||||||||||||
| 318 | =head2 coll.songs_from_album( $album ) | ||||||||||||
| 319 | |||||||||||||
| 320 | Return all L<Audio::MPD::Common::Item::Song>s appearing in C<$album>. | ||||||||||||
| 321 | |||||||||||||
| 322 | =head2 coll.songs_from_album_partial( $string ) | ||||||||||||
| 323 | |||||||||||||
| 324 | Return all L<Audio::MPD::Common::Item::Song>s appearing in album | ||||||||||||
| 325 | containing C<$string>. | ||||||||||||
| 326 | |||||||||||||
| 327 | =head2 coll.songs_with_title( $title ) | ||||||||||||
| 328 | |||||||||||||
| 329 | Return all L<Audio::MPD::Common::Item::Song>s which title is exactly | ||||||||||||
| 330 | C<$title>. | ||||||||||||
| 331 | |||||||||||||
| 332 | =head2 coll.songs_with_title_partial( $string ) | ||||||||||||
| 333 | |||||||||||||
| 334 | Return all L<Audio::MPD::Common::Item::Song>s where C<$string> is part | ||||||||||||
| 335 | of the title. | ||||||||||||
| 336 | |||||||||||||
| 337 | =head1 AUTHOR | ||||||||||||
| 338 | |||||||||||||
| 339 | Jerome Quelin | ||||||||||||
| 340 | |||||||||||||
| 341 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 342 | |||||||||||||
| 343 | This software is copyright (c) 2007 by Jerome Quelin. | ||||||||||||
| 344 | |||||||||||||
| 345 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 346 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 347 | |||||||||||||
| 348 | =cut | ||||||||||||