]>
Commit | Line | Data |
---|---|---|
83d20a45 CS |
1 | # |
2 | # This file is part of Audio::MPD::Common | |
3 | # Copyright (c) 2007 Jerome Quelin, all rights reserved. | |
4 | # | |
5 | # This program is free software; you can redistribute it and/or modify | |
6 | # it under the same terms as Perl itself. | |
7 | # | |
8 | # | |
9 | ||
10 | package Audio::MPD::Common::Item::Song; | |
11 | ||
12 | use strict; | |
13 | use warnings; | |
14 | ||
15 | use overload '""' => \&as_string; | |
16 | use Readonly; | |
17 | ||
18 | use base qw[ Class::Accessor::Fast Audio::MPD::Common::Item ]; | |
19 | __PACKAGE__->mk_accessors( qw[ Album Artist file id pos Title Track time ] ); | |
20 | ||
21 | #our ($VERSION) = '$Rev: 5645 $' =~ /(\d+)/; | |
22 | ||
23 | Readonly my $SEP => ' = '; | |
24 | ||
25 | ||
26 | # | |
27 | # my $str = $song->as_string; | |
28 | # | |
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. | |
36 | # | |
37 | sub as_string { | |
38 | my ($self) = @_; | |
39 | ||
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; | |
49 | } | |
50 | ||
51 | 1; | |
52 | ||
53 | __END__ | |
54 | ||
55 | ||
56 | =head1 NAME | |
57 | ||
58 | Audio::MPD::Common::Item::Song - a song object with some audio tags | |
59 | ||
60 | ||
61 | =head1 DESCRIPTION | |
62 | ||
63 | C<Audio::MPD::Common::Item::Song> is more a placeholder for a | |
64 | hash ref with some pre-defined keys, namely some audio tags. | |
65 | ||
66 | ||
67 | =head1 PUBLIC METHODS | |
68 | ||
69 | This module has a C<new()> constructor, which should only be called by | |
70 | C<Audio::MPD::Common::Item>'s constructor. | |
71 | ||
72 | The only other public methods are the accessors - see below. | |
73 | ||
74 | ||
75 | =head2 Accessors | |
76 | ||
77 | The following methods are the accessors to their respective named fields: | |
78 | C<Album()>, C<Artist()>, C<file()>, C<id>, C<pos>, C<Title()>, CTTrack()>, | |
79 | C<time()>. You can call them either with no arg to get the value, or with | |
80 | an arg to replace the current value. | |
81 | ||
82 | ||
83 | =head2 Methods | |
84 | ||
85 | ||
86 | =over 4 | |
87 | ||
88 | =item $song->as_string() | |
89 | ||
90 | Return a string representing $song. This string will be: | |
91 | ||
92 | =over 4 | |
93 | ||
94 | =item either "Album = Track = Artist = Title" | |
95 | ||
96 | =item or "Artist = Title" | |
97 | ||
98 | =item or "Title" | |
99 | ||
100 | =item or "file" | |
101 | ||
102 | =back | |
103 | ||
104 | (in this order), depending on the existing tags of the song. The last | |
105 | possibility always exist of course, since it's a path. | |
106 | ||
107 | =back | |
108 | ||
109 | ||
110 | =head1 SEE ALSO | |
111 | ||
112 | =over 4 | |
113 | ||
114 | =item L<Audio::MPD> | |
115 | ||
116 | =item L<POE::Component::Client::MPD> | |
117 | ||
118 | =back | |
119 | ||
120 | ||
121 | =head1 AUTHOR | |
122 | ||
123 | Jerome Quelin, C<< <jquelin at cpan.org> >> | |
124 | ||
125 | ||
126 | =head1 COPYRIGHT & LICENSE | |
127 | ||
128 | Copyright (c) 2007 Jerome Quelin, all rights reserved. | |
129 | ||
130 | This program is free software; you can redistribute it and/or modify | |
131 | it under the same terms as Perl itself. | |
132 | ||
133 | =cut |