| 1 | package WWW::LinkChecker::Internal::API::Worker; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | $WWW::LinkChecker::Internal::API::Worker::VERSION = '0.10.0'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use JSON::MaybeXS qw( decode_json encode_json ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use List::Util 1.34 qw/ any none /; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Path::Tiny qw/ path /; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use WWW::Mechanize (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | has 'base_url' => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | has 'before_insert_skip' => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | has 'pre_skip' => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | has 'start_url' => ( is => 'ro', ); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | has 'state_filename' => ( is => 'ro', ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | sub run | ||||||||||||||||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my ( $self, $args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | my $check_url_inform_cb = | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | ( $args->{check_url_inform_cb} // sub { return; } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$args->{"check_url_inform_cb"} // sub {
return;
}
MC/DC0%0/2
$args->{"check_url_inform_cb"} // sub {
return;
}
$args->{"check_url_inform_cb"}
sub {
return;
}
Truth table0%0/3
A // B
A= $args->{"check_url_inform_cb"}B= sub {
return;
}
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $base_url = $self->base_url; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if ( !defined($base_url) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | die "--base must be specified"; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my @before_insert_skips_regexes = @{ $self->before_insert_skip() }; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my @pre_skip_regexes = @{ $self->pre_skip() }; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $alternative_start_url = $self->start_url(); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $state_fn = $self->state_filename(); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | my $start_url = ( $alternative_start_url || $base_url ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$alternative_start_url || $base_url
MC/DC0%0/2
$alternative_start_url || $base_url
$alternative_start_url
$base_url
Truth table0%0/3
A || B
A= $alternative_start_urlB= $base_url
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $state = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$state_fn and -e $state_fn
MC/DC0%0/2
$state_fn and -e $state_fn
$state_fn
-e $state_fn
Truth table0%0/3
A and B
A= $state_fnB= -e $state_fn
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | +( $state_fn && ( -e $state_fn ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 42 | ? decode_json( path($state_fn)->slurp_utf8 ) | ||||||||||||||||||||||||||||||||||||||||||
| 43 | : { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | stack => [ { url => $start_url, from => undef(), } ], | ||||||||||||||||||||||||||||||||||||||||||
| 45 | encountered_urls => { $start_url => 1, }, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $stack = $state->{stack}; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $encountered_urls = $state->{encountered_urls}; | |||||||||||||||||||||||||||||||||||||||||
| 49 | STACK: | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | while ( my $url_rec = pop( @{$stack} ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $url = $url_rec->{'url'}; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $check_url_inform_cb->( { url => $url, } ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $mech = WWW::Mechanize->new(); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | eval { $mech->get($url); }; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($@) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | push @{$stack}, $url_rec; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($state_fn) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | path($state_fn)->spew_utf8( encode_json($state) ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my $from = ( $url_rec->{from} // "START" ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$url_rec->{"from"} // "START"
MC/DC0%0/1
$url_rec->{"from"} // "START"
$url_rec->{"from"}
Truth table0%0/2
A
A= $url_rec->{"from"}
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | die "SRC URL $from points to '$url'."; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ( any { $url =~ $_ } @pre_skip_regexes ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | next STACK; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | foreach my $link ( $mech->links() ) | |||||||||||||||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $dest_url = $link->url_abs() . ""; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $dest_url =~ s{#[^#]+\z}{}ms; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ( ( !exists( $encountered_urls->{$dest_url} ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not exists $encountered_urls->{$dest_url} and $dest_url =~ /\A\Q$base_url\E/msu and &none(sub {
$dest_url =~ /$_/u;
}
, @before_insert_skips_regexes)
not exists $encountered_urls->{$dest_url} and $dest_url =~ /\A\Q$base_url\E/msu
MC/DC0%0/3
not exists $encountered_urls->{$dest_url} and $dest_url =~ /\A\Q$base_url\E/msu and &none(sub {
$dest_url =~ /$_/u;
}
, @before_insert_skips_regexes)
not exists $encountered_urls->{$dest_url}
$dest_url =~ /\A\Q$base_url\E/msu
&none(sub {
$dest_url =~ /$_/u;
}
, @before_insert_skips_regexes)
Truth table0%0/4
not(A) and B and C
A= not exists $encountered_urls->{$dest_url}B= $dest_url =~ /\A\Q$base_url\E/msuC= &none(sub {
$dest_url =~ /$_/u;
}
, @before_insert_skips_regexes)
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | and $dest_url =~ m{\A\Q$base_url\E}ms | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | and ( none { $dest_url =~ $_ } @before_insert_skips_regexes ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $encountered_urls->{$dest_url} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | push @{$stack}, { url => $dest_url, from => $url, }; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | return +{ success => 1, }; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||||||||||||||||