Audio::MPD::Common::Item - a generic collection item


Audio-MPD-Common documentation Contained in the Audio-MPD-Common distribution.

Index


Code Index:

NAME

Top

Audio::MPD::Common::Item - a generic collection item

VERSION

Top

version 1.110550

SYNOPSIS

Top

    my $item = Audio::MPD::Common::Item->new( %params );

DESCRIPTION

Top

Audio::MPD::Common::Item is a virtual class representing a generic item of mpd's collection. It can be either a song, a directory or a playlist.

Depending on the params given to new, it will create and return an Audio::MPD::Common::Item::Song, an Audio::MPD::Common::Item::Directory or an Audio::MPD::Common::Playlist object. Currently, the discrimination is done on the existence of the file key of %params.

METHODS

Top

my $item = Audio::MPD::Common::Item->new( %params );

Create and return either an Audio::MPD::Common::Item::Song, an Audio::MPD::Common::Item::Directory or an Audio::MPD::Common::Playlist object, depending on the existence of a key file, directory or playlist (respectively).

AUTHOR

Top

  Jerome Quelin

COPYRIGHT AND LICENSE

Top


Audio-MPD-Common documentation Contained in the Audio-MPD-Common distribution.

#
# This file is part of Audio-MPD-Common
#
# 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 strict;
use warnings;

package Audio::MPD::Common::Item;
BEGIN {
  $Audio::MPD::Common::Item::VERSION = '1.110550';
}
# ABSTRACT: a generic collection item

use Audio::MPD::Common::Item::Directory;
use Audio::MPD::Common::Item::Playlist;
use Audio::MPD::Common::Item::Song;


# -- constructor


sub new {
    my ($pkg, %params) = @_;

    # transform keys in lowercase, remove dashes "-"
    my %lowcase;
    @lowcase{ map { s/-/_/; lc } keys %params } = values %params;

    return Audio::MPD::Common::Item::Song->new(\%lowcase)      if exists $params{file};
    return Audio::MPD::Common::Item::Directory->new(\%lowcase) if exists $params{directory};
    return Audio::MPD::Common::Item::Playlist->new(\%lowcase)  if exists $params{playlist};
}

1;



__END__