+ );
+
+ warn "here";
+ }
+
+ method prepare_to_wait_idle {
+ $log->trace('declaring idle mode');
+ $mpd->send('idle database playlist')->on_done(
+ sub {
+ warn $_ for @_;
+ my $result = shift;
+ use JSON; warn to_json($result);
+
+ if ( $result->{changed} eq 'database' ) {
+ $self->update_db;
+ $self->prepare_to_wait_idle;
+ }
+ elsif ( $result->{changed} eq 'playlist' ) {
+ $self->queue_songs( undef,
+ sub { $self->prepare_to_wait_idle } );
+ }
+ else {
+ use JSON;
+ $log->warn(
+ "Unknown result from idle: " . to_json($result) );
+ $self->prepare_to_wait_idle;
+ }
+ }
+ );
+ }
+
+ method run {
+ $mpd->on(
+ close => sub {
+ die "Connection to MPD lost";
+ }
+ );
+
+ $self->prepare_to_wait_idle;