| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
############################################################ |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# $Id: UFS.pm,v 1.7 2006/01/10 15:45:58 nicolaw Exp $ |
|
4
|
|
|
|
|
|
|
# WWW::Comic::Plugin::UFS - UFS www.comics.com 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::UFS; |
|
23
|
|
|
|
|
|
|
# vim:ts=4:sw=4:tw=78 |
|
24
|
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
11748
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
97
|
|
|
26
|
2
|
|
|
2
|
|
10
|
use Carp qw(carp croak); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
164
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
2
|
|
|
2
|
|
14
|
use vars qw($VERSION @ISA %COMICS $HAVE_PROBED); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
1880
|
|
|
29
|
|
|
|
|
|
|
$VERSION = sprintf('%d.%02d', q$Revision: 1.7 $ =~ /(\d+)/g); |
|
30
|
|
|
|
|
|
|
@ISA = qw(WWW::Comic::Plugin); |
|
31
|
|
|
|
|
|
|
$HAVE_PROBED = 0; |
|
32
|
|
|
|
|
|
|
%COMICS = ( |
|
33
|
|
|
|
|
|
|
peanuts => 'comics', |
|
34
|
|
|
|
|
|
|
pcnpixel => 'wash', |
|
35
|
|
|
|
|
|
|
heathcliff => 'creators', |
|
36
|
|
|
|
|
|
|
); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
|
39
|
1
|
|
|
1
|
1
|
23
|
my $class = shift; |
|
40
|
1
|
|
|
|
|
3
|
my $self = { homepage => 'http://www.comics.com' }; |
|
41
|
1
|
|
|
|
|
5
|
bless $self, $class; |
|
42
|
1
|
|
|
|
|
4
|
return $self; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub strip_url { |
|
46
|
9
|
|
|
9
|
1
|
23
|
my $self = shift; |
|
47
|
9
|
|
|
|
|
24
|
my %param = @_; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# This plugin doesn't yet support the ID paramater |
|
50
|
9
|
50
|
|
|
|
30
|
return undef if exists $param{id}; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# If we don't know about this comic and we've not probed before, |
|
53
|
|
|
|
|
|
|
# then go and probe for the first time |
|
54
|
9
|
0
|
33
|
|
|
31
|
if (!exists($COMICS{$param{comic}}) && !$HAVE_PROBED) { |
|
55
|
0
|
|
|
|
|
0
|
$self->comics(probe => 1); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# If we've probed and we still do not know about this comic then |
|
59
|
|
|
|
|
|
|
# return undef and complain if perl warnings are turned on |
|
60
|
9
|
50
|
33
|
|
|
36
|
if ($HAVE_PROBED && !exists($COMICS{$param{comic}})) { |
|
61
|
0
|
0
|
|
|
|
0
|
carp "I do not know how to handle comic '$param{comic}'" if $^W; |
|
62
|
0
|
|
|
|
|
0
|
return undef; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
9
|
|
|
|
|
46
|
my $url = "$self->{homepage}/$COMICS{$param{comic}}/$param{comic}"; |
|
66
|
|
|
|
|
|
|
|
|
67
|
9
|
|
66
|
|
|
37
|
$self->{ua} ||= $self->_new_agent(); |
|
68
|
9
|
|
|
|
|
48
|
my $response = $self->{ua}->get($url); |
|
69
|
9
|
50
|
|
|
|
8031904
|
if ($response->is_success) { |
|
|
|
50
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
my $html = $response->content; |
|
71
|
0
|
0
|
|
|
|
0
|
if ($html =~ m#
|
|
72
|
|
|
|
|
|
|
/$COMICS{$param{comic}}/$param{comic} |
|
73
|
|
|
|
|
|
|
/archive/images/$param{comic}.+?)"#imsx) { |
|
74
|
0
|
|
|
|
|
0
|
my $url = $1; |
|
75
|
0
|
0
|
|
|
|
0
|
$url = "$self->{homepage}$1" unless $url =~ /^https?:\/\//i; |
|
76
|
0
|
|
|
|
|
0
|
return $url; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} elsif ($^W) { |
|
80
|
0
|
|
|
|
|
0
|
carp($response->status_line); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
9
|
|
|
|
|
610
|
return undef; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub comics { |
|
87
|
25
|
|
|
25
|
1
|
55
|
my $self = shift; |
|
88
|
25
|
50
|
|
|
|
185
|
my %param = @_ % 2 ? (@_,1) : @_; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# If we have comic information then return it |
|
91
|
25
|
50
|
|
|
|
84
|
if (keys(%COMICS)) { |
|
92
|
|
|
|
|
|
|
# Unless we've never probed before and we're being asked to probe |
|
93
|
25
|
50
|
33
|
|
|
184
|
unless (!$HAVE_PROBED && exists $param{probe} && $param{probe}) { |
|
|
|
|
33
|
|
|
|
|
|
94
|
25
|
|
|
|
|
151
|
return (keys(%COMICS)); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Only continue if we've never probed before and we're |
|
99
|
|
|
|
|
|
|
# being asked to probe |
|
100
|
0
|
0
|
0
|
|
|
|
unless (!$HAVE_PROBED && exists $param{probe} && $param{probe}) { |
|
|
|
|
0
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return (keys(%COMICS)); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$HAVE_PROBED = 1; |
|
105
|
0
|
|
0
|
|
|
|
$self->{ua} ||= $self->_new_agent; |
|
106
|
0
|
|
|
|
|
|
my $response = $self->{ua}->get($self->{homepage}); |
|
107
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
|
|
|
0
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my $html = $response->content; |
|
109
|
0
|
|
|
|
|
|
while ($html =~ m#(/(editoons|comics|creators|wash)/(\w+)/)#ms) { |
|
110
|
0
|
|
|
|
|
|
$COMICS{$3} = $2; |
|
111
|
0
|
|
|
|
|
|
$html =~ s#$1##g; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
} elsif ($^W) { |
|
115
|
0
|
|
|
|
|
|
carp "Failed to retrieve $self->{homepage}: ".$response->status_line; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return (keys(%COMICS)); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub type { |
|
122
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
123
|
0
|
|
|
|
|
|
my %param = @_; |
|
124
|
0
|
0
|
|
|
|
|
if (exists $COMICS{$param{comic}}) { |
|
125
|
0
|
|
|
|
|
|
return $COMICS{$param{comic}}; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
0
|
|
|
|
|
|
return undef; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub homepage { |
|
131
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
132
|
0
|
|
|
|
|
|
my %param = @_; |
|
133
|
0
|
0
|
|
|
|
|
if (exists $COMICS{$param{comic}}) { |
|
134
|
0
|
|
|
|
|
|
return "$self->{homepage}/$COMICS{$param{comic}}/$param{comic}/"; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
0
|
|
|
|
|
|
return undef; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=pod |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 NAME |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
WWW::Comic::Plugin::UFS - UFS www.comics.com plugin for WWW::Comic |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Actively probe www.comics.com to return (and cache) |
|
150
|
|
|
|
|
|
|
# a list of supported comics |
|
151
|
|
|
|
|
|
|
my @comics = $plugin->comics(probe => 1); |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# Return a list of supported comics that has already |
|
154
|
|
|
|
|
|
|
# been cached in memory |
|
155
|
|
|
|
|
|
|
@comics = $plugin->comics; |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# Return the comic homepage URL |
|
158
|
|
|
|
|
|
|
my $url = $plugin->homepage(comic => "peanuts"); |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
See L. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 METHODS |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
See L and L for a list of standard |
|
165
|
|
|
|
|
|
|
methods that this module supports. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Additional methods are: |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over 4 |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item type |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns the type of comic strip; editoons, comics, creators or wash. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item homepage |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Returns the comic homepage URL. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=back |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 VERSION |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
$Id: UFS.pm,v 1.7 2006/01/10 15:45:58 nicolaw Exp $ |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AUTHOR |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Nicola Worthington |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
L |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Copyright 2006 Nicola Worthington. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This software is licensed under The Apache Software License, Version 2.0. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
L |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
|
200
|
|
|
|
|
|
|
|