Scrappy/Scraper/UserAgent.pm

filter: Statementstmt 36.5% 19 / 52 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 25.5% 25 / 98 CC 18 SCAR 55.5
CC
18
Cov
22%
random_user_agent
342.0
BEGIN
1.0
BEGIN
1.0
CRAP 256.8
« Scrappy/Action/Download.pm ↑ Summary Scrappy/Logger.pm »
1 package Scrappy::Scraper::UserAgent;
2  
3 10 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 $Scrappy::Scraper::UserAgent::VERSION = '0.94112090';
5 }
6  
7 # load OO System
8 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # load other libraries
11 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use File::ShareDir ':ALL';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 10 has 'name' => (is => 'rw', isa => 'Str');
17 10 has 'options' => (is => 'rw', isa => 'HashRef');
18  
19 0 ▶sub random_user_agent {
Subroutine random_user_agent: not called CC=18 SCAR=58.3
Pod undocumented
20 0 my $self = shift;
21 0 my ($browser, $os) = @_;
22  
23 0 ▶ $browser = 'any' unless $browser;
Branch: 1 branch
BranchTrueFalseTotal
unless $browser 0 0 0
24  
25 0 ▶ $browser = 'explorer'
Branch: 1 branch
BranchTrueFalseTotal
if lc $browser eq "internet explorer" or lc $browser eq "explorer" or lc $browser eq "ie" 0 0 0
Condition0%0/6
lc $browser eq "internet explorer" or lc $browser eq "explorer" or lc $browser eq "ie"
l!l&&r!l&&!r
000
lc $browser eq "internet explorer" or lc $browser eq "explorer"
l!l&&r!l&&!r
000
MC/DC0%0/3
lc $browser eq "internet explorer" or lc $browser eq "explorer" or lc $browser eq "ie"
lc $browser eq "internet explorer" lc $browser eq "explorer" lc $browser eq "ie"
Truth table0%0/4
A or B or C
A= lc $browser eq "internet explorer"B= lc $browser eq "explorer"C= lc $browser eq "ie"
ABCresult
1XX1
01X1
0011
0000
26 if lc($browser) eq 'internet explorer'
27 || lc($browser) eq 'explorer'
28 || lc($browser) eq 'ie';
29  
30 0 $browser = lc $browser;
31  
32 0 my @browsers = ('explorer', 'chrome', 'firefox', 'opera', 'safari');
33  
34 0 my @oss = ('Windows', 'Linux', 'Macintosh');
35  
36 0 ▶ if ($browser ne 'any') {
Branch: 1 branch
BranchTrueFalseTotal
if ($browser ne "any") 0 0 0
37 0 ▶ croak("Can't load user-agents from unrecognized browser $browser")
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$browser$/, @browsers 0 0 0
38 unless grep /^$browser$/, @browsers;
39 }
40  
41 0 ▶ if ($os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($os) 0 0 0
42 0 $os = ucfirst(lc($os));
43 0 ▶ croak("Can't filter user-agents with an unrecognized Os $os")
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$os$/, @oss 0 0 0
44 unless grep /^$os$/, @oss;
45 }
46  
47 0 my @selection = ();
48 0 ▶ $self->options({})
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->options 0 0 0
49 unless defined $self->options;
50  
51 0 ▶ if ($browser eq 'any') {
Branch: 1 branch
BranchTrueFalseTotal
if ($browser eq 'any') { } 0 0 0
52 0 ▶ if ($self->options->{any}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options->{'any'}) { } 0 0 0
53 0 @selection = @{$self->options->{any}};
54 }
55 else {
56 0 foreach my $file (@browsers) {
57 0 my $u = dist_dir('Scrappy') . "/support/$file.txt";
58 0 ▶ $u = "share/support/$file.txt" unless -e $u;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $u 0 0 0
59 0 push @selection, read_file($u);
60 }
61 0 $self->options->{'any'} = [@selection];
62 }
63 }
64 else {
65 0 ▶ if ($self->options->{$browser}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options->{$browser}) { } 0 0 0
66 0 @selection = @{$self->options->{$browser}};
67 }
68 else {
69 0 my $u = dist_dir('Scrappy') . "/support/$browser.txt";
70 0 ▶ $u = "share/support/$browser.txt" unless -e $u;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $u 0 0 0
71 0 push @selection, read_file($u);
72 0 $self->options->{$browser} = [@selection];
73 }
74 }
75  
76 0 ▶ @selection = grep /$os/, @selection if $os;
Branch: 1 branch
BranchTrueFalseTotal
if $os 0 0 0
77  
78 0 ▶ $self->name($selection[rand(@selection)] || '');
Condition0%0/2
$selection[rand @selection] || ''
l!l
00
MC/DC0%0/1
$selection[rand @selection] || ''
$selection[rand @selection]
Truth table0%0/2
A
A= $selection[rand @selection]
Aresult
11
00
79 0 return $self->name;
80 }
81  
82 10 1;
« Scrappy/Action/Download.pm ↑ Summary Scrappy/Logger.pm »