[project @ 6332]
[audio-mpd-common.git] / lib / POE / Component / Client / MPD / Item / Song.pm
blob03c229c7e8fe7eec469028e9f210244c85a9deae
2 # This file is part of POE::Component::Client::MPD.
3 # Copyright (c) 2007 Jerome Quelin, all rights reserved.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the same terms as Perl itself.
10 package POE::Component::Client::MPD::Item::Song;
12 use strict;
13 use warnings;
15 use overload '""' => \&as_string;
16 use Readonly;
18 use base qw[ Class::Accessor::Fast POE::Component::Client::MPD::Item ];
19 __PACKAGE__->mk_accessors( qw[ album artist file id pos title track time ] );
21 #our ($VERSION) = '$Rev: 5645 $' =~ /(\d+)/;
23 Readonly my $SEP => ' = ';
27 # my $str = $song->as_string;
29 # Return a string representing $song. This string will be;
30 # - either "album = track = artist = title"
31 # - or "artist = title"
32 # - or "title"
33 # - or "file"
34 # (in this order), depending on the existing tags of the song. The last
35 # possibility always exist of course, since it's a path.
37 sub as_string {
38 my ($self) = @_;
40 return $self->file unless defined $self->title;
41 my $str = $self->title;
42 return $str unless defined $self->artist;
43 $str = $self->artist . $SEP . $str;
44 return $str unless defined $self->album && defined $self->track;
45 return join $SEP,
46 $self->album,
47 $self->track,
48 $str;
53 __END__
55 =head1 NAME
57 POE::Component::Client::MPD::Item::Song - a song object with some audio tags
60 =head1 DESCRIPTION
62 C<POE::Component::Client::MPD::Item::Song> is more a placeholder for a
63 hash ref with some pre-defined keys, namely some audio tags.
66 =head1 PUBLIC METHODS
68 =head2 Accessors
70 The following methods are the accessors to their respective named fields:
71 C<album()>, C<artist()>, C<file()>, C<id>, C<pos>, C<title()>, C<track()>,
72 C<time()>. You can call them either with no arg to get the value, or with
73 an arg to replace the current value.
76 =head2 Methods
79 =over 4
81 =item $song->as_string()
83 Return a string representing $song. This string will be:
85 =over 4
87 =item either "album = track = artist = title"
89 =item or "artist = title"
91 =item or "title"
93 =item or "file"
95 =back
97 (in this order), depending on the existing tags of the song. The last
98 possibility always exist of course, since it's a path.
100 =back
103 =head1 SEE ALSO
105 For all related information (bug reporting, mailing-list, pointers to
106 MPD and POE, etc.), refer to C<POE::Component::Client::MPD>'s pod,
107 section C<SEE ALSO>
110 =head1 AUTHOR
112 Jerome Quelin, C<< <jquelin at cpan.org> >>
115 =head1 COPYRIGHT & LICENSE
117 Copyright (c) 2007 Jerome Quelin, all rights reserved.
119 This program is free software; you can redistribute it and/or modify
120 it under the same terms as Perl itself.
122 =cut