| 1 | package LWP::UserAgent::Plugin::FilterLcpan; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Log::ger; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use HTTP::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||
| 11 | 1 | our $DATE = '2023-09-26'; # DATE | |||||||||||||||||||||||||||
| 12 | 1 | our $DIST = 'App-lcpan'; # DIST | |||||||||||||||||||||||||||
| 13 | 1 | our $VERSION = '1.074'; # VERSION | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub before_mirror { | ||||||||||||||||||||||||||
|
Subroutine
before_mirror: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 0 | my ($self, $r) = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | my ($ua, $url, $filename) = @{ $r->{argv} }; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | if ($r->{config}{include_author}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | my $ary = ref $r->{config}{include_author} eq 'ARRAY' ? | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $r->{config}{include_author} : [split /;/, $r->{config}{include_author}]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | if ($url =~ m!authors/id/./../(.+)/! && !(grep { $_ eq $1 } @$ary)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$url =~ m[authors/id/./../(.+)/] and not grep({$_ eq $1;} @$ary)
MC/DC0%0/2
$url =~ m[authors/id/./../(.+)/] and not grep({$_ eq $1;} @$ary)
$url =~ m[authors/id/./../(.+)/]
not grep({$_ eq $1;} @$ary)
Truth table0%0/3
A and not(B)
A= $url =~ m[authors/id/./../(.+)/]B= not grep({$_ eq $1;} @$ary)
| |||||||||||||||||||||||||||||
| 24 | say "mirror($url, $filename): author not included, skipping" | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if $r->{config}{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | return HTTP::Response->new(304); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if ($r->{config}{exclude_author}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | my $ary = ref $r->{config}{exclude_author} eq 'ARRAY' ? | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $r->{config}{exclude_author} : [split /;/, $r->{config}{exclude_author}]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ($url =~ m!authors/id/./../(.+)/! && (grep { $_ eq $1 } @$ary)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$url =~ m[authors/id/./../(.+)/] and grep {$_ eq $1;} @$ary
MC/DC0%0/2
$url =~ m[authors/id/./../(.+)/] and grep {$_ eq $1;} @$ary
$url =~ m[authors/id/./../(.+)/]
grep {$_ eq $1;} @$ary
Truth table0%0/3
A and B
A= $url =~ m[authors/id/./../(.+)/]B= grep {$_ eq $1;} @$ary
| |||||||||||||||||||||||||||||
| 33 | say "mirror($url, $filename): author included, skipping" | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if $r->{config}{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | return HTTP::Response->new(304); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if (my $max_size = $r->{config}{max_size}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | my $size = (-s $filename); | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ($size && $size > $max_size) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$size and $size > $max_size
MC/DC0%0/2
$size and $size > $max_size
$size
$size > $max_size
Truth table0%0/3
A and B
A= $sizeB= $size > $max_size
| |||||||||||||||||||||||||||||
| 41 | say "mirror($url, $filename): local size ($size) > max_size ($max_size), skipping" | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if $r->{config}{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | return HTTP::Response->new(304); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # perform HEAD request to find out the size | ||||||||||||||||||||||||||||
| 47 | 0 | my $resp = $ua->head($url); | |||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | last unless $resp->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | last unless defined(my $len = $resp->header("Content-Length")); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($len > $max_size) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | say "mirror($url, $filename): remote size ($len) > max_size ($max_size), skipping" | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if $r->{config}{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | return HTTP::Response->new(304); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | 1; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | 1; | |||||||||||||||||||||||||||
| 63 | # ABSTRACT: Filter mirror() based on some criteria | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||