AnyEvent-Net-MPD
view release on metacpan or search on metacpan
# 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**
lib/AnyEvent/Net/MPD.pm view on Meta::CPAN
default => sub { [] },
handles_via => 'Array',
handles => {
push_read => 'push',
pop_read => 'pop',
shift_read => 'shift',
unshift_read => 'unshift',
},
);
has password => (
is => 'ro',
isa => Maybe[Str],
lazy => 1,
);
has port => (
is => 'ro',
isa => Int,
lazy => 1,
default => sub { $ENV{MPD_PORT} // 6600 },
lib/AnyEvent/Net/MPD.pm view on Meta::CPAN
lazy => 1,
default => sub { $ENV{MPD_HOST} // 'localhost' },
);
has _uri => (
is => 'ro',
init_arg => undef,
lazy => 1,
default => sub {
my $self = shift;
( $self->password ? $self->password . '@' : q{} )
. $self->host
. ( $self->port ? ':' . $self->port : q{} )
},
);
has [qw( handle socket )] => ( is => 'rw', init_arg => undef, );
{
my @buffer;
sub _parse_block {
lib/AnyEvent/Net/MPD.pm view on Meta::CPAN
return sub {
my ($handle, $line) = @_;
if ($line =~ /\w/) {
$log->tracef('< %s', $line);
if ($line =~ /^OK/) {
if ($line =~ /OK MPD (.*)/) {
$log->trace('Connection established');
$self->{version} = $1;
$self->send( password => $self->password )
if $self->password and $self->state ne 'ready';
$self->state( 'ready' );
}
else {
$self->shift_read->( \@buffer );
@buffer = ();
}
}
elsif ($line =~ /^ACK/) {
return $self->emit(error => $line );
lib/AnyEvent/Net/MPD.pm view on Meta::CPAN
=over 4
=item B<host>
The host to connect to. Defaults to B<localhost>.
=item B<port>
The port to connect to. Defaults to B<6600>.
=item B<password>
The password to use to connect to the server. Defaults to undefined, which
means to use no password.
=item B<auto_connect>
If set to true, the constructor will block until the connection to the MPD
server has been established. Defaults to false.
=back
=head1 METHODS
use Test::More;
use Test::Warnings;
use Try::Tiny;
use AnyEvent::Net::MPD;
ok my $mpd = AnyEvent::Net::MPD->new, 'constructor succeeds';
# Attributes
can_ok $mpd, $_ foreach qw( version auto_connect state password host port );
# Methods
can_ok $mpd, $_ foreach qw( send get idle noidle connect );
done_testing();
( run in 0.953 second using v1.01-cache-2.11-cpan-49f99fa48dc )