View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Zoffix Znet > WWW-XKCD-AsText-0.003 > WWW::XKCD::AsText



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.003   Source   Latest Release: WWW-XKCD-AsText-0.006


WWW::XKCD::AsText - retrieve text versions of comics on


    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 transcriptions which can be found on



    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.


    ->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.



    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.


    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.


    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 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).


    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,


Zoffix Znet, <zoffix at> (,


Please report any bugs or feature requests to bug-www-xkcd-astext at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


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

    perldoc WWW::XKCD::AsText

You can also look for information at:


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.

syntax highlighting: