NAME
WWW::xkcd - Synchronous and asynchronous interfaces to xkcd comics
VERSION
version 0.001
SYNOPSIS
use WWW::xkcd;
my $xkcd = WWW::xkcd->new;
my $comic = $xkcd->fetch; # provides latest data
say "Today's comic is titled: ", $comic->{'title'};
# or in async mode
$xkcd->fetch( sub {
my $comic = shift;
say "Today's comic is titled: ", $comic->{'title'};
} );
DESCRIPTION
This module allows you to access xkcd comics ()
using the official API in synchronous mode (what people are used to) or
in asynchronous mode.
The asynchronous mode requires you have AnyEvent and AnyEvent::HTTP
available. However, since it's just *supported* and not *crucial*, it is
not declared as a prerequisite.
Currently it retrieves the metadata of each comic, but it will probalby
also fetch the actual comic in the next release.
This module still hasn't materialized so some things might change, but
probably not a lot, if at all.
METHODS
new
Create a new WWW::xkcd object.
# 'file' will probably be renamed
my $xkcd = WWW::xkcd->new(
base_url => 'http://www.xkcd.com',
file => 'info.0.json',
);
fetch
Fetch the metadata of the comic. This method will probably be renamed,
stay tuned.
# fetching the latest
my $comic = $xkcd->fetch;
# fetching a specific one
my $comic = $xkcd->fetch(20);
# using callbacks for async mode
$xkcd->fetch( sub { my $comic = shift; ... } );
# using callbacks for a specific one
$xkcd->fetch( 20, sub { my $comic = shift; ... } );
DEPENDENCIES
* Try::Tiny
* HTTP::Tiny
* JSON
* Carp
AUTHOR
Sawyer X
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Sawyer X.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.