blib/lib/WWW/Comic/Plugin/f8d.pm

filter: Statementstmt 83.7% 31 / 37 Branchbran 37.5% 3 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 79.2% 42 / 53 CC 5 SCAR 14.0
CC
5
Cov
76%
strip_url
7.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.1
↑ Summary
1 package WWW::Comic::Plugin::f8d;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use vars qw($VERSION @ISA %COMICS);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 our $VERSION = '0.02';
9 3 @ISA = qw(WWW::Comic::Plugin);
10 3 %COMICS = (f8d => 'f8d - minimalist and esoteric webcomic');
11  
12 # $Id: f8d.pm 733 2009-09-17 13:31:20Z davidp $
13  
14 =head1 NAME
15  
16 WWW::Comic::Plugin::f8d - WWW::Comic plugin to fetch f8d comic
17  
18  
19 =head1 SYNOPSIS
20  
21 See L<WWW::Comic> 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 => 'f8d');
27
28  
29 =head1 DESCRIPTION
30  
31 A plugin for L<WWW::Comic> to fetch the f8d comic from http://www.f8d.org/
32  
33 See L<WWW::Comic> and L<WWW::Comic::Plugin> 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<WWW::Comic> for usage
44  
45 =cut
46  
47  
48 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
49 1 my $class = shift;
50 1 my $self = { homepage => 'http://www.f8d.org/' };
51 1 bless $self, $class;
52 1 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 1 ▶sub strip_url {
Subroutine strip_url: called CC=5 SCAR=19.6
Pod documented
63 1 my $self = shift;
64 1 my %param = @_;
65  
66 1 my $url = $self->{homepage};
67 1 ▶ $url .= "?c=$param{id}/" if $param{id};
Branch: 1 branch
BranchTrueFalseTotal
if $param{"id"} 0 1 1
68
69 1 my $response = $self->_new_agent->get($url);
70 1 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 1 0 1
71 1 my $html = $response->content;
72 1 ▶ if ($html =~ m{<img src="(.+?)" title}i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html =~ /<img src="(.+?)" title/i) { } 0 1 1
73 0 my $stripurl = $1;
74 0 ▶ if (!$stripurl !~ /^http/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not !$stripurl =~ /^http/) 0 0 0
75 0 $stripurl = "http://f8d.org" . $stripurl;
76 0 return $stripurl;
77 }
78 } else {
79 1 carp "Failed to find f8d comic strip at $url";
80 1 warn "Content was:\n$html\n";
81 1 return;
82 }
83
84 } else {
85 0 carp "Failed to fetch $url - " . $response->status_line;
86 0 return;
87 }
88
89 }
90  
91  
92  
93 =back
94  
95 =head1 AUTHOR
96  
97 David Precious, C<< <davidp at preshweb.co.uk> >>
98  
99 =head1 BUGS
100  
101 Please report any bugs or feature requests to
102 C<bug-www-comic-plugin-f8d at rt.cpan.org>,
103 or through the web interface at
104 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Comic-Plugin-f8d>.
105 I will be notified, and then you'll automatically be notified of progress on
106 your bug as I make changes.
107  
108  
109  
110  
111 =head1 SUPPORT
112  
113 You can find documentation for this module with the perldoc command.
114  
115 perldoc WWW::Comic::Plugin::f8d
116  
117  
118 You can also look for information at:
119  
120 =over 4
121  
122 =item * RT: CPAN's request tracker
123  
124 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Comic-Plugin-f8d>
125  
126 =item * AnnoCPAN: Annotated CPAN documentation
127  
128 L<http://annocpan.org/dist/WWW-Comic-Plugin-f8d>
129  
130 =item * CPAN Ratings
131  
132 L<http://cpanratings.perl.org/d/WWW-Comic-Plugin-f8d>
133  
134 =item * Search CPAN
135  
136 L<http://search.cpan.org/dist/WWW-Comic-Plugin-f8d>
137  
138 =back
139  
140  
141 =head1 ACKNOWLEDGEMENTS
142  
143 To Nicola Worthington (NICOLAW) for writing WWW::Comic
144  
145 =head1 COPYRIGHT & LICENSE
146  
147 Copyright 2008-09 David Precious, all rights reserved.
148  
149 This program is free software; you can redistribute it and/or modify it
150 under the same terms as Perl itself.
151  
152  
153 =cut
154  
155 3 1; # End of WWW::Comic::Plugin::f8d
↑ Summary