Help-Site Computer Manuals
Software
Hardware
Programming
Networking
  Algorithms & Data Structures   Programming Languages   Revision Control
  Protocols
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

WebService::Audioscrobbler::DataFetcher
Cached data fetching provider

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


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 the Cache::FileCache manpage 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 the Cache::FileCache manpage 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, the Cache::FileCache manpage 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 the LWP::Simple manpage and returns it.

croak

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


AUTHOR

Nilson Santos Figueiredo Júnior, <nilsonsfj at cpan.org>


COPYRIGHT & LICENSE

Copyright 2006-2007 Nilson Santos Figueiredo Júnior, all rights reserved.

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

Programminig
Wy
Wy
yW
Wy
Programming
Wy
Wy
Wy
Wy