WWW::XKCD::AsText - retrieve text versions of comics on www.xkcd.com
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;
The module retrieving http://xkcd.com transcriptions which can be found on http://www.ohnorobot.com/.
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:
->new( timeout => 10 );
Optional. Specifies the timeout argument of LWP::UserAgent's constructor, which is used for retrieving text. Defaults to: 30 seconds.
timeout
30
->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.
ua
WWW::XKCD::AsText
agent
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().
undef
error()
croak()
defined()
Note: the module relies on user submitted transcriptions of comics, therefore you are unlikely to be able to retrieve texts for newest comics.
Takes no arguments, must be called after failed retrieve() method. Returns a human parsable error message describing why retrieve() failed.
retrieve()
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.
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().
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).
new()
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.
LWP::UserAgent, URI, http://xkcd.com
Zoffix Znet, <zoffix at cpan.org> (http://zoffix.com, http://haslayout.net)
<zoffix at cpan.org>
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.
bug-www-xkcd-astext at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc WWW::XKCD::AsText
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-XKCD-AsText
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/WWW-XKCD-AsText
CPAN Ratings
http://cpanratings.perl.org/d/WWW-XKCD-AsText
Search CPAN
http://search.cpan.org/dist/WWW-XKCD-AsText
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.
To install WWW::XKCD::AsText, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::XKCD::AsText
CPAN shell
perl -MCPAN -e shell install WWW::XKCD::AsText
For more information on module installation, please visit the detailed CPAN module installation guide.