line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Comic::Plugin::XKCD; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
31125
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
5
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
166
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
14
|
use vars qw($VERSION @ISA %COMICS); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1031
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
@ISA = qw(WWW::Comic::Plugin); |
10
|
|
|
|
|
|
|
%COMICS = (xkcd => 'xkcd - A webcomic of romance, sarcasm, math, and language'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# $Id: XKCD.pm 331 2008-04-07 21:58:43Z davidp $ |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
WWW::Comic::Plugin::XKCD - WWW::Comic plugin to fetch XKCD comic |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
See L for full details, but here's a brief example: |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use WWW::Comic; |
24
|
|
|
|
|
|
|
my $wc = new WWW::Comic; |
25
|
|
|
|
|
|
|
my $latest_candh_strip_url |
26
|
|
|
|
|
|
|
= WWW::Comic->strip_url(comic => 'xkcd'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
A plugin for L to fetch the xkcd comic from http://www.xkcd.org/ |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
See L and L for information on the WWW::Comic |
34
|
|
|
|
|
|
|
interface. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 FUNCTIONS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over 4 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item new |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Constructor - see L for usage |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
50
|
0
|
|
|
|
|
|
my $self = { homepage => 'http://www.xkcd.org/' }; |
51
|
0
|
|
|
|
|
|
bless $self, $class; |
52
|
0
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item strip_url |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Returns the URL to the current strip image (or, if given the 'id' param, |
58
|
|
|
|
|
|
|
the URL to that particular strip) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub strip_url { |
63
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
64
|
0
|
|
|
|
|
|
my %param = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $url = $self->{homepage}; |
67
|
0
|
0
|
|
|
|
|
$url .= "$param{id}/" if $param{id}; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $response = $self->_new_agent->get($url); |
70
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
71
|
0
|
|
|
|
|
|
my $html = $response->content; |
72
|
0
|
|
|
|
|
|
my $alt_text = 'Cyanide and Happiness, a daily webcomic'; |
73
|
0
|
0
|
|
|
|
|
if ($html |
74
|
|
|
|
|
|
|
=~ m{Image URL \(for hotlinking/embedding\): (.+)}msi) |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
|
|
|
my $url = $1; |
77
|
0
|
|
|
|
|
|
return $url; |
78
|
|
|
|
|
|
|
} else { |
79
|
0
|
|
|
|
|
|
carp "Failed to find C+H comic strip at $url"; |
80
|
0
|
|
|
|
|
|
warn "Content was:\n$html\n"; |
81
|
0
|
|
|
|
|
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} else { |
85
|
0
|
|
|
|
|
|
carp "Failed to fetch $url - " . $response->status_line; |
86
|
0
|
|
|
|
|
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
David Precious, C<< >> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 BUGS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
100
|
|
|
|
|
|
|
C, |
101
|
|
|
|
|
|
|
or through the web interface at |
102
|
|
|
|
|
|
|
L. |
103
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
104
|
|
|
|
|
|
|
your bug as I make changes. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SUPPORT |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
perldoc WWW::Comic::Plugin::XKCD |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
You can also look for information at: |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over 4 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * CPAN Ratings |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * Search CPAN |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=back |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
To Nicola Worthington (NICOLAW) for writing WWW::Comic |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Copyright 2008 David Precious, all rights reserved. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
148
|
|
|
|
|
|
|
under the same terms as Perl itself. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; # End of WWW::Comic::Plugin::XKCD |