WWW/FetchStory/Fetcher/Owl.pm

filter: Statementstmt 12.2% 11 / 90 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 25.0% 3 / 12 Podpod 100% 9 / 9 totaltotal 17.0% 23 / 135 CC 13 SCAR 27.0
CC
13
Cov
10%
extract_story
30.0
parse_chapter_urls
30.0
parse_toc
6.0
CRAP 14.9
« WWW/FetchStory/Fetcher/PotterPlace.pm ↑ Summary WWW/FetchStory/Fetcher/DigitalQuill.pm »
1 package WWW::FetchStory::Fetcher::Owl;
2 1 $WWW::FetchStory::Fetcher::Owl::VERSION = '0.2602';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 =head1 NAME
6  
7 WWW::FetchStory::Fetcher::Owl - fetching module for WWW::FetchStory
8  
9 =head1 VERSION
10  
11 version 0.2602
12  
13 =head1 DESCRIPTION
14  
15 This is the Owl story-fetching plugin for WWW::FetchStory.
16  
17 =cut
18  
19 1 ▶use parent qw(WWW::FetchStory::Fetcher);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 =head2 info
22  
23 Information about the fetcher.
24  
25 $info = $self->info();
26  
27 =cut
28  
29 0 ▶sub info {
Subroutine info: not called CC=1 SCAR=6.9
Pod documented
30 0 my $self = shift;
31
32 0 my $info = "(http://owl.tauri.org/) A Harry Potter fiction archive.";
33  
34 0 return $info;
35 } # info
36  
37 =head2 priority
38  
39 The priority of this fetcher. Fetchers with higher priority
40 get tried first. This is useful where there may be a generic
41 fetcher for a particular site, and then a more specialized fetcher
42 for particular sections of a site. For example, there may be a
43 generic Owl fetcher, and then refinements for particular
44 Owl community, such as the sshg_exchange community.
45 This works as either a class function or a method.
46  
47 This must be overridden by the specific fetcher class.
48  
49 $priority = $self->priority();
50  
51 $priority = WWW::FetchStory::Fetcher::priority($class);
52  
53 =cut
54  
55 0 ▶sub priority {
Subroutine priority: not called CC=1 SCAR=6.9
Pod documented
56 0 my $class = shift;
57  
58 0 return 1;
59 } # priority
60  
61 =head2 allow
62  
63 If this fetcher can be used for the given URL, then this returns
64 true.
65 This must be overridden by the specific fetcher class.
66  
67 if ($obj->allow($url))
68 {
69 ....
70 }
71  
72 =cut
73  
74 0 ▶sub allow {
Subroutine allow: not called CC=1 SCAR=6.9
Pod documented
75 0 my $self = shift;
76 0 my $url = shift;
77  
78 0 return ($url =~ /owl\.tauri\.org/);
79 } # allow
80  
81 =head1 Private Methods
82  
83 =head2 extract_story
84  
85 Extract the story-content from the fetched content.
86  
87 my ($story, $title) = $self->extract_story(content=>$content,
88 title=>$title);
89  
90 =cut
91  
92 0 ▶sub extract_story {
Subroutine extract_story: not called CC=5 SCAR=34.0
Pod documented
93 0 my $self = shift;
94 0 my %args = (
95 content=>'',
96 title=>'',
97 @_
98 );
99  
100 0 my $content = $args{content};
101 0 my $story = '';
102 0 my $title = '';
103 0 ▶ if ($content =~ m#<title>OWL\s*::\s*([^<]+)</title>#)
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ m[<title>OWL\s*::\s*([^<]+)</title>]) { } 0 0 0
104 {
105 0 $title = $1;
106 }
107 else
108 {
109 0 $title = $args{title};
110 }
111  
112 0 ▶ if ($content =~ m#<div class=pagehead></div>(.*?)<div align=left><span class=credits>#s)
Branch: 2 branches
BranchTrueFalseTotal
if ($content =~ m[<div class=pagehead></div>(.*?)<div align=left><span class=credits>]s) { } 0 0 0
elsif ($content =~ m[<body[^>]*>(.*)</body>]is) { } 0 0 0
113 {
114 0 $story = $1;
115 }
116 elsif ($content =~ m#<body[^>]*>(.*)</body>#is)
117 {
118 0 $story = $1;
119 }
120  
121 0 ▶ if ($story)
Branch: 1 branch
BranchTrueFalseTotal
if ($story) { } 0 0 0
122 {
123 0 $story = $self->tidy_chars($story);
124 }
125 else
126 {
127 0 $story = $content;
128 }
129  
130 0 return ($story, $title);
131 } # extract_story
132  
133 =head2 parse_toc
134  
135 Parse the table-of-contents file.
136  
137 %info = $self->parse_toc(content=>$content,
138 url=>$url,
139 urls=>\@urls);
140  
141 This should return a hash containing:
142  
143 =over
144  
145 =item chapters
146  
147 An array of URLs for the chapters of the story. In the case where the
148 story only takes one page, that will be the chapter.
149 In the case where multiple URLs have been passed in, it will be those URLs.
150  
151 =item title
152  
153 The title of the story.
154  
155 =back
156  
157 It may also return additional information, such as Summary.
158  
159 =cut
160  
161 0 ▶sub parse_toc {
Subroutine parse_toc: not called CC=2 SCAR=17.9
Pod documented
162 0 my $self = shift;
163 0 my %args = (
164 url=>'',
165 content=>'',
166 @_
167 );
168  
169 0 my %info = ();
170 0 my $content = $args{content};
171 0 $info{url} = $args{url};
172 0 my $sid='';
173 0 ▶ if ($args{url} =~ m#psid=(\d+)#)
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'url'} =~ /psid=(\d+)/) { } 0 0 0
174 {
175 0 $sid = $1;
176 }
177 else
178 {
179 0 return $self->SUPER::parse_toc(%args);
180 }
181  
182 0 $info{title} = $self->parse_title(%args);
183 0 $info{author} = $self->parse_author(%args);
184 0 $info{summary} = $self->parse_summary(%args);
185 0 $info{characters} = $self->parse_characters(%args);
186 0 $info{universe} = 'Harry Potter';
187 0 $info{chapters} = $self->parse_chapter_urls(%args, sid=>$sid);
188  
189 0 return %info;
190 } # parse_toc
191  
192 =head2 parse_chapter_urls
193  
194 Figure out the URLs for the chapters of this story.
195  
196 =cut
197 0 ▶sub parse_chapter_urls {
Subroutine parse_chapter_urls: not called CC=5 SCAR=34.0
Pod documented
198 0 my $self = shift;
199 0 my %args = (
200 url=>'',
201 content=>'',
202 @_
203 );
204 0 my $content = $args{content};
205 0 my $sid = $args{sid};
206 0 my @chapters = ();
207 0 ▶ if (defined $args{urls})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"urls"}) 0 0 0
208 {
209 0 @chapters = @{$args{urls}};
210 }
211 0 ▶ if (@chapters == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@chapters == 1) 0 0 0
212 {
213 0 @chapters = ();
214 # Owl does not have a sane chapter system
215 0 my $fmt = 'http://owl.tauri.org/stories.php?sid=%d&action=print';
216 0 ▶ while ($content =~ m#stories.php\?sid=(\d+)#sg)
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /stories.php\?sid=(\d+)/gs) 0 0 0
217 {
218 0 my $ch_sid = $1;
219 0 my $ch_url = sprintf($fmt, $ch_sid);
220 0 ▶ warn "chapter=$ch_url\n" if ($self->{verbose} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 0 0
221 0 push @chapters, $ch_url;
222 }
223 }
224  
225 0 return \@chapters;
226 } # parse_chapter_urls
227  
228 =head2 parse_title
229  
230 Get the title from the content
231  
232 =cut
233 0 ▶sub parse_title {
Subroutine parse_title: not called CC=2 SCAR=17.9
Pod documented
234 0 my $self = shift;
235 0 my %args = (
236 url=>'',
237 content=>'',
238 @_
239 );
240  
241 0 my $content = $args{content};
242 0 my $title = $self->SUPER::parse_title(%args);
243 0 ▶ if ($title =~ m#OWL\s*::\s*([^<]+)#)
Branch: 1 branch
BranchTrueFalseTotal
if ($title =~ /OWL\s*::\s*([^<]+)/) 0 0 0
244 {
245 0 $title = $1;
246 }
247 0 return $title;
248 } # parse_title
249  
250 =head2 parse_author
251  
252 Get the author from the content
253  
254 =cut
255 0 ▶sub parse_author {
Subroutine parse_author: not called CC=2 SCAR=17.9
Pod documented
256 0 my $self = shift;
257 0 my %args = (
258 url=>'',
259 content=>'',
260 @_
261 );
262  
263 0 my $content = $args{content};
264 0 my $author = '';
265 0 ▶ if ($content =~ m#by <a href="users.php\?uid=\d+">([^<]+)</a>#s)
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ m[by <a href="users.php\?uid=\d+">([^<]+)</a>]s) { } 0 0 0
266 {
267 0 $author = $1;
268 }
269 else
270 {
271 0 $author = $self->SUPER::parse_author(%args);
272 }
273 0 return $author;
274 } # parse_author
275  
276 =head2 parse_summary
277  
278 Get the summary from the content
279  
280 =cut
281 0 ▶sub parse_summary {
Subroutine parse_summary: not called CC=2 SCAR=17.9
Pod documented
282 0 my $self = shift;
283 0 my %args = (
284 url=>'',
285 content=>'',
286 @_
287 );
288  
289 0 my $content = $args{content};
290 0 my $summary = '';
291 0 ▶ if ($content =~ m#<span class=summary>([^<]+)</span>#s)
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ m[<span class=summary>([^<]+)</span>]s) { } 0 0 0
292 {
293 0 $summary = $1;
294 }
295 else
296 {
297 0 $summary = $self->SUPER::parse_summary(%args);
298 }
299 0 return $summary;
300 } # parse_summary
301  
302 1 1; # End of WWW::FetchStory::Fetcher::Owl
303 __END__
« WWW/FetchStory/Fetcher/PotterPlace.pm ↑ Summary WWW/FetchStory/Fetcher/DigitalQuill.pm »