NAME

WebService::Audioscrobbler::DataFetcher - Cached data fetching provider

SYNOPSIS

This is responsible for fetching and caching all data requested from Audioscrobbler WebServices, as recommended by their usage policy.

It can actually function as a generic XML-fetcher-and-converter-to-hashrefs and has no limitations regarding being used only for Audioscrobbler WebServices. In the future, it might even became a completely separate module.

use WebService::Audioscrobbler::DataFetcher;

my $data_fetcher = WebService::Audioscrobbler::DataFetcher->new(
    "http://www.my-base-url.com/base_dir/"
);

# retrieves "http://www.my-base-url.com/base_dir/myown/resource.xml"
# and parses it through XML::Simple::XMLin so we get a hashref
my $data = $data_fetcher->fetch("myown/resource.xml")

FIELDS

base_url

This is the base URL from where data will be fetched.

cache

This is the underlying cache object. By default, this will be a Cache::FileCache object.

cache_root

This is the root directory where the cache will be created. It should only be set as a parameter to new(), setting it afterwards won't have any effect.

METHODS

new($base_url)

new(\%fields)

Creates a new object using either the given $base_url or the \%fields hashref. Any of the above fields can be specified. If the cache field is undefined, create_cache will be called after object construction.

create_cache

Creates a new Cache::FileCache object and saves it in the cache field. The cache has a daily auto purging turned on and data will expire by default in 3 days, which is reasonable since most of Audioscrobbler data changes at most weekly. The cache root will be as specified by the cache_root field (if it's undefined, Cache::FileCache defaults will be used).

fetch($resource)

Actually fetches a XML resource URL. If the resource is not already cached, retrieve_data is called it's results are then cached. The results are then processed by XML::Simple::XMLin so we end up with a nice hashref as our return value.

retrieve_data($uri)

Retrieves data from the specified $uri using LWP::Simple and returns it.

croak

Shortcut for Carp::croak which can be called as a method.

AUTHOR

Nilson Santos Figueiredo Junior, <nilsonsfj at cpan.org>

COPYRIGHT & LICENSE

Copyright 2006-2007 Nilson Santos Figueiredo Junior, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.