File Coverage

blib/lib/WebService/Audioscrobbler.pm
Criterion Covered Total %
statement 24 38 63.1
branch 0 2 0.0
condition n/a
subroutine 8 13 61.5
pod 5 5 100.0
total 37 58 63.7


line stmt bran cond sub pod time code
1             package WebService::Audioscrobbler;
2 1     1   21039 use warnings;
  1         2  
  1         32  
3 1     1   5 use strict;
  1         2  
  1         23  
4 1     1   746 use CLASS;
  1         350  
  1         6  
5            
6 1     1   40 use base 'Class::Data::Accessor';
  1         2  
  1         811  
7 1     1   647 use base 'Class::Accessor::Fast';
  1         3  
  1         856  
8            
9 1     1   5724 use NEXT;
  1         6794  
  1         45  
10 1     1   1020 use UNIVERSAL::require;
  1         6719  
  1         13  
11            
12 1     1   1088 use URI;
  1         5095  
  1         10  
13            
14             =head1 NAME
15            
16             WebService::Audioscrobbler - An object-oriented interface to the Audioscrobbler WebService API
17            
18             =cut
19            
20             our $VERSION = '0.08';
21            
22             CLASS->mk_classaccessor("base_url" => URI->new("http://ws.audioscrobbler.com/1.0/"));
23            
24             # defining default classes
25             CLASS->mk_classaccessor("artist_class" => CLASS . '::Artist');
26             CLASS->mk_classaccessor("track_class" => CLASS . '::Track');
27             CLASS->mk_classaccessor("tag_class" => CLASS . '::Tag');
28             CLASS->mk_classaccessor("user_class" => CLASS . '::User');
29             CLASS->mk_classaccessor("data_fetcher_class" => CLASS . '::DataFetcher');
30            
31             # requiring stuff
32             CLASS->artist_class->require or die $@;
33             CLASS->track_class->require or die $@;
34             CLASS->tag_class->require or die $@;
35             CLASS->user_class->require or die $@;
36             CLASS->data_fetcher_class->require or die $@;
37            
38             # object accessors
39             CLASS->mk_accessors(qw/data_fetcher/);
40            
41             =head1 SYNOPSIS
42            
43             B
44             B
45             If you feel like taking over and developing it further, feel free to contact the
46             author.
47            
48             Thisa module aims to be a full implementation of a an object-oriented interface
49             to the Audioscrobbler WebService API (as available on
50             L). Since version 0.04, the
51             module fully supports data caching and, thus, complies to the service's
52             recommended usage guides.
53            
54             use WebService::Audioscrobbler;
55            
56             my $ws = WebService::Audioscrobbler->new;
57            
58             # get an object for artist named 'foo'
59             my $artist = $ws->artist('foo');
60            
61             # retrieves tracks from 'foo'
62             my @tracks = $artist->tracks;
63            
64             # retrieves tags associated with 'foo'
65             my @tags = $artist->tags;
66            
67             # fetch artists similar to 'foo'
68             my @similar = $artist->similar_artists;
69            
70             # prints each one of their names
71             for my $similar (@similar) {
72             print $similar->name . "\n";
73             }
74            
75             ...
76            
77             # get an object for tag 'bar'
78             my $tag = $ws->tag('bar');
79            
80             # fetch tracks tagged with 'bar'
81             my @bar_tracks = $tag->tracks;
82            
83             ...
84            
85             my $user = $ws->user('baz');
86            
87             my @baz_neighbours = $user->neighbours;
88            
89             Audioscrobbler is a great service for tracking musical data of various sorts,
90             and its integration with the LastFM service (L) makes it
91             work even better. Audioscrobbler provides data regarding similarity between
92             artists, artists discography, tracks by musical genre (actually, by tags),
93             top artists / tracks / albums / tags and how all of that related to your own
94             musical taste.
95            
96             Currently, only of subset of these data feeds are implemented, which can be
97             viewed as the core part of the service: artists, tags, tracks and users. Since
98             this module was developed as part of a automatic playlist building application
99             (still in development) these functions were more than enough for its initial
100             purposes but a (nearly) full WebServices API is planned.
101            
102             In any case, code or documentation patches are welcome.
103            
104             =head1 METHODS
105            
106             =cut
107            
108             =head2 C
109            
110             Creates a new C object. This object can then be
111             used to retrieve various bits of information from the Audioscrobbler database.
112             If C<$cache_root> is specified, Audioscrobbler data will be cached under this
113             directory, otherwise it will use L defaults.
114            
115             =cut
116            
117             sub new {
118 0     0 1   my $class = shift;
119 0           my ($cache_root) = @_;
120            
121 0           my $self = bless {}, $class;
122            
123             # creates the data fetcher object which will be extensively used
124 0           $self->data_fetcher(
125             $self->data_fetcher_class->new( {
126             base_url => $self->base_url,
127             cache_root => $cache_root
128             } )
129             );
130            
131 0           $self;
132             }
133            
134             =head2 C
135            
136             Returns an L object constructed using the
137             given C<$name>. Note that this call doesn't actually check if the artist exists
138             since no remote calls are dispatched - the object is only constructed.
139            
140             =cut
141            
142             sub artist {
143 0     0 1   my ($self, $artist) = @_;
144 0           return $self->artist_class->new($artist, $self->data_fetcher);
145             }
146            
147             =head2 C
148            
149             Returns an L object constructed used the
150             given C<$artist> and C<$title>. The C<$artist> parameter can either be a
151             L object or a string (in this case, a
152             L will be created behind the scenes). Note
153             that this call doesn't actually check if the track exists since no remote calls
154             are dispatched - the object is only constructed.
155            
156             =cut
157            
158             sub track {
159 0     0 1   my ($self, $artist, $title) = @_;
160            
161 0 0         $artist = $self->artist($artist)
162             unless ref $artist; # assume the user knows what he's doing
163            
164 0           return $self->track_class->new($artist, $title, $self->data_fetcher);
165             }
166            
167             =head2 C
168            
169             Returns an L object constructed using the given
170             C<$name>. Note that this call doesn't actually check if the tag exists since no
171             remote calls are dispatched - the object is only constructed.
172            
173             =cut
174            
175             sub tag {
176 0     0 1   my ($self, $tag) = @_;
177 0           return $self->tag_class->new($tag, $self->data_fetcher);
178             }
179            
180             =head2 C
181            
182             Returns an L object constructed using the given
183             C<$name>. Note that this call doesn't actually check if the user exists since no
184             remote calls are dispatched - the object is only constructed.
185            
186             =cut
187            
188             sub user {
189 0     0 1   my ($self, $user) = @_;
190 0           return $self->user_class->new($user, $self->data_fetcher);
191             }
192            
193             =head1 AUTHOR
194            
195             Nilson Santos Figueiredo Junior, C<< >>
196            
197             =head1 BUGS
198            
199             Please report any bugs or feature requests to
200             C, or through the web interface at
201             L.
202             I will be notified, and then you'll automatically be notified of progress on
203             your bug as I make changes.
204            
205             =head1 SUPPORT
206            
207             You can find documentation for this module with the perldoc command.
208            
209             perldoc WebService::Audioscrobbler
210            
211             You can also look for information at:
212            
213             =over 4
214            
215             =item * AnnoCPAN: Annotated CPAN documentation
216            
217             L
218            
219             =item * CPAN Ratings
220            
221             L
222            
223             =item * RT: CPAN's request tracker
224            
225             L
226            
227             =item * Search CPAN
228            
229             L
230            
231             =back
232            
233             =head1 COPYRIGHT & LICENSE
234            
235             Copyright 2006-2007 Nilson Santos Figueiredo Junior, all rights reserved.
236            
237             This program is free software; you can redistribute it and/or modify it
238             under the same terms as Perl itself.
239            
240             B: The datafeed from audioscrobbler.net is for
241             I. Please see
242             L for
243             more licensing information.
244            
245             =head1 SEE ALSO
246            
247             =over 4
248            
249             =item * L and L
250            
251             =item * L, L, L
252            
253             =item * L, L, L, L
254            
255             =back
256            
257             =cut
258            
259             1; # End of WebService::Audioscrobbler