File Coverage

lib/WWW/Comic/Plugin/UserFriendly.pm
Criterion Covered Total %
statement 25 28 89.2
branch 4 10 40.0
condition 3 6 50.0
subroutine 5 5 100.0
pod 2 2 100.0
total 39 51 76.4


line stmt bran cond sub pod time code
1             ############################################################
2             #
3             # $Id: UserFriendly.pm,v 1.1 2006/01/09 23:31:45 nicolaw Exp $
4             # WWW::Comic::Plugin::UserFriendly - UserFriendly 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::UserFriendly;
23             # vim:ts=4:sw=4:tw=78
24              
25 2     2   5032 use strict;
  2         4  
  2         86  
26 2     2   12 use Carp qw(carp croak);
  2         4  
  2         136  
27              
28 2     2   12 use vars qw($VERSION @ISA %COMICS);
  2         4  
  2         1204  
29             $VERSION = sprintf('%d.%02d', q$Revision: 1.1 $ =~ /(\d+)/g);
30             @ISA = qw(WWW::Comic::Plugin);
31             %COMICS = ( userfriendly => 'User Friendly the Comic Strip' );
32              
33             sub new {
34 1     1 1 21 my $class = shift;
35 1         3 my $self = { homepage => 'http://ars.userfriendly.org/cartoons/' };
36 1         4 bless $self, $class;
37 1         3 return $self;
38             }
39              
40             sub strip_url {
41 5     5 1 12 my $self = shift;
42 5         16 my %param = @_;
43              
44 5   66     32 $self->{ua} ||= $self->_new_agent();
45 5         16 my $url = $self->{homepage};
46 5 50 33     28 if (exists $param{id} && $param{id} =~ /^[0-9]+$/) {
47 0         0 $url .= "?id=$param{id}";
48             }
49              
50 5         32 my $response = $self->{ua}->get($url);
51 5 50       9968366 if ($response->is_success) {
    0          
52 5         89 my $html = $response->content;
53 5 50       852 if ($html =~ m#
54             /cartoons/archives/\S+/\w*uf\d+\.(gif|jpe?g|png))"#imsx) {
55 5         18 my $url = $1;
56 5 50       39 $url = "$self->{homepage}$1" unless $url =~ /^https?:\/\//i;
57 5         195 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::UserFriendly - UserFriendly plugin for WWW::Comic
74              
75             =head1 SYNOPSIS
76              
77             See L.
78              
79             =head1 VERSION
80              
81             $Id: UserFriendly.pm,v 1.1 2006/01/09 23:31:45 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