The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WWW::Opentracker::Stats::Mode - Base module for the different modes

SYNOPSIS

    use WWW::Opentracker::Stats::Mode::TPBS;
    my $tpbs = WWW::Opentracker::Stats::Mode::TPBS->new(
        {
            'statsurl'  => 'http://localhost:6969/stats',
        }
    );

    my $stats   = $tpbs->stats();
    printf "%d torrents served", scalar @{$stats->{'files'}};

DESCRIPTION

Provides accessability for fetching and parsing the statistics from Opentracker.

METHODS

new

 Args: $class, $args

Constructor. Creates a new instance of the class. This constructor is also used by all sub statistics packages.

It takes a HASH/HASHREF of arguments. - statsurl (mandatory) - useragent (mandatory)

stats

 Args: $self

Fetches statistics from the opentracker server over a HTTP channel, decodes the content in the HTTP response and returns the statistics data structure.

It caches the statistics for the entire lifetime of the object. If something is found in the cache, it is returned instead of contacting the server.

parse_stats

 Args: $self, $payload

Returns the payload unchanged.

WARNING This method should really, really be implemented by a subclass. It should return a HASHREF with a sane structure of the statistics data.

fetch

 Args: $self

Makes a HTTP request to the opentracker statistics service using the implementation (sub) class' mode and format settings.

Returns the content of the response unless there was an error. Dies on errors.

url

 Args: $self

Assembles the URL to the opentracker statistics based on the statsurl, format and mode.

Returns the URL as a string.

parse_thousands

 Args: $self, $number

Parses a string that represents a number with a thousands delimiter.

_require_impl

 Private method

 Args: $self

Croaks from the perspect of the caller two steps up the call stack if the method is not called from a subclass implementation.

AUTHOR

Knut-Olav Hoven, <knutolav@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2009 by Knut-Olav Hoven

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.