Audio::MPD::Common::Item::Song - a song object with some audio tags


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

Index


Code Index:

NAME

Top

Audio::MPD::Common::Item::Song - a song object with some audio tags

VERSION

Top

version 1.110550

DESCRIPTION

Top

Audio::MPD::Common::Item::Song is more a placeholder with some attributes. Those attributes are taken from the song tags, so some of them can be empty depending on the file.

The constructor should only be called by Audio::MPD::Common::Item's constructor.

ATTRIBUTES

Top

$song->album;

Album of the song.

$song->artist;

Artist of the song.

$song->date;

Last modification date of the song.

$song->disc;

Disc number of the album. This is a string to allow tags such as 1/2.

$song->file;

Path to the song. Only attribute which will always be defined.

$song->genre;

Genre of the song.

$song->id;

Id of the song in MPD's database.

$song->name;

Name of the song (for http streams).

$song->pos;

Position of the song in the playlist.

$song->title;

Title of the song.

$song->track;

Track number of the song.

$song->time;

Length of the song in seconds.

METHODS

Top

my $str = $song->as_string;

Return a string representing $song. This string will be:

either "album = track = artist = title"
or "artist = title"
or "title"
or "file"

(in this order), depending on the existing tags of the song. The last possibility always exist of course, since it's a path.

This method is also used to automatically stringify the $song.

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::Song;
BEGIN {
  $Audio::MPD::Common::Item::Song::VERSION = '1.110550';
}
# ABSTRACT: a song object with some audio tags

use Moose;
use MooseX::Has::Sugar;
use MooseX::Types::Moose qw{ Int Str };
use Readonly;

use base qw{ Audio::MPD::Common::Item };
use overload '""' => \&as_string;

Readonly my $SEP => ' = ';


# -- public attributes


has album  => ( rw, isa=>Str );
has artist => ( rw, isa=>Str );
has date   => ( rw, isa=>Str );
has disc   => ( rw, isa=>Str );
has file   => ( rw, isa=>Str, required );
has genre  => ( rw, isa=>Str );
has id     => ( rw, isa=>Int );
has name   => ( rw, isa=>Str );
has pos    => ( rw, isa=>Int );
has title  => ( rw, isa=>Str );
has track  => ( rw, isa=>Str );
has time   => ( rw, isa=>Int );


# -- public methods


sub as_string {
    my ($self) = @_;

    return $self->file unless defined $self->title;
    my $str = $self->title;
    return $str unless defined $self->artist;
    $str = $self->artist . $SEP . $str;
    return $str unless defined $self->album && defined $self->track;
    return join $SEP,
        $self->album,
        $self->track,
        $str;
}

1;



__END__