Audio-RPLD
view release on metacpan or search on metacpan
lib/Audio/RPLD.pm view on Meta::CPAN
} elsif ( $k eq 'history' ) {
$v = int($v);
} elsif ( $k eq 'history_size' ) {
$v = int($v);
} elsif ( $k eq 'mixer' ) {
$v = int($v);
$v = undef if $v == -1;
}
$c->{lc($k)} = $v;
}
return $c;
}
# This is very similar to p_playlist(). Maybe they should be merged.
sub p_client {
my ($e, $client) = @_;
my $c;
my ($k, $v);
local $_;
$client =~ /^\s*(\d+):\s*\[([^\]]+)\]\s*"(.+?)"$/ or return undef;
$c = {'id' => int($1), 'name' => $3};
foreach (split(/, /, $2)) {
($k, $v) = /^([^:]+):\s(.+)$/;
$k =~ tr/ /_/;
$k = lc($k);
if ( $k eq 'protocol' || $k eq 'nodename' ) {
$v =~ s/^"(.+)"$/$1/;
} elsif ( $k eq 'pid' || $k eq 'hostid' ) {
$v = int($v);
}
$c->{$k} = $v;
}
return $c;
}
#-------------
# define hi-level functions
# -- Basic:
=pod
=head2 Basic communication functions
=cut
sub noop {
return $_[0]->cmd('NOOP');
}
=pod
=head3 $res = $rpld-E<gt>noop()
Send a NOOP command to the server.
This can be used to ping the server or for keep-alive.
=cut
# -- server info:
=pod
=head2 Server information functions
=cut
sub serverinfo {
my ($e) = @_;
my $res = {'x' => {}};
my $q = $e->cmd_data('SERVERINFO');
local $_;
my $cur;
return undef unless $e->is_ok($q->[0]);
foreach (@{$q}[1..$#{$q}]) {
$cur = $res;
$cur = $cur->{'x'} if s/^X-//i;
if ( /^([A-Z]+)\s+"(.+)"$/ ) {
$cur->{lc $1} = $2;
} elsif ( /^([A-Z]+)\s+([A-Z]+)\s+"(.+)"$/ ) {
$cur->{lc $1} ||= {};
$cur->{lc $1}->{lc $2} = $3;
} elsif ( /^([A-Z]+)\s+([0-9]+)$/ ) {
$cur->{lc $1} = int($2);
} elsif ( /^([A-Z]+)\s+(0x[0-9a-fA-F]+)$/ ) {
$cur->{lc $1} = hex($2);
}
}
return $res;
}
=pod
=head3 $res = $rpld-E<gt>serverinfo()
Send a SERVERINFO command to the server.
This tells basic informations about the server like it's version and location.
The return value is a hashref which contains the following keys (all keys may or may not be set depending on what info the server provides):
=over
=item version
This is the product name, version and vendor information for the server.
=item location
This is the location of the server in a lion readable way e.g. "kitchen".
=item description
( run in 1.677 second using v1.01-cache-2.11-cpan-df04353d9ac )