############################################################
#
# $Id: UFS.pm,v 1.7 2006/01/10 15:45:58 nicolaw Exp $
# WWW::Comic::Plugin::UFS - UFS www.comics.com plugin for WWW::Comic
#
# Copyright 2006 Nicola Worthington
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################
package WWW::Comic::Plugin::UFS;
# vim:ts=4:sw=4:tw=78
use strict;
use Carp qw(carp croak);
use vars qw($VERSION @ISA %COMICS $HAVE_PROBED);
$VERSION = sprintf('%d.%02d', q$Revision: 1.7 $ =~ /(\d+)/g);
@ISA = qw(WWW::Comic::Plugin);
$HAVE_PROBED = 0;
%COMICS = (
peanuts => 'comics',
pcnpixel => 'wash',
heathcliff => 'creators',
);
sub new {
my $class = shift;
my $self = { homepage => 'http://www.comics.com' };
bless $self, $class;
return $self;
}
sub strip_url {
my $self = shift;
my %param = @_;
# This plugin doesn't yet support the ID paramater
return undef if exists $param{id};
# If we don't know about this comic and we've not probed before,
# then go and probe for the first time
if (!exists($COMICS{$param{comic}}) && !$HAVE_PROBED) {
$self->comics(probe => 1);
}
# If we've probed and we still do not know about this comic then
# return undef and complain if perl warnings are turned on
if ($HAVE_PROBED && !exists($COMICS{$param{comic}})) {
carp "I do not know how to handle comic '$param{comic}'" if $^W;
return undef;
}
my $url = "$self->{homepage}/$COMICS{$param{comic}}/$param{comic}";
$self->{ua} ||= $self->_new_agent();
my $response = $self->{ua}->get($url);
if ($response->is_success) {
my $html = $response->content;
if ($html =~ m#
{homepage}$1" unless $url =~ /^https?:\/\//i;
return $url;
}
} elsif ($^W) {
carp($response->status_line);
}
return undef;
}
sub comics {
my $self = shift;
my %param = @_ % 2 ? (@_,1) : @_;
# If we have comic information then return it
if (keys(%COMICS)) {
# Unless we've never probed before and we're being asked to probe
unless (!$HAVE_PROBED && exists $param{probe} && $param{probe}) {
return (keys(%COMICS));
}
}
# Only continue if we've never probed before and we're
# being asked to probe
unless (!$HAVE_PROBED && exists $param{probe} && $param{probe}) {
return (keys(%COMICS));
}
$HAVE_PROBED = 1;
$self->{ua} ||= $self->_new_agent;
my $response = $self->{ua}->get($self->{homepage});
if ($response->is_success) {
my $html = $response->content;
while ($html =~ m#(/(editoons|comics|creators|wash)/(\w+)/)#ms) {
$COMICS{$3} = $2;
$html =~ s#$1##g;
}
} elsif ($^W) {
carp "Failed to retrieve $self->{homepage}: ".$response->status_line;
}
return (keys(%COMICS));
}
sub type {
my $self = shift;
my %param = @_;
if (exists $COMICS{$param{comic}}) {
return $COMICS{$param{comic}};
}
return undef;
}
sub homepage {
my $self = shift;
my %param = @_;
if (exists $COMICS{$param{comic}}) {
return "$self->{homepage}/$COMICS{$param{comic}}/$param{comic}/";
}
return undef;
}
1;
=pod
=head1 NAME
WWW::Comic::Plugin::UFS - UFS www.comics.com plugin for WWW::Comic
=head1 SYNOPSIS
# Actively probe www.comics.com to return (and cache)
# a list of supported comics
my @comics = $plugin->comics(probe => 1);
# Return a list of supported comics that has already
# been cached in memory
@comics = $plugin->comics;
# Return the comic homepage URL
my $url = $plugin->homepage(comic => "peanuts");
See L.
=head1 METHODS
See L and L for a list of standard
methods that this module supports.
Additional methods are:
=over 4
=item type
Returns the type of comic strip; editoons, comics, creators or wash.
=item homepage
Returns the comic homepage URL.
=back
=head1 VERSION
$Id: UFS.pm,v 1.7 2006/01/10 15:45:58 nicolaw Exp $
=head1 AUTHOR
Nicola Worthington
L
=head1 COPYRIGHT
Copyright 2006 Nicola Worthington.
This software is licensed under The Apache Software License, Version 2.0.
L
=cut