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

filter: Statementstmt 6.5% 12 / 182 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 / 353 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.2004';
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.2004
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 ▶ if ($self->{debug})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'debug'}) { } 0 0 0
263 {
264 0 open(my $fh, ">", "FS$$.html");
265 0 print $fh $content;
266 0 close $fh;
267 0 die "STORY not found. Content is in FS$$.html"
268 }
269 else
270 {
271 0 print STDERR "story not found\n";
272 0 return $self->tidy_chars($content);
273 }
274 }
275  
276 0 my $out = <<EOT;
277 <h1>$title</h1>
278 EOT
279 0 ▶ if ($url)
Branch: 1 branch
BranchTrueFalseTotal
if ($url) 0 0 0
280 {
281 0 $out .= <<EOT;
282 <p>(from <a href='$url'>$url</a>)</p>
283 EOT
284 }
285 0 $out .= <<EOT;
286 <p>$story
287 EOT
288 0 return ($out, $title);
289 } # extract_story
290  
291 =head2 get_toc
292  
293 Get a table-of-contents page.
294  
295 =cut
296 sub get_toc {
297 0 ▶ my $self = shift;
Subroutine get_toc: not called CC=1 SCAR=6.9
Pod documented
298 0 my $url = shift;
299  
300 0 return $self->get_page("${url}?format=light");
301 } # get_toc
302  
303 =head2 parse_author
304  
305 Get the author from the content
306  
307 =cut
308 sub parse_author {
309 0 ▶ my $self = shift;
Subroutine parse_author: not called CC=5 SCAR=34.0
Pod documented
310 0 my %args = (
311 url=>'',
312 content=>'',
313 @_
314 );
315  
316 0 my $content = $args{content};
317 0 my $author = '';
318 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
319 {
320 0 $author = $1;
321 }
322 elsif ($content =~ m#<b>Creator:\s*</b>\s*<span\s+class="ljuser\s+i-ljuser\s+"\s+lj:user="([-_\w]+)"#)
323 {
324 0 $author = $1;
325 }
326 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>#)
327 {
328 0 $author = $1;
329 }
330 elsif ($content =~ m#<a href='http://[-\w]+\.livejournal\.com/'><b>(.*?)</b></a>#)
331 {
332 0 $author = $1;
333 }
334 else
335 {
336 0 $author = $self->SUPER::parse_author(%args);
337 }
338 0 return $author;
339 } # parse_author
340  
341 =head2 parse_title
342  
343 Get the title from the content
344  
345 =cut
346 sub parse_title {
347 0 ▶ my $self = shift;
Subroutine parse_title: not called CC=10 SCAR=47.0
Pod documented
348 0 my %args = (
349 content=>'',
350 @_
351 );
352  
353 0 my $content = $args{content};
354 0 my $title = '';
355 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
356 {
357 0 $title = $1;
358 }
359 elsif ($content =~ /\bTitle:\s*"?(.*?)"?\s*<br/s)
360 {
361 0 $title = $1;
362 }
363 elsif ($content =~ m#<title>[\w]+:\s*([^<]+)</title>#s)
364 {
365 0 $title = $1;
366 }
367 elsif ($content =~ m#<h1 class="b-singlepost-title">\s*([^<]+)\s*</h1>#s)
368 {
369 0 $title = $1;
370 }
371 elsif ($content =~ m#<title>([^<]+)</title>#s)
372 {
373 0 $title = $1;
374 }
375 elsif ($content =~ m#<h2 class="asset-name page-header2"><a href="([^"]+)">([^>]+)</a></h2>#)
376 {
377 0 $title = $2;
378 }
379 elsif ($content =~ m#<div class="subject">([^<]+)</div>#)
380 {
381 0 $title = $1;
382 }
383 elsif ($content =~ m#<h1>([^<]+)</h1>#is)
384 {
385 0 $title = $1;
386 }
387 elsif ($content =~ m#<h2>([^<]+)</h2>#is)
388 {
389 0 $title = $1;
390 }
391 0 $title = decode_entities($title); # get rid of HTML entities in the title
392 0 $title =~ s/<u>//ig;
393 0 $title =~ s/<\/u>//ig;
394 0 return $title;
395 } # parse_title
396  
397 =head2 parse_toc
398  
399 Parse the table-of-contents file.
400  
401 %info = $self->parse_toc(content=>$content,
402 url=>$url,
403 urls=>\@urls);
404  
405 This should return a hash containing:
406  
407 =over
408  
409 =item chapters
410  
411 An array of URLs for the chapters of the story. In the case where the
412 story only takes one page, that will be the chapter.
413 In the case where multiple URLs have been passed in, it will be those URLs.
414  
415 =item title
416  
417 The title of the story.
418  
419 =back
420  
421 It may also return additional information, such as Summary.
422  
423 =cut
424  
425 sub parse_toc {
426 0 ▶ my $self = shift;
Subroutine parse_toc: not called CC=5 SCAR=34.0
Pod documented
427 0 my %args = (
428 url=>'',
429 content=>'',
430 @_
431 );
432  
433 0 my $content = $args{content};
434 0 my $user = '';
435 0 my $is_community = 0;
436 0 ▶ if ($args{url} =~ m{http://([-\w]+)\.livejournal\.com})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"url"} =~ m[http://([-\w]+)\.livejournal\.com]) 0 0 0
437 {
438 0 $user = $1;
439 }
440 0 ▶ if ($user eq 'community')
Branch: 1 branch
BranchTrueFalseTotal
if ($user eq "community") 0 0 0
441 {
442 0 $is_community = 1;
443 0 $user = '';
444 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
445 {
446 0 $user = $1;
447 }
448 }
449  
450 0 my %info = ();
451 0 $info{url} = $args{url};
452 0 $info{toc_first} = 1;
453  
454 0 my $title = $self->parse_title(%args);
455 0 $title =~ s/${user}:\s*//;
456 0 $title =~ s/Fic:\s*//;
457 0 $info{title} = $title;
458  
459 0 my $summary = $self->parse_summary(%args);
460 0 $summary =~ s/"/'/g;
461 0 $info{summary} = $summary;
462  
463 0 my $author = $self->parse_author(%args);
464 0 ▶ if (!$author)
Branch: 1 branch
BranchTrueFalseTotal
unless ($author) 0 0 0
465 {
466 0 $author = $user;
467 }
468 0 $info{author} = $author;
469  
470 0 my $characters = $self->parse_characters(%args);
471 0 $info{characters} = $characters;
472  
473 0 $info{universe} = $self->parse_universe(%args);
474 0 $info{chapters} = $self->parse_chapter_urls(%args, user=>$user,
475 is_community=>$is_community);
476  
477 0 return %info;
478 } # parse_toc
479  
480 =head2 parse_chapter_urls
481  
482 Figure out the URLs for the chapters of this story.
483  
484 =cut
485 sub parse_chapter_urls {
486 0 ▶ my $self = shift;
Subroutine parse_chapter_urls: not called CC=14 SCAR=53.5
Pod documented
487 0 my %args = (
488 url=>'',
489 content=>'',
490 @_
491 );
492 0 my $content = $args{content};
493 0 my $user = $args{user};
494 0 my @chapters = ();
495  
496 # avoid adding duplicate URLs by remembering what we've parsed
497 0 my %remember_ch_urls = ();
498 0 $remember_ch_urls{$args{url}} = 1;
499  
500 0 ▶ if (defined $args{urls})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"urls"}) 0 0 0
501 {
502 0 @chapters = @{$args{urls}};
503 0 ▶ for (my $i = 0; $i < @chapters; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @chapters) 0 0 0
504 {
505 0 $chapters[$i] = sprintf('%s?format=light', $chapters[$i]);
506 }
507 }
508 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
509 {
510 0 ▶ warn "parse_chapter_urls: user=$user\n" if ($self->{verbose} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 0 0
511 0 ▶ if ($args{is_community})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'is_community'}) { } 0 0 0
512 {
513 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
514 {
515 0 my $ch_url = $1;
516 0 ▶ if (!$remember_ch_urls{$ch_url})
Branch: 1 branch
BranchTrueFalseTotal
unless ($remember_ch_urls{$ch_url}) 0 0 0
517 {
518 0 ▶ warn "chapter=$ch_url\n" if ($self->{verbose} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 0 0
519 0 push @chapters, "${ch_url}?format=light";
520 0 $remember_ch_urls{$ch_url} = 1;
521 }
522 }
523 }
524 else
525 {
526 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
527 {
528 0 my $ch_url = $1;
529 0 my $rest = $2;
530 0 ▶ if ($rest =~ /prevnext-link/)
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /prevnext-link/) { } 0 0 0
531 {
532 # it's a prev-next link, ignore it
533 }
534 else
535 {
536 0 ▶ warn "chapter='$ch_url'\n" if ($self->{verbose} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 0 0
537 0 ▶ if (!$remember_ch_urls{$ch_url})
Branch: 1 branch
BranchTrueFalseTotal
unless ($remember_ch_urls{$ch_url}) 0 0 0
538 {
539 0 push @chapters, "${ch_url}?format=light";
540 0 $remember_ch_urls{$ch_url} = 1;
541 }
542 }
543 }
544 }
545 }
546  
547 0 return \@chapters;
548 } # parse_chapter_urls
549  
550 1 1; # End of WWW::FetchStory::Fetcher::LiveJournal
551 __END__
↑ Summary blib/lib/WWW/FetchStory/Fetcher/Teaspoon.pm »