AnyEvent-Net-MPD

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


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](https://metacpan.org/pod/Net::Async::MPD). If you want an async interface
to MPD, please consider using that distribution instead.

# ATTRIBUTES

- **host**

    The host to connect to. Defaults to **localhost**.

- **port**

    The port to connect to. Defaults to **6600**.

- **password**

    The password to use to connect to the server. Defaults to undefined, which
    means to use no password.

- **auto\_connect**

    If set to true, the constructor will block until the connection to the MPD
    server has been established. Defaults to false.

# METHODS

- **connect**

    If the client is not connected, wait until it is. Otherwise, do nothing.
    Returns the client itself;

- **send** $cmd
- **send** $cmd => @args
- **send** \[ $cmd1 $cmd2 $cmd3 \]

    Send a command to the server in a non-blocking way. This command always returns
    an [AnyEvent](https://metacpan.org/pod/AnyEvent) condvar.

    If called with a single string, then that string will be sent as the command.

    If called with a list, the list will be joined with spaces and sent as the
    command.

    If called with an array reference, then the value of each of item in that array
    will be processed as above (with array references instead of plain lists). If
    the referenced array contains more than one command, then these will be sent to
    the server as a command list.

    An optional subroutine reference passed as the last argument will be passed to
    the condvar constructor, and fire when the condvar is ready (= when there is a
    response from the server).

    The response from the server will be parsed with a command-specific parser, to
    provide some structure to the flat lists returned by MPD. If no parser is
    found, or if the user specifically asks for no parser to be used (see below),
    then the response will be an array reference with the raw lines from the server.

    Finally, a hash reference with additional options can be passed as the _first_
    argument. Valid keys to use are:

    - **parser**

        Specify the parser to use for the response. Parser labels are MPD commands. If
        the requested parser is not found, the fallback `none` will be used.

        Alternatively, if the value itself is a code reference, then that will be
        called with a reference to the raw list of lines as its only argument.

    For ease of use, underscores in the final command name will be removed before
    sending to the server (unless the command name requires them).

- **get**

    Send a command in a blocking way. Internally calls **send** and immediately
    waits for the response.

- **idle**



( run in 0.889 second using v1.01-cache-2.11-cpan-39bf76dae61 )