File Coverage

lib/WWW/Comic/Plugin/Goats.pm
Criterion Covered Total %
statement 13 28 46.4
branch 0 10 0.0
condition 0 6 0.0
subroutine 4 5 80.0
pod 2 2 100.0
total 19 51 37.2


line stmt bran cond sub pod time code
1             ############################################################
2             #
3             # $Id: Goats.pm,v 1.1 2006/01/09 23:47:31 nicolaw Exp $
4             # WWW::Comic::Plugin::Goats - Goats plugin for WWW::Comic
5             #
6             # Copyright 2006 Nicola Worthington
7             #
8             # Licensed under the Apache License, Version 2.0 (the "License");
9             # you may not use this file except in compliance with the License.
10             # You may obtain a copy of the License at
11             #
12             # http://www.apache.org/licenses/LICENSE-2.0
13             #
14             # Unless required by applicable law or agreed to in writing, software
15             # distributed under the License is distributed on an "AS IS" BASIS,
16             # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17             # See the License for the specific language governing permissions and
18             # limitations under the License.
19             #
20             ############################################################
21              
22             package WWW::Comic::Plugin::Goats;
23             # vim:ts=4:sw=4:tw=78
24              
25 2     2   3760 use strict;
  2         5  
  2         80  
26 2     2   11 use Carp qw(carp croak);
  2         4  
  2         144  
27              
28 2     2   11 use vars qw($VERSION @ISA %COMICS);
  2         5  
  2         1025  
29             $VERSION = sprintf('%d.%02d', q$Revision: 1.1 $ =~ /(\d+)/g);
30             @ISA = qw(WWW::Comic::Plugin);
31             %COMICS = ( goats => 'goats: the comic strip' );
32              
33             sub new {
34 1     1 1 5549 my $class = shift;
35 1         4 my $self = { homepage => 'http://www.goats.com/' };
36 1         3 bless $self, $class;
37 1         5 return $self;
38             }
39              
40             sub strip_url {
41 0     0 1   my $self = shift;
42 0           my %param = @_;
43              
44 0   0       $self->{ua} ||= $self->_new_agent();
45 0           my $url = $self->{homepage};
46 0 0 0       if (exists $param{id} && $param{id} =~ /^[0-9]+$/) {
47 0           $url .= "archive/$param{id}.html";
48             }
49              
50 0           my $response = $self->{ua}->get($url);
51 0 0         if ($response->is_success) {
    0          
52 0           my $html = $response->content;
53 0 0         if ($html =~ m#
54             /comix/[0-9]+/goats[0-9]+.(gif|jpe?g|png))"#imsx) {
55 0           my $url = $1;
56 0 0         $url = "$self->{homepage}$1" unless $url =~ /^https?:\/\//i;
57 0           return $url;
58             }
59              
60             } elsif ($^W) {
61 0           carp($response->status_line);
62             }
63              
64 0           return undef;
65             }
66              
67             1;
68              
69             =pod
70              
71             =head1 NAME
72              
73             WWW::Comic::Plugin::Goats - Goats plugin for WWW::Comic
74              
75             =head1 SYNOPSIS
76              
77             See L.
78              
79             =head1 VERSION
80              
81             $Id: Goats.pm,v 1.1 2006/01/09 23:47:31 nicolaw Exp $
82              
83             =head1 AUTHOR
84              
85             Nicola Worthington
86              
87             L
88              
89             =head1 COPYRIGHT
90              
91             Copyright 2006 Nicola Worthington.
92              
93             This software is licensed under The Apache Software License, Version 2.0.
94              
95             L
96              
97             =cut
98