| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | $browser = 'explorer' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
lc $browser eq "internet explorer" or lc $browser eq "explorer" or lc $browser eq "ie"
lc $browser eq "internet explorer" or lc $browser eq "explorer"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | croak("Can't load user-agents from unrecognized browser $browser") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | unless grep /^$browser$/, @browsers; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ($os) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $os = ucfirst(lc($os)); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | croak("Can't filter user-agents with an unrecognized Os $os") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | unless grep /^$os$/, @oss; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my @selection = (); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $self->options({}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | unless defined $self->options; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($browser eq 'any') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($self->options->{any}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $self->name($selection[rand(@selection)] || ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$selection[rand @selection] || ''
MC/DC0%0/1
$selection[rand @selection] || ''
$selection[rand @selection]
Truth table0%0/2
A
A= $selection[rand @selection]
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return $self->name; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||