WWW::Comic::Plugin::CyanideAndHappiness - WWW::Comic plugin to fetch C+H


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

Index


Code Index:

NAME

Top

WWW::Comic::Plugin::CyanideAndHappiness - WWW::Comic plugin to fetch C+H

VERSION

Top

Version 0.01

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 => 'cyanideandhappiness');




DESCRIPTION

Top

A plugin for WWW::Comic to fetch the Cyanide and Happiness comic from http://www.explosm.net/

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-cyanideandhappiness at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Comic-Plugin-CyanideAndHappiness. 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::CyanideAndHappiness




You can also look for information at:

* RT: CPAN's request tracker

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

* AnnoCPAN: Annotated CPAN documentation

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

* CPAN Ratings

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

* Search CPAN

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

ACKNOWLEDGEMENTS

Top

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

COPYRIGHT & LICENSE

Top


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

use warnings;
use strict;
use Carp;

use vars qw($VERSION @ISA %COMICS);
our $VERSION = '0.01';
@ISA = qw(WWW::Comic::Plugin);
%COMICS = ( cyanideandhappiness => 'Cyanide and Happiness' );

# $Id: CyanideAndHappiness.pm 326 2008-04-04 22:28:44Z davidp $


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

sub strip_url {
    my $self = shift;
    my %param = @_;
    
    my $id = $param{id} || 'new';
    my $url = $self->{homepage} . "$id/";
    
    my $response = $self->_new_agent->get($url);
    if ($response->is_success) {
        my $html = $response->content;
        my $alt_text = 'Cyanide and Happiness, a daily webcomic';
        if ($html =~ m{<img alt="$alt_text" src="([^"]+)">}msi)
        {
            my $url = $1;
            return $url;
        } else {
            carp "Failed to find C+H comic strip at $url";
            warn "Content was:\n$html\n";
            return;
        }
    
    } else {
        carp "Failed to fetch $url - " . $response->status_line;
        return;
    }
    
}

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