File Coverage

blib/lib/WWW/FetchStory/Fetcher/SSHGGiftfest.pm
Criterion Covered Total %
statement 9 58 15.5
branch 0 10 0.0
condition n/a
subroutine 3 8 37.5
pod 5 5 100.0
total 17 81 20.9


line stmt bran cond sub pod time code
1             package WWW::FetchStory::Fetcher::SSHGGiftfest;
2             $WWW::FetchStory::Fetcher::SSHGGiftfest::VERSION = '0.2602';
3 1     1   202220 use strict;
  1         3  
  1         43  
4 1     1   6 use warnings;
  1         2  
  1         76  
5             =head1 NAME
6              
7             WWW::FetchStory::Fetcher::SSHGGiftfest - fetching module for WWW::FetchStory
8              
9             =head1 VERSION
10              
11             version 0.2602
12              
13             =head1 DESCRIPTION
14              
15             This is the SSHGGiftfest story-fetching plugin for WWW::FetchStory.
16              
17             =cut
18              
19 1     1   10 use parent qw(WWW::FetchStory::Fetcher::LiveJournal);
  1         3  
  1         8  
20              
21             =head1 METHODS
22              
23             =head2 info
24              
25             Information about the fetcher.
26              
27             $info = $self->info();
28              
29             =cut
30              
31             sub info {
32 0     0 1   my $self = shift;
33            
34 0           my $info = "(http://sshg-giftfest.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             sub priority {
58 0     0 1   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             sub allow {
77 0     0 1   my $self = shift;
78 0           my $url = shift;
79              
80 0           return ($url =~ /sshg[-_]giftfest\.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             sub parse_toc {
114 0     0 1   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           $info{title} = $title;
129              
130 0           my $summary = $self->parse_summary(%args);
131 0           $summary =~ s/"/'/g;
132 0           $info{summary} = $summary;
133              
134 0           my $author = $self->parse_author(%args);
135 0           $info{author} = $author;
136              
137 0           $info{characters} = $self->parse_characters(%args);
138 0           $info{characters} =~ s!Severus/Hermione!Severus Snape, Hermione Granger!;
139 0           $info{characters} =~ s!Hermione/Severus!Hermione Granger, Severus Snape!;
140 0 0         if (!$info{characters})
141             {
142 0           $info{characters} = 'Hermione Granger, Severus Snape';
143             }
144 0           $info{category} = 'SSHG';
145 0           $info{universe} = 'Harry Potter';
146 0           $info{recipient} = $self->parse_recipient(%args);
147 0 0         if (!$info{recipient}) # if it fails to parse the recipient, remove them
148             {
149 0           delete $info{recipient};
150             }
151 0           $info{chapters} = $self->parse_chapter_urls(%args);
152              
153 0           return %info;
154             } # parse_toc
155              
156             =head2 parse_chapter_urls
157              
158             Figure out the URLs for the chapters of this story.
159              
160             =cut
161             sub parse_chapter_urls {
162 0     0 1   my $self = shift;
163 0           my %args = (
164             url=>'',
165             content=>'',
166             @_
167             );
168 0           my $content = $args{content};
169 0           my $sid = $args{sid};
170 0           my @chapters = ();
171 0 0         if (defined $args{urls})
172             {
173 0           @chapters = @{$args{urls}};
  0            
174 0           for (my $i = 0; $i < @chapters; $i++)
175             {
176 0           $chapters[$i] = sprintf('%s?format=light', $chapters[$i]);
177             }
178             }
179 0 0         if (@chapters == 1)
180             {
181 0           while ($content =~ m/href=["'](https?:\/\/sshg-(?:mod|gifts|giftmod)\.livejournal\.com\/\d+.html)/sg)
182             {
183 0           my $ch_url = $1;
184 0 0         warn "chapter=$ch_url\n" if ($self->{verbose} > 1);
185 0           push @chapters, "${ch_url}?format=light";
186             }
187             }
188              
189 0           return \@chapters;
190             } # parse_chapter_urls
191              
192             1; # End of WWW::FetchStory::Fetcher::SSHGGiftfest
193             __END__