From c5c06d73fd14f47a2e741f2adc2f1bdf38086b51 Mon Sep 17 00:00:00 2001 From: jq Date: Mon, 2 Apr 2007 15:47:43 +0000 Subject: [PATCH] [project @ 5805] using _cooked_command_strip_first_field() to factorize code - and achieving better code coverage (100% reached for am::collection!) --- lib/Audio/MPD.pm | 5 +---- lib/Audio/MPD/Collection.pm | 22 ++++++---------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/lib/Audio/MPD.pm b/lib/Audio/MPD.pm index 3f1db39..21d7cce 100644 --- a/lib/Audio/MPD.pm +++ b/lib/Audio/MPD.pm @@ -260,10 +260,7 @@ sub updatedb { # sub urlhandlers { my ($self) = @_; - my @handlers = - map { /^handler: (.+)$/ ? $1 : () } - $self->_send_command("urlhandlers\n"); - return @handlers; + return $self->_cooked_command_strip_first_field("urlhandlers\n"); } diff --git a/lib/Audio/MPD/Collection.pm b/lib/Audio/MPD/Collection.pm index 596dd1d..45bbcb4 100644 --- a/lib/Audio/MPD/Collection.pm +++ b/lib/Audio/MPD/Collection.pm @@ -27,7 +27,7 @@ use base qw[ Class::Accessor::Fast ]; __PACKAGE__->mk_accessors( qw[ _mpd ] ); -#our ($VERSION) = '$Rev: 5802 $' =~ /(\d+)/; +#our ($VERSION) = '$Rev: 5805 $' =~ /(\d+)/; #-- @@ -123,9 +123,7 @@ sub items_in_dir { # sub all_albums { my ($self) = @_; - return - map { /^Album: (.+)$/ ? $1 : () } - $self->_mpd->_send_command( "list album\n" ); + return $self->_mpd->_cooked_command_strip_first_field( "list album\n" ); } @@ -136,9 +134,7 @@ sub all_albums { # sub all_artists { my ($self) = @_; - return - map { /^Artist: (.+)$/ ? $1 : () } - $self->_mpd->_send_command( "list artist\n" ); + return $self->_mpd->_cooked_command_strip_first_field( "list artist\n" ); } @@ -149,9 +145,7 @@ sub all_artists { # sub all_titles { my ($self) = @_; - return - map { /^Title: (.+)$/ ? $1 : () } - $self->_mpd->_send_command( "list title\n" ); + return $self->_mpd->_cooked_command_strip_first_field( "list title\n" ); } @@ -162,9 +156,7 @@ sub all_titles { # sub all_pathes { my ($self) = @_; - return - map { /^file: (.+)$/ ? $1 : () } - $self->_mpd->_send_command( "list filename\n" ); + return $self->_mpd->_cooked_command_strip_first_field( "list filename\n" ); } @@ -205,9 +197,7 @@ sub songs_with_filename_partial { # sub albums_by_artist { my ($self, $artist) = @_; - return - map { /^Album: (.+)$/ ? $1 : () } - $self->_mpd->_send_command( qq[list album "$artist"\n] ); + return $self->_mpd->_cooked_command_strip_first_field( qq[list album "$artist"\n] ); } -- 2.11.4.GIT