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