/usr/share/perl5/POE/Component/Client/MPD/Commands.pm is in libpoe-component-client-mpd-perl 2.000-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | #
# This file is part of POE-Component-Client-MPD
#
# This software is copyright (c) 2007 by Jerome Quelin.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use 5.010;
use strict;
use warnings;
package POE::Component::Client::MPD::Commands;
# ABSTRACT: module handling basic mpd commands
$POE::Component::Client::MPD::Commands::VERSION = '2.000';
use Moose;
use MooseX::Has::Sugar;
use POE;
use Readonly;
use POE::Component::Client::MPD::Message;
Readonly my $K => $poe_kernel;
# -- attributes
has mpd => ( ro, required, weak_ref, );# isa=>'POE::Component::Client::MPD' );
# -- MPD interaction: general commands
sub _do_version {
my ($self, $msg) = @_;
$msg->set_status(1);
$K->post( $msg->_from, 'mpd_result', $msg, $self->mpd->version );
}
sub _do_password {
my ($self, $msg) = @_;
my $pw = $msg->params->[0];
$msg->_set_commands( [ qq{password $pw} ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_kill {
my ($self, $msg) = @_;
$msg->_set_commands ( [ 'kill' ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
$K->delay_set('disconnect'=>1);
}
sub _do_updatedb {
my ($self, $msg) = @_;
my $path = $msg->params->[0] // ''; # FIXME: padre//
$msg->_set_commands( [ qq{update "$path"} ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_urlhandlers {
my ($self, $msg) = @_;
$msg->_set_commands ( [ 'urlhandlers' ] );
$msg->_set_cooking ( 'strip_first' );
$self->mpd->_send_to_mpd( $msg );
}
# -- MPD interaction: handling volume & output
sub _do_volume {
my ($self, $msg) = @_;
my $volume;
if ( $msg->params->[0] =~ /^(-|\+)(\d+)/ ) {
my ($op, $delta) = ($1, $2);
if ( not defined $msg->_data ) {
# no status yet - fire an event
$msg->_set_post( 'volume' );
$self->mpd->_dispatch('status', $msg);
return;
}
# already got a status result
my $curvol = $msg->_data->volume;
$volume = $op eq '+' ? $curvol + $delta : $curvol - $delta;
} else {
$volume = $msg->params->[0];
}
$msg->_set_commands ( [ "setvol $volume" ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_output_enable {
my ($self, $msg) = @_;
my $output = $msg->params->[0];
$msg->_set_commands ( [ "enableoutput $output" ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_output_disable {
my ($self, $msg) = @_;
my $output = $msg->params->[0];
$msg->_set_commands ( [ "disableoutput $output" ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
# -- MPD interaction: retrieving info from current state
sub _do_stats {
my ($self, $msg) = @_;
$msg->_set_commands ( [ 'stats' ] );
$msg->_set_cooking ( 'as_kv' );
$msg->_set_transform( 'as_stats' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_status {
my ($self, $msg) = @_;
$msg->_set_commands ( [ 'status' ] );
$msg->_set_cooking ( 'as_kv' );
$msg->_set_transform( 'as_status' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_current {
my ($self, $msg) = @_;
$msg->_set_commands ( [ 'currentsong' ] );
$msg->_set_cooking ( 'as_items' );
$msg->_set_transform( 'as_scalar' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_song {
my ($self, $msg) = @_;
my $song = $msg->params->[0];
$msg->_set_commands ( [ defined $song ? "playlistinfo $song" : 'currentsong' ] );
$msg->_set_cooking ( 'as_items' );
$msg->_set_transform( 'as_scalar' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_songid {
my ($self, $msg) = @_;
my $song = $msg->params->[0];
$msg->_set_commands ( [ defined $song ? "playlistid $song" : 'currentsong' ] );
$msg->_set_cooking ( 'as_items' );
$msg->_set_transform( 'as_scalar' );
$self->mpd->_send_to_mpd( $msg );
}
# -- MPD interaction: altering settings
sub _do_repeat {
my ($self, $msg) = @_;
my $mode = $msg->params->[0];
if ( defined $mode ) {
$mode = $mode ? 1 : 0; # force integer
} else {
if ( not defined $msg->_data ) {
# no status yet - fire an event
$msg->_set_post( 'repeat' );
$self->mpd->_dispatch('status', $msg);
return;
}
$mode = $msg->_data->repeat ? 0 : 1; # negate current value
}
$msg->_set_cooking ( 'raw' );
$msg->_set_commands( [ "repeat $mode" ] );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_fade {
my ($self, $msg) = @_;
my $seconds = $msg->params->[0] // 0; # FIXME: padre//
$msg->_set_commands ( [ "crossfade $seconds" ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_random {
my ($self, $msg) = @_;
my $mode = $msg->params->[0];
if ( defined $mode ) {
$mode = $mode ? 1 : 0; # force integer
} else {
if ( not defined $msg->_data ) {
# no status yet - fire an event
$msg->_set_post( 'random' );
$self->mpd->_dispatch('status', $msg);
return;
}
$mode = $msg->_data->random ? 0 : 1; # negate current value
}
$msg->_set_cooking ( 'raw' );
$msg->_set_commands( [ "random $mode" ] );
$self->mpd->_send_to_mpd( $msg );
}
# -- MPD interaction: controlling playback
sub _do_play {
my ($self, $msg) = @_;
my $number = $msg->params->[0] // ''; # FIXME: padre//
$msg->_set_commands ( [ "play $number" ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_playid {
my ($self, $msg) = @_;
my $number = $msg->params->[0] // ''; # FIXME: padre//
$msg->_set_commands ( [ "playid $number" ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_pause {
my ($self, $msg) = @_;
my $state = $msg->params->[0] // ''; # FIXME: padre//
$msg->_set_commands ( [ "pause $state" ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_stop {
my ($self, $msg) = @_;
$msg->_set_commands ( [ 'stop' ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_next {
my ($self, $msg) = @_;
$msg->_set_commands ( [ 'next' ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_prev {
my ($self, $msg) = @_;
$msg->_set_commands ( [ 'previous' ] );
$msg->_set_cooking ( 'raw' );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_seek {
my ($self, $msg) = @_;
my ($time, $song) = @{ $msg->params }[0,1];
$time ||= 0; $time = int $time;
if ( not defined $song ) {
if ( not defined $msg->_data ) {
# no status yet - fire an event
$msg->_set_post( 'seek' );
$self->mpd->_dispatch('status', $msg);
return;
}
$song = $msg->_data->song;
}
$msg->_set_cooking ( 'raw' );
$msg->_set_commands( [ "seek $song $time" ] );
$self->mpd->_send_to_mpd( $msg );
}
sub _do_seekid {
my ($self, $msg) = @_;
my ($time, $songid) = @{ $msg->params }[0,1];
$time ||= 0; $time = int $time;
if ( not defined $songid ) {
if ( not defined $msg->_data ) {
# no status yet - fire an event
$msg->_set_post( 'seekid' );
$self->mpd->_dispatch('status', $msg);
return;
}
$songid = $msg->_data->songid;
}
$msg->_set_cooking ( 'raw' );
$msg->_set_commands( [ "seekid $songid $time" ] );
$self->mpd->_send_to_mpd( $msg );
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
__END__
=pod
=head1 NAME
POE::Component::Client::MPD::Commands - module handling basic mpd commands
=head1 VERSION
version 2.000
=head1 DESCRIPTION
L<POE::Component::Client::MPD::Commands> is responsible for handling
general purpose commands. They are in a dedicated module to achieve
easier code maintenance.
To achieve those commands, send the corresponding event to the POCOCM
session you created: it will be responsible for dispatching the event
where it is needed. Under no circumstance should you call directly subs
or methods from this module directly.
Read POCOCM's pod to learn how to deal with answers from those commands.
Following is a list of general purpose events accepted by POCOCM.
=head1 CONTROLLING THE SERVER
=head2 version( )
Return mpd's version number as advertised during connection. Note that
mpd returns B<protocol> version when connected. This protocol version can
differ from the real mpd version. eg, mpd version 0.13.2 is "speaking"
and thus advertising version 0.13.0.
=head2 password( $password )
Sends a connection password to mpd. Used internally on connect, but can
be called whenever if you're feeling like it.
=head2 kill( )
Kill the mpd server, and request the pococm to be shutdown.
=head2 updatedb( [$path] )
Force mpd to rescan its collection. If C<$path> (relative to MPD's music
directory) is supplied, MPD will only scan it - otherwise, MPD will
rescan its whole collection.
=head2 urlhandlers( )
Return an array of supported URL schemes.
=head1 HANDLING VOLUME & OUTPUT
=head2 volume( $volume )
Sets the audio output volume percentage to absolute C<$volume>. If
C<$volume> is prefixed by '+' or '-' then the volume is changed
relatively by that value.
=head2 output_enable( $output )
Enable the specified audio output. C<$output> is the ID of the audio
output.
=head2 output_disable( $output )
Disable the specified audio output. C<$output> is the ID of the audio output.
=head1 RETRIEVING INFO FROM CURRENT STATE
=head2 stats( )
Return an L<Audio::MPD::Common::Stats> object with the current
statistics of MPD.
=head2 status( )
Return an L<Audio::MPD::Common::Status> object with the current
status of MPD.
=head2 current( )
Return an L<Audio::MPD::Common::Item::Song> representing the song
currently playing.
=head2 song( [$song] )
Return an L<Audio::MPD::Common::Item::Song> representing the song number
C<$song>. If C<$song> is not supplied, returns the current song.
=head2 songid( [$songid] )
Return an L<Audio::MPD::Common::Item::Song> representing the song id
C<$songid>. If C<$songid> is not supplied, returns the current song.
=head1 ALTERING MPD SETTINGS
=head2 repeat( [$repeat] )
Set the repeat mode to C<$repeat> (1 or 0). If C<$repeat> is not
specified then the repeat mode is toggled.
=head2 fade( [$seconds] )
Enable crossfading and set the duration of crossfade between songs. If
C<$seconds> is not specified or C<$seconds> is 0, then crossfading is
disabled.
=head2 random( [$random] )
Set the random mode to C<$random> (1 or 0). If C<$random> is not
specified then the random mode is toggled.
=head1 CONTROLLING PLAYBACK
=head2 play( [$song] )
Begin playing playlist at song number C<$song>. If no argument supplied,
resume playing.
=head2 playid( [$song] )
Begin playing playlist at song ID C<$song>. If no argument supplied,
resume playing.
=head2 pause( [$sate] )
Pause playback. If C<$state> is 0 then the current track is unpaused, if
C<$state> is 1 then the current track is paused.
Note that if C<$state> is not given, pause state will be toggled.
=head2 stop( )
Stop playback.
=head2 next( )
Play next song in playlist.
=head2 prev( )
Play previous song in playlist.
=head2 seek( $time, [$song] )
Seek to C<$time> seconds in song number C<$song>. If C<$song> number is
not specified then the perl module will try and seek to C<$time> in the
current song.
=head2 seekid( $time, [$songid] )
Seek to C<$time> seconds in song ID C<$songid>. If C<$songid> number is
not specified then the perl module will try and seek to C<$time> in the
current song.
=head1 AUTHOR
Jerome Quelin
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2007 by Jerome Quelin.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|