Scrappy.pm

filter: Statementstmt 39.1% 9 / 23 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 28.8% 13 / 45 CC 10 SCAR 44.4
CC
10
Cov
24%
crawl
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 84.8
« Scrappy/Scraper/Control.pm ↑ Summary Scrappy/Action.pm »
1 # ABSTRACT: The All Powerful Web Spidering, Scraping, Creeping Crawling Framework
2 # Dist::Zilla: +PodWeaver
3  
4 package Scrappy;
5  
6 10 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 $Scrappy::VERSION = '0.94112090';
8 }
9  
10 # load OO System
11 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # load other libraries
14 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 extends 'Scrappy::Scraper';
16  
17 0 ▶sub crawl {
Subroutine crawl: not called CC=10 SCAR=47.0
Pod documented
18 0 my ($self, $starting_url, %pages) = @_;
19  
20 0 ▶ croak(
Branch: 1 branch
BranchTrueFalseTotal
unless $self and $starting_url and keys %pages 0 0 0
Condition0%0/6
$self and $starting_url and keys %pages
!ll&&!rl&&r
000
$self and $starting_url
!ll&&!rl&&r
000
MC/DC0%0/3
$self and $starting_url and keys %pages
$self $starting_url keys %pages
Truth table0%0/4
A and B and C
A= $selfB= $starting_urlC= keys %pages
ABCresult
0XX0
10X0
1100
1111
21 'Please provide a starting URL and a valid configuration before crawling'
22 ) unless ($self && $starting_url && keys %pages);
23  
24 # register the starting url
25 0 $self->queue->add($starting_url);
26  
27 # start the crawl loop
28 0 ▶ while (my $url = $self->queue->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = $self->queue->next) 0 0 0
29  
30 # check if the url matches against any registered pages
31 0 foreach my $page (keys %pages) {
32 0 my $data = $self->page_match($page, $url);
33  
34 0 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 0 0
35  
36 # found a page match, fetch and scrape the page for data
37 0 ▶ if ($self->get($url)->page_loaded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get($url)->page_loaded) 0 0 0
38  
39 0 foreach my $selector (keys(%{$pages{$page}})) {
40  
41 # loop through resultset
42 0 foreach my $item (@{$self->select($selector)->data}) {
43  
44 # execute selector code
45 0 $pages{$page}->{$selector}->($self, $item, $data);
46 }
47 }
48 }
49 }
50 }
51 }
52  
53 0 return $self;
54 }
55  
56  
57 10 1;
58  
59 __END__
« Scrappy/Scraper/Control.pm ↑ Summary Scrappy/Action.pm »