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

NAME

WWW::XKCD::AsText - retrieve text versions of comics on www.xkcd.com

SYNOPSIS

    use strict;
    use warnings;

    use WWW::XKCD::AsText;

    my $xkcd = WWW::XKCD::AsText->new;

    my $text = $xkcd->retrieve( 333 )
        or die $xkcd->error;

    printf "Text for comic on %s is:\n%s\n",
                $xkcd->uri, $text;

DESCRIPTION

The module retrieving http://xkcd.com transcriptions which can be found on http://www.ohnorobot.com/.

CONSTRUCTOR

new

    my $xkcd = WWW::XKCD::AsText->new;

    my $xkcd = WWW::XKCD::AsText->new(
        timeout => 10,
    );

    my $xkcd = WWW::XKCD::AsText->new(
        ua => LWP::UserAgent->new(
            timeout => 10,
            agent   => 'comicReader',
        ),
    );

Constructs and returns a brand new yummy juicy WWW::XKCD::AsText object. Takes two arguments, both are optional. Possible arguments are as follows:

timeout

    ->new( timeout => 10 );

Optional. Specifies the timeout argument of LWP::UserAgent's constructor, which is used for retrieving text. Defaults to: 30 seconds.

ua

    ->new( ua => LWP::UserAgent->new( agent => 'Foos!' ) );

Optional. If the timeout argument is not enough for your needs of mutilating the LWP::UserAgent object used for retrieving, feel free to specify the ua argument which takes an LWP::UserAgent object as a value. Note: the timeout argument to the constructor will not do anything if you specify the ua argument as well. Defaults to: plain boring default LWP::UserAgent object with timeout argument set to whatever WWW::XKCD::AsText's timeout argument is set to as well as agent argument is set to mimic Firefox.

METHODS

retrieve

    my $text = $xkcd->retrieve( 333 )
        or die $xkcd->error;

Takes one mandatory argument which is the XKCD's comic number. If a network error occured or text is not available for the comic returns either undef or an empty list depending on the context and the reason for the error will be available via error() method (see below). On success returns comic's transcription as a scalar. Will croak() if comic ID is not a number or is not defined().

Note: the module relies on user submitted transcriptions of comics, therefore you are unlikely to be able to retrieve texts for newest comics.

error

    my $text = $xkcd->retrieve( 333 )
        or die $xkcd->error;

Takes no arguments, must be called after failed retrieve() method. Returns a human parsable error message describing why retrieve() failed.

text

    my $text = $xkcd->text;

Must be called after a successfull call to retrieve() method. Takes no arguments, returns a transcription of the comic which was retrieve()d last.

uri

    my $comic_uri = $xkcd->uri;

Must be called after a successfull call to retrieve() method. Takes no arguments, returns URI object pointing to the comic on http://xkcd.com ID of which you've specified in retrieve().

timeout

    my $timeout = $xkcd->timeout;

Takes no arguments, returns whatever you've specified as the timeout argument to the new() method (or its default if you didn't specify anything).

ua

    my $ua_obj = $xkcd->ua;

    $xkcd->ua( LWP::UserAgent->new( timeout => 10, agent => 'comicBook' ) ):

Returns an LWP::UserAgent object which is used for retrieving comic texts. Accepts one optional argument which must be an LWP::UserAgent object, if you specify it then whatever you specify will be used for retrieving comic texts.

SEE ALSO

LWP::UserAgent, URI, http://xkcd.com

AUTHOR

Zoffix Znet, <zoffix at cpan.org> (http://zoffix.com, http://haslayout.net)

BUGS

Please report any bugs or feature requests to bug-www-xkcd-astext at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-XKCD-AsText. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc WWW::XKCD::AsText

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2008 Zoffix Znet, all rights reserved.

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