NAME

AnyEvent::Net::MPD - A non-blocking interface to MPD

SYNOPSIS

use AnyEvent::Net::MPD;

my $mpd = AnyEvent::Net::MPD->new( host => $ARGV[0] )->connect;

my @subsystems = qw( player mixer database );

# Register a listener
foreach my $subsystem (@subsystems) {
  $mpd->on( $subsystem => sub {
    my ($self) = @_;
    print "$subsystem has changed\n";

    # Stop listening if mixer changes
    $mpd->noidle if $subsystem eq 'mixer';
  });
}

# Send a command
my $stats = $mpd->send( 'stats' );

# Or in blocking mode
my $status = $mpd->send( 'status' )->recv;

# Which is the same as
$status = $mpd->get( 'status' );

print "Server is ", $status->{state}, " state\n";
print "Server has ", $stats->recv->{albums}, " albums in the database\n";

# Put the client in looping idle mode
my $idle = $mpd->idle( @subsystems );

# Set the emitter in motion, until the next call to noidle
$idle->recv;

DESCRIPTION

AnyEvent::Net::MPD provides a non-blocking interface to an MPD server.

NOTE

Although in what is mostly a usable state, AnyEvent::Net::MPD is currently DEPRECATED, in favour of Net::Async::MPD. If you want an async interface to MPD, please consider using that distribution instead.

ATTRIBUTES

METHODS

EVENTS

After calling idle, the client will be in idle mode, which means that any changes to the specified subsystemswill trigger a signal. When the client receives this signal, it will fire an event named as the subsystem that fired it.

The event will be fired with the client as the first argument, and the response from the server as the second argument. This can safely be ignored, since the server response will normally just hold the name of the subsystem that changed, which you already know.

Event descriptions

SEE ALSO

AUTHOR

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by José Joaquín Atria.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.