ADJUST {
Getopt::Long::Configure('pass_through');
- Getopt::Long::GetOptions('cfg|config=s' => \$cfg_file);
+ Getopt::Long::GetOptions( 'cfg|config=s' => \$cfg_file );
Getopt::Long::Configure('no_pass_through');
$cfg_file //= DEFAULT_CONFIG_FILE if -e DEFAULT_CONFIG_FILE;
IO::Async::Signal->new(
name => 'USR1',
on_receipt => sub {
- $log->debug("SIGUSR1 received. Dumping configuration to STDERR");
+ $log->debug(
+ "SIGUSR1 received. Dumping configuration to STDERR");
my $old = select \*STDERR;
try {
$opt->dump;
$self->update_db;
}
-method update_db($force = undef) {
- if (!$db_needs_update and !$force) {
+method update_db( $force = undef ) {
+ if ( !$db_needs_update and !$force ) {
$log->debug("Skipping DB update");
return;
}
}
}
-method queue_songs($num = undef) {
+method queue_songs( $num = undef ) {
$self->connect_db;
- if (!defined $num) {
+ if ( !defined $num ) {
$self->connect_mpd;
$log->trace("Requesting playlist");
my $present = $mpd->send('playlist')->get // [];
$log->notice( "Playlist contains $present songs. Wanted: "
. $opt->target_queue_length );
if ( $present < $opt->target_queue_length ) {
- $self->queue_songs(
- $opt->target_queue_length - $present );
+ $self->queue_songs( $opt->target_queue_length - $present );
}
return;
}
$log->debug( "Adding " . join( ', ', map {"«$_»"} @paths ) );
+
# MPD needs raw bytes
utf8::encode($_) for @paths;
my @commands;
$log->notice("disconnecting and re-starting");
$self->stop;
- my @exec =
- ( $0, '--config', $self->cfg_file, '--skip-db-update' );
+ my @exec = ( $0, '--config', $self->cfg_file, '--skip-db-update' );
if ( $log->is_trace ) {
- $log->trace( 'exec '
- . join( ' ', map { /\s/ ? "'$_'" : $_ } @exec ) );
+ $log->trace(
+ 'exec ' . join( ' ', map { /\s/ ? "'$_'" : $_ } @exec ) );
}
exec(@exec);
}
}
method break_idle {
- if ($idler && !$idler->is_ready) {
+ if ( $idler && !$idler->is_ready ) {
$log->trace("hand-sending 'noidle'");
undef $idler;
- $mpd->{mpd_handle}->write("noidle\n");;
+ $mpd->{mpd_handle}->write("noidle\n");
}
else {
$log->trace("no idler found");
if ( time - $last_mpd_comm > 300 ) {
$log->trace(
- "no active MPD communication for more that 5 minutes"
- );
+ "no active MPD communication for more that 5 minutes");
$log->trace("forcing alive check");
$self->break_idle;
}
else {
- $log->trace("contacted MPD less than 5 minutes ago. skipping alive check");
+ $log->trace(
+ "contacted MPD less than 5 minutes ago. skipping alive check"
+ );
}
},
)->start
for ( ;; ) {
$log->debug("Waiting idle. PID=$$");
$last_mpd_comm = time;
- $idler = $mpd->send("idle database playlist");
+ $idler = $mpd->send("idle database playlist");
my $result = $idler->get;
undef $idler;
- if ($result and $result->{changed}){
+ if ( $result and $result->{changed} ) {
my $changed = $result->{changed};
- $changed = [ $changed ] unless ref $changed;
+ $changed = [$changed] unless ref $changed;
$mpd->emit($_) for @$changed;
}