WWW/FetchStory/Fetcher/SSHGPromptfest.pm

filter: Statementstmt 20.3% 11 / 54 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod 100% 5 / 5 totaltotal 24.6% 19 / 77 CC 6 SCAR 30.1
CC
6
Cov
17%
parse_chapter_urls
42.0
info
2.0
priority
2.0
CRAP 20.2
« WWW/FetchStory/Fetcher/SSHGExchange.pm ↑ Summary WWW/FetchStory/Fetcher/SSHGGiftfest.pm »
1 package WWW::FetchStory::Fetcher::SSHGPromptfest;
2 1 $WWW::FetchStory::Fetcher::SSHGPromptfest::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::SSHGPromptfest - fetching module for WWW::FetchStory
8  
9 =head1 VERSION
10  
11 version 0.2602
12  
13 =head1 DESCRIPTION
14  
15 This is the SSHGPromptfest story-fetching plugin for WWW::FetchStory.
16  
17 =cut
18  
19 1 ▶use parent qw(WWW::FetchStory::Fetcher::LiveJournal);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 =head1 METHODS
22  
23 =head2 info
24  
25 Information about the fetcher.
26  
27 $info = $self->info();
28  
29 =cut
30  
31 0 ▶sub info {
Subroutine info: not called CC=1 SCAR=6.9
Pod documented
32 0 my $self = shift;
33
34 0 my $info = "(http://sshg_promptfest.livejournal.com/) Severus Snape/Hermione Granger fiction exchange comm.";
35  
36 0 return $info;
37 } # info
38  
39 =head2 priority
40  
41 The priority of this fetcher. Fetchers with higher priority
42 get tried first. This is useful where there may be a generic
43 fetcher for a particular site, and then a more specialized fetcher
44 for particular sections of a site. For example, there may be a
45 generic LiveJournal fetcher, and then refinements for particular
46 LiveJournal community, such as the sshg_exchange community.
47 This works as either a class function or a method.
48  
49 This must be overridden by the specific fetcher class.
50  
51 $priority = $self->priority();
52  
53 $priority = WWW::FetchStory::Fetcher::priority($class);
54  
55 =cut
56  
57 0 ▶sub priority {
Subroutine priority: not called CC=1 SCAR=6.9
Pod documented
58 0 my $class = shift;
59  
60 0 return 2;
61 } # priority
62  
63 =head2 allow
64  
65 If this fetcher can be used for the given URL, then this returns
66 true.
67 This must be overridden by the specific fetcher class.
68  
69 if ($obj->allow($url))
70 {
71 ....
72 }
73  
74 =cut
75  
76 0 ▶sub allow {
Subroutine allow: not called CC=1 SCAR=6.9
Pod documented
77 0 my $self = shift;
78 0 my $url = shift;
79  
80 0 return ($url =~ /sshg[-_]promptfest\.livejournal\.com/);
81 } # allow
82  
83 =head1 Private Methods
84  
85 =head2 parse_toc
86  
87 Parse the table-of-contents file.
88  
89 %info = $self->parse_toc(content=>$content,
90 url=>$url,
91 urls=>\@urls);
92  
93 This should return a hash containing:
94  
95 =over
96  
97 =item chapters
98  
99 An array of URLs for the chapters of the story. In the case where the
100 story only takes one page, that will be the chapter.
101 In the case where multiple URLs have been passed in, it will be those URLs.
102  
103 =item title
104  
105 The title of the story.
106  
107 =back
108  
109 It may also return additional information, such as Summary.
110  
111 =cut
112  
113 0 ▶sub parse_toc {
Subroutine parse_toc: not called CC=1 SCAR=6.9
Pod documented
114 0 my $self = shift;
115 0 my %args = (
116 url=>'',
117 content=>'',
118 @_
119 );
120  
121 0 my $content = $args{content};
122  
123 0 my %info = ();
124 0 $info{url} = $args{url};
125 0 $info{toc_first} = 1;
126  
127 0 my $title = $self->parse_title(%args);
128 0 $title =~ s/sshg_promptfest\s*//;
129 0 $info{title} = $title;
130  
131 0 my $summary = $self->parse_summary(%args);
132 0 $summary =~ s/"/'/g;
133 0 $info{summary} = $summary;
134  
135 0 my $author = $self->parse_author(%args);
136 0 $info{author} = $author;
137  
138 0 $info{characters} = "Hermione Granger, Severus Snape";
139 0 $info{universe} = 'Harry Potter';
140 0 $info{recipient} = $self->parse_recipient(%args);
141 0 $info{chapters} = $self->parse_chapter_urls(%args);
142  
143 0 return %info;
144 } # parse_toc
145  
146 =head2 parse_chapter_urls
147  
148 Figure out the URLs for the chapters of this story.
149  
150 =cut
151 0 ▶sub parse_chapter_urls {
Subroutine parse_chapter_urls: not called CC=6 SCAR=37.4
Pod documented
152 0 my $self = shift;
153 0 my %args = (
154 url=>'',
155 content=>'',
156 @_
157 );
158 0 my $content = $args{content};
159 0 my $sid = $args{sid};
160 0 my @chapters = ();
161 0 ▶ if (defined $args{urls})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"urls"}) 0 0 0
162 {
163 0 @chapters = @{$args{urls}};
164 0 ▶ for (my $i = 0; $i < @chapters; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @chapters) 0 0 0
165 {
166 0 $chapters[$i] = sprintf('%s?format=light', $chapters[$i]);
167 }
168 }
169 0 ▶ if (@chapters == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@chapters == 1) 0 0 0
170 {
171 0 ▶ while ($content =~ m/href=["'](http:\/\/sshg[-_]pf[-_](?:mod|fanwork)\.livejournal\.com\/\d+.html)/sg)
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ m[href=["'](http://sshg[-_]pf[-_](?:mod|fanwork)\.livejournal\.com/\d+.html)]gs) 0 0 0
172 {
173 0 my $ch_url = $1;
174 0 ▶ warn "chapter=$ch_url\n" if ($self->{verbose} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 0 0
175 0 push @chapters, "${ch_url}?format=light";
176 }
177 }
178  
179 0 return \@chapters;
180 } # parse_chapter_urls
181  
182 1 1; # End of WWW::FetchStory::Fetcher::SSHGPromptfest
183 __END__
« WWW/FetchStory/Fetcher/SSHGExchange.pm ↑ Summary WWW/FetchStory/Fetcher/SSHGGiftfest.pm »