package WebService::Audioscrobbler;
use warnings;
use strict;
use CLASS;
use base 'Class::Data::Accessor';
use base 'Class::Accessor::Fast';
use NEXT;
use UNIVERSAL::require;
use URI;
=head1 NAME
WebService::Audioscrobbler - An object-oriented interface to the Audioscrobbler WebService API
=cut
our $VERSION = '0.07';
CLASS->mk_classaccessor("base_url" => URI->new("http://ws.audioscrobbler.com/1.0/"));
# defining default classes
CLASS->mk_classaccessor("artist_class" => CLASS . '::Artist');
CLASS->mk_classaccessor("track_class" => CLASS . '::Track');
CLASS->mk_classaccessor("tag_class" => CLASS . '::Tag');
CLASS->mk_classaccessor("user_class" => CLASS . '::User');
CLASS->mk_classaccessor("data_fetcher_class" => CLASS . '::DataFetcher');
# requiring stuff
CLASS->artist_class->require or die $@;
CLASS->track_class->require or die $@;
CLASS->tag_class->require or die $@;
CLASS->user_class->require or die $@;
CLASS->data_fetcher_class->require or die $@;
# object accessors
CLASS->mk_accessors(qw/data_fetcher/);
=head1 SYNOPSIS
This module aims to be a full implementation of a an object-oriented interface
to the Audioscrobbler WebService API (as available on
L). Since version 0.04, the
module fully supports data caching and, thus, complies to the service's
recommended usage guides.
use WebService::Audioscrobbler;
my $ws = WebService::Audioscrobbler->new;
# get an object for artist named 'foo'
my $artist = $ws->artist('foo');
# retrieves tracks from 'foo'
my @tracks = $artist->tracks;
# retrieves tags associated with 'foo'
my @tags = $artist->tags;
# fetch artists similar to 'foo'
my @similar = $artist->similar_artists;
# prints each one of their names
for my $similar (@similar) {
print $similar->name . "\n";
}
...
# get an object for tag 'bar'
my $tag = $ws->tag('bar');
# fetch tracks tagged with 'bar'
my @bar_tracks = $tag->tracks;
...
my $user = $ws->user('baz');
my @baz_neighbours = $user->neighbours;
Audioscrobbler is a great service for tracking musical data of various sorts,
and its integration with the LastFM service (L) makes it
work even better. Audioscrobbler provides data regarding similarity between
artists, artists discography, tracks by musical genre (actually, by tags),
top artists / tracks / albums / tags and how all of that related to your own
musical taste.
Currently, only of subset of these data feeds are implemented, which can be
viewed as the core part of the service: artists, tags, tracks and users. Since
this module was developed as part of a automatic playlist building application
(still in development) these functions were more than enough for its initial
purposes but a (nearly) full WebServices API is planned.
In any case, code or documentation patches are welcome.
=head1 METHODS
=cut
=head2 C
Creates a new C object. This object can then be
used to retrieve various bits of information from the Audioscrobbler database.
If C<$cache_root> is specified, Audioscrobbler data will be cached under this
directory, otherwise it will use L defaults.
=cut
sub new {
my $class = shift;
my ($cache_root) = @_;
my $self = bless {}, $class;
# creates the data fetcher object which will be extensively used
$self->data_fetcher(
$self->data_fetcher_class->new( {
base_url => $self->base_url,
cache_root => $cache_root
} )
);
$self;
}
=head2 C
Returns an L object constructed using the
given C<$name>. Note that this call doesn't actually check if the artist exists
since no remote calls are dispatched - the object is only constructed.
=cut
sub artist {
my ($self, $artist) = @_;
return $self->artist_class->new($artist, $self->data_fetcher);
}
=head2 C