Audio-MPD
view release on metacpan or search on metacpan
lib/Audio/MPD/Playlist.pm view on Meta::CPAN
#
# This file is part of Audio-MPD
#
# This software is copyright (c) 2007 by Jerome Quelin.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use 5.008;
use warnings;
use strict;
package Audio::MPD::Playlist;
# ABSTRACT: class to mess MPD's playlist
$Audio::MPD::Playlist::VERSION = '2.004';
use Moose;
use MooseX::Has::Sugar;
use MooseX::SemiAffordanceAccessor;
has _mpd => ( ro, required, weak_ref );
#--
# Constructor
#
# my $collection = Audio::MPD::Playlist->new( _mpd => $mpd );
#
# This will create the object, holding a back-reference to the Audio::MPD
# object itself (for communication purposes). But in order to play safe and
# to free the memory in time, this reference is weakened.
#
# Note that you're not supposed to call this constructor yourself, an
# Audio::MPD::Playlist is automatically created for you during the creation
# of an Audio::MPD object.
#
#--
# Public methods
# -- Playlist: retrieving information
sub as_items {
my ($self) = @_;
my @list = $self->_mpd->_cooked_command_as_items("playlistinfo\n");
return @list;
}
sub items_changed_since {
my ($self, $plid) = @_;
return $self->_mpd->_cooked_command_as_items("plchanges $plid\n");
}
# -- Playlist: adding / removing songs
sub add {
my ($self, @pathes) = @_;
my $command =
"command_list_begin\n"
. join( '', map { my $p=$_; $p=~s/"/\\"/g; qq[add "$p"\n] } @pathes )
. "command_list_end\n";
$self->_mpd->_send_command( $command );
}
sub delete {
my ($self, @songs) = @_;
my $command =
"command_list_begin\n"
. join( '', map { my $p=$_; $p=~s/"/\\"/g; "delete $p\n" } @songs )
. "command_list_end\n";
$self->_mpd->_send_command( $command );
}
sub deleteid {
my ($self, @songs) = @_;
my $command =
"command_list_begin\n"
. join( '', map { "deleteid $_\n" } @songs )
. "command_list_end\n";
$self->_mpd->_send_command( $command );
( run in 1.302 second using v1.01-cache-2.11-cpan-5a3173703d6 )