blib/lib/WWW/FetchStory.pm

filter: Statementstmt 25.4% 14 / 55 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 25.6% 21 / 82 CC 12 SCAR 34.3
CC
12
Cov
20%
fetch_story
56.0
new
30.0
list_fetchers
6.0
CRAP 31.0
« blib/lib/WWW/FetchStory/Fetcher/HPAdultFanfiction.pm ↑ Summary blib/lib/WWW/FetchStory/Fetcher/AO3.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package WWW::FetchStory;
5 1 $WWW::FetchStory::VERSION = '0.2001';
6 =head1 NAME
7  
8 WWW::FetchStory - Fetch a story from a fiction website
9  
10 =head1 VERSION
11  
12 version 0.2001
13  
14 =head1 SYNOPSIS
15  
16 use WWW::FetchStory;
17  
18 my $obj = WWW::FetchStory->new(%args);
19  
20 my %story_info = $obj->fetch_story(urls=>\@urls);
21  
22 =head1 DESCRIPTION
23  
24 This will fetch a story from a fiction website, intelligently
25 dealing with the formats from various different fiction websites
26 such as fanfiction.net; it deals with multi-file stories,
27 and strips all the extras from the HTML (such as navbars and javascript)
28 so that all you get is the story text and its formatting.
29  
30 =head2 Fetcher Plugins
31  
32 In order to tidy the HTML and parse the pages for data about the story,
33 site-specific "Fetcher" plugins are required.
34  
35 These are in the namespace 'WWW::FetchStory::Fetcher'; a fetcher for the Foo site
36 would be called 'WWW::FetchStory::Fetcher::Foo'.
37  
38 =cut
39  
40 1 ▶use WWW::FetchStory::Fetcher;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 use Module::Pluggable instantiate => 'new',
42 search_path => ['WWW::FetchStory::Fetcher'],
43 1 ▶sub_name => 'fetchers';
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 =head1 METHODS
46  
47 =head2 new
48  
49 Create a new object, setting global values for the object.
50  
51 my $obj = WWW::FetchStory->new();
52  
53 =cut
54  
55 sub new {
56 0 ▶ my $class = shift;
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
57 0 my %parameters = (@_);
58 0 ▶ my $self = bless ({%parameters}, ref ($class) || $class);
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
59  
60 # ---------------------------------------
61 # Fetchers
62 # find out what fetchers are available, and group them by priority
63 0 $self->{fetch_pri} = {};
64 0 my @fetchers = $self->fetchers();
65 0 foreach my $fe (@fetchers)
66 {
67 0 my $priority = $fe->priority();
68 0 my $name = $fe->name();
69 0 ▶ if ($self->{debug})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
70 {
71 0 print STDERR "fetcher=$name($priority)\n";
72 }
73 0 ▶ if (!exists $self->{fetch_pri}->{$priority})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"fetch_pri"}{$priority}) 0 0 0
74 {
75 0 $self->{fetch_pri}->{$priority} = [];
76 }
77 0 push @{$self->{fetch_pri}->{$priority}}, $fe;
78 }
79  
80 0 return ($self);
81 } # new
82  
83 =head2 fetch_story
84  
85 my %story_info = fetch_story(
86 urls=>\@urls,
87 verbose=>0,
88 toc=>0);
89  
90 =cut
91 sub fetch_story ($%) {
92 0 ▶ my $self = shift;
Subroutine fetch_story: not called CC=7 SCAR=40.3
Pod documented
93 0 my %args = (
94 urls=>undef,
95 verbose=>0,
96 toc=>0,
97 @_
98 );
99  
100 0 my $fetcher;
101 0 my $first_url = $args{urls}[0];
102 0 foreach my $pri (reverse sort keys %{$self->{fetch_pri}})
103 {
104 0 foreach my $fe (@{$self->{fetch_pri}->{$pri}})
105 {
106 0 ▶ if ($fe->allow($first_url))
Branch: 1 branch
BranchTrueFalseTotal
if ($fe->allow($first_url)) 0 0 0
107 {
108 0 $fetcher = $fe;
109 0 ▶ warn "Fetcher($pri): ", $fe->name(), "\n" if $args{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"verbose"} 0 0 0
110 0 last;
111 }
112 }
113 0 ▶ if (defined $fetcher)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fetcher) 0 0 0
114 {
115 0 last;
116 }
117 }
118 0 ▶ if (defined $fetcher)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fetcher) 0 0 0
119 {
120 0 $fetcher->init(%{$self});
121 0 return $fetcher->fetch(%args);
122 }
123  
124 0 return undef;
125 } # fetch_story
126  
127 =head2 list_fetchers
128  
129 my %fetchers = list_fetchers();
130  
131 =cut
132 sub list_fetchers ($%) {
133 0 ▶ my $self = shift;
Subroutine list_fetchers: not called CC=2 SCAR=17.9
Pod documented
134 0 my %args = (
135 verbose=>0,
136 @_
137 );
138  
139 0 my %fetchers = ();
140 0 my @all_fetchers = $self->fetchers();
141 0 foreach my $fe (@all_fetchers)
142 {
143 0 $fetchers{$fe->name()} = $fe->info();
144 }
145 0 return %fetchers;
146  
147 } # list_fetchers
148  
149 =head1 BUGS
150  
151 Please report any bugs or feature requests to the author.
152  
153 =cut
154  
155 1 1; # End of Text::ParseStory
156 __END__
« blib/lib/WWW/FetchStory/Fetcher/HPAdultFanfiction.pm ↑ Summary blib/lib/WWW/FetchStory/Fetcher/AO3.pm »