blib/lib/WWW/FetchStory/Fetcher/LiveJournal.pm

filter: Statementstmt 6.7% 12 / 178 Branchbran 0.0% 0 / 136 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 25.0% 3 / 12 Podpod 100% 9 / 9 totaltotal 6.8% 24 / 349 CC 72 SCAR 68.7
CC
72
Cov
4%
extract_story
1806.0
parse_chapter_urls
210.0
parse_title
110.0
CRAP 966.3
↑ Summary blib/lib/WWW/FetchStory/Fetcher/Teaspoon.pm »
1 package WWW::FetchStory::Fetcher::LiveJournal;
2 1 $WWW::FetchStory::Fetcher::LiveJournal::VERSION = '0.2001';
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 1 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 =head1 NAME
7  
8 WWW::FetchStory::Fetcher::LiveJournal - fetching module for WWW::FetchStory
9  
10 =head1 VERSION
11  
12 version 0.2001
13  
14 =head1 DESCRIPTION
15  
16 This is the LiveJournal story-fetching plugin for WWW::FetchStory.
17  
18 =cut
19  
20 1 our @ISA = qw(WWW::FetchStory::Fetcher);
21  
22 =head1 METHODS
23  
24 =head2 info
25  
26 Information about the fetcher.
27  
28 $info = $self->info();
29  
30 =cut
31  
32 sub info {
33 0 ▶ my $self = shift;
Subroutine info: not called CC=1 SCAR=6.9
Pod documented
34
35 0 my $info = "(http://www.livejournal.com/) Journalling site where some people post their fiction.";
36  
37 0 return $info;
38 } # info
39  
40 =head2 priority
41  
42 The priority of this fetcher. Fetchers with higher priority
43 get tried first. This is useful where there may be a generic
44 fetcher for a particular site, and then a more specialized fetcher
45 for particular sections of a site. For example, there may be a
46 generic LiveJournal fetcher, and then refinements for particular
47 LiveJournal community, such as the sshg_exchange community.
48 This works as either a class function or a method.
49  
50 This must be overridden by the specific fetcher class.
51  
52 $priority = $self->priority();
53  
54 $priority = WWW::FetchStory::Fetcher::priority($class);
55  
56 =cut
57  
58 sub priority {
59 0 ▶ my $class = shift;
Subroutine priority: not called CC=1 SCAR=6.9
Pod documented
60  
61 0 return 1;
62 } # priority
63  
64 =head2 allow
65  
66 If this fetcher can be used for the given URL, then this returns
67 true.
68 This must be overridden by the specific fetcher class.
69  
70 if ($obj->allow($url))
71 {
72 ....
73 }
74  
75 =cut
76  
77 sub allow {
78 0 ▶ my $self = shift;
Subroutine allow: not called CC=1 SCAR=6.9
Pod documented
79 0 my $url = shift;
80  
81 0 return ($url =~ /\.livejournal\.com/);
82 } # allow
83  
84 =head1 Private Methods
85  
86 =head2 extract_story
87  
88 Extract the story-content from the fetched content.
89  
90 my ($story, $title) = $self->extract_story(content=>$content,
91 title=>$title);
92  
93 =cut
94  
95 sub extract_story {
96 0 ▶ my $self = shift;
Subroutine extract_story: not called CC=42 SCAR=75.0
Pod documented
97 0 my %args = (
98 content=>'',
99 title=>'',
100 @_
101 );
102 0 my $content = $args{content};
103  
104 0 my $ljuser= '';
105 0 my $title = $args{title};
106 0 my $url = '';
107 0 ▶ if ($content =~ m#<title>([\w]+):\s*([^<]+)</title>#s)
Branch: 5 branches
BranchTrueFalseTotal
if ($content =~ m[<title>([\w]+):\s*([^<]+)</title>]s) { } 0 0 0
elsif ($content =~ m[<h1 class="b-singlepost-title">\s*([^<]+)\s*</h1>]s) { } 0 0 0
elsif ($content =~ m[<title>([^<]+)</title>]s) { } 0 0 0
elsif ($content =~ m[<h2 class="asset-name page-header2"><a href="([^"]+)">([^>]+)</a></h2>]) { } 0 0 0
elsif ($content =~ m[<div class="subject">([^<]+)</div>]) { } 0 0 0
108 {
109 0 $ljuser= $1;
110 0 $title = $2;
111 }
112 elsif ($content =~ m#<h1 class="b-singlepost-title">\s*([^<]+)\s*</h1>#s)
113 {
114 0 $title = $1;
115 }
116 elsif ($content =~ m#<title>([^<]+)</title>#s)
117 {
118 0 $title = $1;
119 }
120 elsif ($content =~ m#<h2 class="asset-name page-header2"><a href="([^"]+)">([^>]+)</a></h2>#)
121 {
122 0 $url = $1;
123 0 $title = $2;
124 }
125 elsif ($content =~ m#<div class="subject">([^<]+)</div>#)
126 {
127 0 $title = $1;
128 }
129 0 ▶ if ($content =~ m#([-\w]+)</b></a></span>\) wrote in <span class='ljuser'#s)
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ m[([-\w]+)</b></a></span>\) wrote in <span class='ljuser']s) 0 0 0
130 {
131 0 $ljuser = $1;
132 }
133  
134 0 ▶ if (!$url)
Branch: 1 branch
BranchTrueFalseTotal
unless ($url) 0 0 0
135 {
136 0 ▶ if ($content =~ m#(http://[-\w]+.livejournal.com/\d+\.html)\?format=light\&mode=reply#s)
Branch: 4 branches
BranchTrueFalseTotal
if ($content =~ m[(http://[-\w]+.livejournal.com/\d+\.html)\?format=light\&mode=reply]s) { } 0 0 0
elsif ($content =~ /<a[^>]*href=["']([^?\s]+)\?mode=reply["']\s*>Post a new comment/s) { } 0 0 0
elsif ($content =~ /<a[^>]*href=["']([^?\s]+)\?mode=reply/s) { } 0 0 0
elsif ($content =~ m[<a[^>]*href="([^?\s]+)"\s*>Link</a>]s) { } 0 0 0
137 {
138 0 $url = $1;
139 }
140 elsif ($content =~ m#<a[^>]*href=["']([^?\s]+)\?mode=reply["']\s*>Post a new comment#s)
141 {
142 0 $url = $1;
143 }
144 elsif ($content =~ m#<a[^>]*href=["']([^?\s]+)\?mode=reply#s)
145 {
146 0 $url = $1;
147 }
148 elsif ($content =~ m#<a[^>]*href="([^?\s]+)"\s*>Link</a>#s)
149 {
150 0 $url = $1;
151 }
152 }
153 0 ▶ if (!$ljuser && $url && ($url =~ m#http://([-\w]+)\.livejournal\.com#s))
Branch: 1 branch
BranchTrueFalseTotal
if (not $ljuser and $url and $url =~ m[http://([-\w]+)\.livejournal\.com]s) 0 0 0
Condition0%0/6
not $ljuser and $url and $url =~ m[http://([-\w]+)\.livejournal\.com]s
!ll&&!rl&&r
000
not $ljuser and $url
!ll&&!rl&&r
000
MC/DC0%0/3
not $ljuser and $url and $url =~ m[http://([-\w]+)\.livejournal\.com]s
not $ljuser $url $url =~ m[http://([-\w]+)\.livejournal\.com]s
Truth table0%0/4
not(A) and B and C
A= not $ljuserB= $urlC= $url =~ m[http://([-\w]+)\.livejournal\.com]s
ABCresult
0XX0
10X0
1100
1111
154 {
155 0 $ljuser = $1;
156 }
157  
158 0 my $story = '';
159 0 ▶ if ($content =~ m#<article class="\s*b-singlepost-body[^>]*>(.*?)</article>#s)
Branch: 22 branches
BranchTrueFalseTotal
if ($content =~ m[<article class="\s*b-singlepost-body[^>]*>(.*?)</article>]s) { } 0 0 0
elsif ($content =~ /<article class="\s*b-singlepost-body[^>]*>(.*?)<div class="\s*b-singlepost-tags ljtags\s*"/s) { } 0 0 0
elsif ($content =~ /<div class="b-singlepost-body">(.*?)<div id="comments"/s) { } 0 0 0
elsif ($content =~ m[</table><p>(.*)<br[^>]*/><hr[^>]*/><div id='Comments'>]s) { } 0 0 0
elsif ($content =~ /<div class="b-singlepost-body">(.*?)<div class="b-singlepost-tags ljtags">/s) { } 0 0 0
elsif ($content =~ m[<div class="b-singlepost-body">(.*?)</div>]s) { } 0 0 0
elsif ($content =~ /<div class="entrytext">(.*?)<div class="meta">/s) { } 0 0 0
elsif ($content =~ m[<div style='[^']+'>(.*)</div>\s*<br[^>]*/><hr[^>]*/><div id='Comments'>]s) { } 0 0 0
elsif ($content =~ m[</table></div>(.*)<br[^>]*/><hr[^>]*/><div id='Comments'>]s) { } 0 0 0
elsif ($content =~ m[<div class="asset-body">\s*<div class="user-icon"[^>]+>\s*<img[^>]+>\s*<br\s*/>\s*</div>(.*)</div>\s*<div class="lj-currents">]s) { } 0 0 0
elsif ($content =~ m[<td valign='top'>(<strong>.*)<strong>Current Mood:</strong>]s) { } 0 0 0
elsif ($content =~ m[<div\s*class="entryHeader">([^<]*)</div>.*?<td\s*class="entry">\s*(<div>.*?</div>)]s) { } 0 0 0
elsif ($content =~ /<div\s*class="asset-content">\s*(.*?)\s*<div class="lj-currents">/s) { } 0 0 0
elsif ($content =~ /<div\s*class="asset-content">\s*(.*?)\s*<div class="quickreply" id="ljqrtentrycomment"/s) { } 0 0 0
elsif ($content =~ m[<div\s*class="entryText">\s*(.*?)\s*</div>\s*<div class="entryMetadata">]s) { } 0 0 0
elsif ($content =~ m[<div\s*class="entryText">\s*(.*?)\s*</div>\s*<div class="entryFooter">]s) { } 0 0 0
elsif ($content =~ m[<b>Entry tags:</b>.*?</table>(.*?)<div class="ljad ljadleaderboard"]s) { } 0 0 0
elsif ($content =~ m[<b>Entry tags:</b>.*?</table>(.*?)<iframe src='http://ads.sixapart.com/]s) { } 0 0 0
elsif ($content =~ m[alt="Next Entry".*?</table>\s*</div>(.*?)<iframe src='http://ads.sixapart.com/]s) { } 0 0 0
elsif ($content =~ m[alt="Next Entry".*?</table>\s*</div>(.*?)<div id='Comments'>]s) { } 0 0 0
elsif ($content =~ /<div class="entry_text">(.*?)<div class="clear">/s) { } 0 0 0
elsif ($content =~ m[(<b>Tags</b>.*?)\s*<div class="quickreply" id="ljqrttopcomment"]s) { } 0 0 0
160 {
161 0 $story = $1;
162 }
163 elsif ($content =~ m#<article class="\s*b-singlepost-body[^>]*>(.*?)<div class="\s*b-singlepost-tags ljtags\s*"#s)
164 {
165 0 $story = $1;
166 }
167 elsif ($content =~ m#<div class="b-singlepost-body">(.*?)<div id="comments"#s)
168 {
169 0 $story = $1;
170 }
171 elsif ($content =~ m#</table><p>(.*)<br[^>]*/><hr[^>]*/><div id='Comments'>#s)
172 {
173 0 $story = $1;
174 }
175 elsif ($content =~ m#<div class="b-singlepost-body">(.*?)<div class="b-singlepost-tags ljtags">#s)
176 {
177 0 $story = $1;
178 }
179 elsif ($content =~ m#<div class="b-singlepost-body">(.*?)</div>#s)
180 {
181 0 $story = $1;
182 }
183 elsif ($content =~ m#<div class="entrytext">(.*?)<div class="meta">#s)
184 {
185 0 $story = $1;
186 }
187 elsif ($content =~ m#<div style='[^']+'>(.*)</div>\s*<br[^>]*/><hr[^>]*/><div id='Comments'>#s)
188 {
189 0 $story = $1;
190 }
191 elsif ($content =~ m#</table></div>(.*)<br[^>]*/><hr[^>]*/><div id='Comments'>#s)
192 {
193 0 $story = $1;
194 }
195 elsif ($content =~ m#<div class="asset-body">\s*<div class="user-icon"[^>]+>\s*<img[^>]+>\s*<br\s*/>\s*</div>(.*)</div>\s*<div class="lj-currents">#s)
196 {
197 0 $story = $1;
198 }
199 elsif ($content =~ m#<td valign='top'>(<strong>.*)<strong>Current Mood:</strong>#s)
200 {
201 0 $story = $1;
202 }
203 elsif ($content =~ m#<div\s*class="entryHeader">([^<]*)</div>.*?<td\s*class="entry">\s*(<div>.*?</div>)#s)
204 {
205 0 $title = $1;
206 0 $story = $2;
207 }
208 elsif ($content =~ m#<div\s*class="asset-content">\s*(.*?)\s*<div class="lj-currents">#s)
209 {
210 0 $story = $1;
211 }
212 elsif ($content =~ m#<div\s*class="asset-content">\s*(.*?)\s*<div class="quickreply" id="ljqrtentrycomment"#s)
213 {
214 0 $story = $1;
215 }
216 elsif ($content =~ m#<div\s*class="entryText">\s*(.*?)\s*</div>\s*<div class="entryMetadata">#s)
217 {
218 0 $story = $1;
219 }
220 elsif ($content =~ m#<div\s*class="entryText">\s*(.*?)\s*</div>\s*<div class="entryFooter">#s)
221 {
222 0 $story = $1;
223 }
224 elsif ($content =~ m#<b>Entry tags:</b>.*?</table>(.*?)<div class="ljad ljadleaderboard"#s)
225 {
226 0 $story = $1;
227 }
228 elsif ($content =~ m#<b>Entry tags:</b>.*?</table>(.*?)<iframe src='http://ads.sixapart.com/#s)
229 {
230 0 $story = $1;
231 }
232 elsif ($content =~ m#alt="Next Entry".*?</table>\s*</div>(.*?)<iframe src='http://ads.sixapart.com/#s)
233 {
234 0 $story = $1;
235 }
236 elsif ($content =~ m#alt="Next Entry".*?</table>\s*</div>(.*?)<div id='Comments'>#s)
237 {
238 0 $story = $1;
239 }
240 elsif ($content =~ m#<div class="entry_text">(.*?)<div class="clear">#s)
241 {
242 0 $story = $1;
243 }
244 elsif ($content =~ m#(<b>Tags</b>.*?)\s*<div class="quickreply" id="ljqrttopcomment"#s)
245 {
246 0 $story = $1;
247 }
248 0 ▶ warn "ljuser=$ljuser, title=$title\n" if ($self->{verbose} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 0 0
249 0 ▶ warn "url=$url\n" if ($self->{verbose} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 0 0
250 0 ▶ if ($story)
Branch: 1 branch
BranchTrueFalseTotal
if ($story) { } 0 0 0
251 {
252 # remove LJ-specific cruft
253 0 $story =~ s#<a name="cutid."></a>##sg;
254 0 $story =~ s#<a name='cutid.-end'></a>##sg;
255 0 $story =~ s#<center><div class="lj-like">.*</center>##sg;
256 0 $story =~ s#<a href="http://[A-Za-z_-]+\.livejournal\.com/profile"[^>]*>\s*<img\s*class="i-ljuser-userhead"[^>]*/>\s*</a>##sg;
257  
258 0 $story = $self->tidy_chars($story);
259 }
260 else
261 {
262 0 print STDERR "story not found\n";
263 0 ▶ print STDERR "\n==============\n${content}\n===========\n" if ($self->{debug});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
264 0 return $self->tidy_chars($content);
265 }
266  
267 0 my $out = <<EOT;
268 <h1>$title</h1>
269 EOT
270 0 ▶ if ($url)
Branch: 1 branch
BranchTrueFalseTotal
if ($url) 0 0 0
271 {
272 0 $out .= <<EOT;
273 <p>(from <a href='$url'>$url</a>)</p>
274 EOT
275 }
276 0 $out .= <<EOT;
277 <p>$story
278 EOT
279 0 return ($out, $title);
280 } # extract_story
281  
282 =head2 get_toc
283  
284 Get a table-of-contents page.
285  
286 =cut
287 sub get_toc {
288 0 ▶ my $self = shift;
Subroutine get_toc: not called CC=1 SCAR=6.9
Pod documented
289 0 my $url = shift;
290  
291 0 return $self->get_page("${url}?format=light");
292 } # get_toc
293  
294 =head2 parse_author
295  
296 Get the author from the content
297  
298 =cut
299 sub parse_author {
300 0 ▶ my $self = shift;
Subroutine parse_author: not called CC=5 SCAR=34.0
Pod documented
301 0 my %args = (
302 url=>'',
303 content=>'',
304 @_
305 );
306  
307 0 my $content = $args{content};
308 0 my $author = '';
309 0 ▶ if ($content =~ m#<b>Author: </b> <span\s+class="ljuser\s+i-ljuser\s+"\s+lj:user="([-_\w]+)"#)
Branch: 4 branches
BranchTrueFalseTotal
if ($content =~ m[<b>Author: </b> <span\s+class="ljuser\s+i-ljuser\s+"\s+lj:user="([-_\w]+)"]) { } 0 0 0
elsif ($content =~ m[<b>Creator:\s*</b>\s*<span\s+class="ljuser\s+i-ljuser\s+"\s+lj:user="([-_\w]+)"]) { } 0 0 0
elsif ($content =~ m(<span class='ljuser ljuser-name_\w+' lj:user='\w+' style='white-space: nowrap;'><a href='http://\w+\.livejournal\.com/profile'><img src='http://l-stat\.livejournal\.com/img/userinfo\.gif' alt='\[info\]' width='17' height='17' style='vertical-align: bottom; border: 0; padding-right: 1px;' /></a><a href='http://\w+\.livejournal\.com/'><b>(.*?)</b></a></span>)) { } 0 0 0
elsif ($content =~ m[<a href='http://[-\w]+\.livejournal\.com/'><b>(.*?)</b></a>]) { } 0 0 0
310 {
311 0 $author = $1;
312 }
313 elsif ($content =~ m#<b>Creator:\s*</b>\s*<span\s+class="ljuser\s+i-ljuser\s+"\s+lj:user="([-_\w]+)"#)
314 {
315 0 $author = $1;
316 }
317 elsif ($content =~ m#<span class='ljuser ljuser-name_\w+' lj:user='\w+' style='white-space: nowrap;'><a href='http://\w+\.livejournal\.com/profile'><img src='http://l-stat\.livejournal\.com/img/userinfo\.gif' alt='\[info\]' width='17' height='17' style='vertical-align: bottom; border: 0; padding-right: 1px;' /></a><a href='http://\w+\.livejournal\.com/'><b>(.*?)</b></a></span>#)
318 {
319 0 $author = $1;
320 }
321 elsif ($content =~ m#<a href='http://[-\w]+\.livejournal\.com/'><b>(.*?)</b></a>#)
322 {
323 0 $author = $1;
324 }
325 else
326 {
327 0 $author = $self->SUPER::parse_author(%args);
328 }
329 0 return $author;
330 } # parse_author
331  
332 =head2 parse_title
333  
334 Get the title from the content
335  
336 =cut
337 sub parse_title {
338 0 ▶ my $self = shift;
Subroutine parse_title: not called CC=10 SCAR=47.0
Pod documented
339 0 my %args = (
340 content=>'',
341 @_
342 );
343  
344 0 my $content = $args{content};
345 0 my $title = '';
346 0 ▶ if ($content =~ /<(?:b|strong)>Title:?\s*<\/(?:b|strong)>:?\s*"?(.*?)"?\s*<(?:br|p|\/p|div|\/div)/si)
Branch: 9 branches
BranchTrueFalseTotal
if ($content =~ m[<(?:b|strong)>Title:?\s*</(?:b|strong)>:?\s*"?(.*?)"?\s*<(?:br|p|/p|div|/div)]is) { } 0 0 0
elsif ($content =~ /\bTitle:\s*"?(.*?)"?\s*<br/s) { } 0 0 0
elsif ($content =~ m[<title>[\w]+:\s*([^<]+)</title>]s) { } 0 0 0
elsif ($content =~ m[<h1 class="b-singlepost-title">\s*([^<]+)\s*</h1>]s) { } 0 0 0
elsif ($content =~ m[<title>([^<]+)</title>]s) { } 0 0 0
elsif ($content =~ m[<h2 class="asset-name page-header2"><a href="([^"]+)">([^>]+)</a></h2>]) { } 0 0 0
elsif ($content =~ m[<div class="subject">([^<]+)</div>]) { } 0 0 0
elsif ($content =~ m[<h1>([^<]+)</h1>]is) { } 0 0 0
elsif ($content =~ m[<h2>([^<]+)</h2>]is) { } 0 0 0
347 {
348 0 $title = $1;
349 }
350 elsif ($content =~ /\bTitle:\s*"?(.*?)"?\s*<br/s)
351 {
352 0 $title = $1;
353 }
354 elsif ($content =~ m#<title>[\w]+:\s*([^<]+)</title>#s)
355 {
356 0 $title = $1;
357 }
358 elsif ($content =~ m#<h1 class="b-singlepost-title">\s*([^<]+)\s*</h1>#s)
359 {
360 0 $title = $1;
361 }
362 elsif ($content =~ m#<title>([^<]+)</title>#s)
363 {
364 0 $title = $1;
365 }
366 elsif ($content =~ m#<h2 class="asset-name page-header2"><a href="([^"]+)">([^>]+)</a></h2>#)
367 {
368 0 $title = $2;
369 }
370 elsif ($content =~ m#<div class="subject">([^<]+)</div>#)
371 {
372 0 $title = $1;
373 }
374 elsif ($content =~ m#<h1>([^<]+)</h1>#is)
375 {
376 0 $title = $1;
377 }
378 elsif ($content =~ m#<h2>([^<]+)</h2>#is)
379 {
380 0 $title = $1;
381 }
382 0 $title = decode_entities($title); # get rid of HTML entities in the title
383 0 $title =~ s/<u>//ig;
384 0 $title =~ s/<\/u>//ig;
385 0 return $title;
386 } # parse_title
387  
388 =head2 parse_toc
389  
390 Parse the table-of-contents file.
391  
392 %info = $self->parse_toc(content=>$content,
393 url=>$url,
394 urls=>\@urls);
395  
396 This should return a hash containing:
397  
398 =over
399  
400 =item chapters
401  
402 An array of URLs for the chapters of the story. In the case where the
403 story only takes one page, that will be the chapter.
404 In the case where multiple URLs have been passed in, it will be those URLs.
405  
406 =item title
407  
408 The title of the story.
409  
410 =back
411  
412 It may also return additional information, such as Summary.
413  
414 =cut
415  
416 sub parse_toc {
417 0 ▶ my $self = shift;
Subroutine parse_toc: not called CC=5 SCAR=34.0
Pod documented
418 0 my %args = (
419 url=>'',
420 content=>'',
421 @_
422 );
423  
424 0 my $content = $args{content};
425 0 my $user = '';
426 0 my $is_community = 0;
427 0 ▶ if ($args{url} =~ m{http://([-\w]+)\.livejournal\.com})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"url"} =~ m[http://([-\w]+)\.livejournal\.com]) 0 0 0
428 {
429 0 $user = $1;
430 }
431 0 ▶ if ($user eq 'community')
Branch: 1 branch
BranchTrueFalseTotal
if ($user eq "community") 0 0 0
432 {
433 0 $is_community = 1;
434 0 $user = '';
435 0 ▶ if ($args{url} =~ m{http://community\.livejournal\.com/([-\w]+)})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"url"} =~ m[http://community\.livejournal\.com/([-\w]+)]) 0 0 0
436 {
437 0 $user = $1;
438 }
439 }
440  
441 0 my %info = ();
442 0 $info{url} = $args{url};
443 0 $info{toc_first} = 1;
444  
445 0 my $title = $self->parse_title(%args);
446 0 $title =~ s/${user}:\s*//;
447 0 $title =~ s/Fic:\s*//;
448 0 $info{title} = $title;
449  
450 0 my $summary = $self->parse_summary(%args);
451 0 $summary =~ s/"/'/g;
452 0 $info{summary} = $summary;
453  
454 0 my $author = $self->parse_author(%args);
455 0 ▶ if (!$author)
Branch: 1 branch
BranchTrueFalseTotal
unless ($author) 0 0 0
456 {
457 0 $author = $user;
458 }
459 0 $info{author} = $author;
460  
461 0 my $characters = $self->parse_characters(%args);
462 0 $info{characters} = $characters;
463  
464 0 $info{universe} = $self->parse_universe(%args);
465 0 $info{chapters} = $self->parse_chapter_urls(%args, user=>$user,
466 is_community=>$is_community);
467  
468 0 return %info;
469 } # parse_toc
470  
471 =head2 parse_chapter_urls
472  
473 Figure out the URLs for the chapters of this story.
474  
475 =cut
476 sub parse_chapter_urls {
477 0 ▶ my $self = shift;
Subroutine parse_chapter_urls: not called CC=14 SCAR=53.5
Pod documented
478 0 my %args = (
479 url=>'',
480 content=>'',
481 @_
482 );
483 0 my $content = $args{content};
484 0 my $user = $args{user};
485 0 my @chapters = ();
486  
487 # avoid adding duplicate URLs by remembering what we've parsed
488 0 my %remember_ch_urls = ();
489 0 $remember_ch_urls{$args{url}} = 1;
490  
491 0 ▶ if (defined $args{urls})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"urls"}) 0 0 0
492 {
493 0 @chapters = @{$args{urls}};
494 0 ▶ for (my $i = 0; $i < @chapters; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @chapters) 0 0 0
495 {
496 0 $chapters[$i] = sprintf('%s?format=light', $chapters[$i]);
497 }
498 }
499 0 ▶ if (@chapters <= 1 and $user)
Branch: 1 branch
BranchTrueFalseTotal
if (@chapters <= 1 and $user) 0 0 0
Condition0%0/3
@chapters <= 1 and $user
!ll&&!rl&&r
000
MC/DC0%0/2
@chapters <= 1 and $user
@chapters <= 1 $user
Truth table0%0/3
A and B
A= @chapters <= 1B= $user
ABresult
0X0
100
111
500 {
501 0 ▶ warn "parse_chapter_urls: user=$user\n" if ($self->{verbose} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 0 0
502 0 ▶ if ($args{is_community})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'is_community'}) { } 0 0 0
503 {
504 0 ▶ while ($content =~ m/href="(http:\/\/community\.livejournal\.com\/${user}\/\d+.html)/sg)
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ m[href="(http://community\.livejournal\.com/$user/\d+.html)]gs) 0 0 0
505 {
506 0 my $ch_url = $1;
507 0 ▶ if (!$remember_ch_urls{$ch_url})
Branch: 1 branch
BranchTrueFalseTotal
unless ($remember_ch_urls{$ch_url}) 0 0 0
508 {
509 0 ▶ warn "chapter=$ch_url\n" if ($self->{verbose} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 0 0
510 0 push @chapters, "${ch_url}?format=light";
511 0 $remember_ch_urls{$ch_url} = 1;
512 }
513 }
514 }
515 else
516 {
517 0 ▶ while ($content =~ m/<a\s+href="(http:\/\/${user}\.livejournal\.com\/\d+.html)"\s*([^>]*)>/sg)
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ m[<a\s+href="(http://$user\.livejournal\.com/\d+.html)"\s*([^>]*)>]gs) 0 0 0
518 {
519 0 my $ch_url = $1;
520 0 my $rest = $2;
521 0 ▶ if ($rest =~ /prevnext-link/)
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /prevnext-link/) { } 0 0 0
522 {
523 # it's a prev-next link, ignore it
524 }
525 else
526 {
527 0 ▶ warn "chapter='$ch_url'\n" if ($self->{verbose} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 0 0
528 0 ▶ if (!$remember_ch_urls{$ch_url})
Branch: 1 branch
BranchTrueFalseTotal
unless ($remember_ch_urls{$ch_url}) 0 0 0
529 {
530 0 push @chapters, "${ch_url}?format=light";
531 0 $remember_ch_urls{$ch_url} = 1;
532 }
533 }
534 }
535 }
536 }
537  
538 0 return \@chapters;
539 } # parse_chapter_urls
540  
541 1 1; # End of WWW::FetchStory::Fetcher::LiveJournal
542 __END__
↑ Summary blib/lib/WWW/FetchStory/Fetcher/Teaspoon.pm »