WWW::Comic::Plugin::LeastICouldDo - WWW::Comic plugin to fetch LeastICouldDo comic


WWW-Comic-Plugin-LeastICouldDo documentation Contained in the WWW-Comic-Plugin-LeastICouldDo distribution.

Index


Code Index:

NAME

Top

WWW::Comic::Plugin::LeastICouldDo - WWW::Comic plugin to fetch LeastICouldDo comic

SYNOPSIS

Top

See WWW::Comic for full details, but here's a brief example:

 use WWW::Comic;
 my $wc = new WWW::Comic;
 my $latest_candh_strip_url 
    = WWW::Comic->strip_url(comic => 'LeastICouldDo');




DESCRIPTION

Top

A plugin for WWW::Comic to fetch the LeastICouldDo comic from http://www.leasticoulddo.com/

See WWW::Comic and WWW::Comic::Plugin for information on the WWW::Comic interface.

FUNCTIONS

Top

new

Constructor - see WWW::Comic for usage

strip_url

Returns the URL to the current strip image (or, if given the 'id' param, the URL to that particular strip)

AUTHOR

Top

David Precious, <davidp at preshweb.co.uk>

BUGS

Top

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

SUPPORT

Top

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

    perldoc WWW::Comic::Plugin::LeastICouldDo




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Comic-Plugin-LeastICouldDo

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/WWW-Comic-Plugin-LeastICouldDo

* CPAN Ratings

http://cpanratings.perl.org/d/WWW-Comic-Plugin-LeastICouldDo

* Search CPAN

http://search.cpan.org/dist/WWW-Comic-Plugin-LeastICouldDo

ACKNOWLEDGEMENTS

Top

To Nicola Worthington (NICOLAW) for writing WWW::Comic

COPYRIGHT & LICENSE

Top


WWW-Comic-Plugin-LeastICouldDo documentation Contained in the WWW-Comic-Plugin-LeastICouldDo distribution.
package WWW::Comic::Plugin::LeastICouldDo;

use warnings;
use strict;
use Carp;
use XML::Simple;

use vars qw($VERSION @ISA %COMICS);
our $VERSION = '0.01';
@ISA = qw(WWW::Comic::Plugin);
%COMICS = (leasticoulddo => 'LeastICouldDo');

# $Id: LeastICouldDo.pm 388 2008-06-26 14:56:37Z davidp $


sub new {
    my $class = shift;
    my $self = { homepage => 'http://www.leasticoulddo.com/' };
    bless $self, $class;
    return $self;
}

sub strip_url {
    my $self = shift;
    my %param = @_;
    
    my $stripstub = 'http://archive.leasticoulddo.com/strips';

    if ($param{id}) {
        # we know what the URL will be
        # TODO: maybe fetch it to make sure it's actually valid?
        return "$stripstub/$param{id}.gif";
    }

    # the latest comic will be found at /strips/comic.gif - but that's not
    # much good for anything that expects each strip to have a different
    # URL.  So, instead, we'll need to parse the RSS feed and return the
    # first comic from the feed (which will have the proper URL).
    my $feedurl = 'http://feeds.feedburner.com/LICD';
    my $response = $self->_new_agent->get($feedurl);
    if ($response->is_success) {
        my $rss = XML::Simple::XMLin($response->content);

        if (!$rss) {
            carp "Failed to parse RSS feed";
            return;
        }

        item:
        for my $item (@{ $rss->{channel}->{item} }) {
            next item if $item->{category} ne 'Comic';

            if (my($id) = $item->{guid}->{content} =~ m{comic/([0-9]+)$})
            {
                # bingo, found the first comic listed in the feed:
                return "$stripstub/$id.gif";
            }
        }
            
        # we should not get here in normal operation:
        carp "Failed to find comics in RSS feed";
        return;
        
    } else {
        carp "Failed to fetch $feedurl - " . $response->status_line;
        return;
    }
    
}


1; # End of WWW::Comic::Plugin::LeastICouldDo