LWP/UserAgent/Plugin/FilterLcpan.pm

filter: Statementstmt 40.4% 19 / 47 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 24.2% 24 / 99 CC 19 SCAR 57.1
CC
19
Cov
22%
before_mirror
380.0
BEGIN
1.0
BEGIN
1.0
CRAP 301.0
« App/lcpan/Cmd/deps_by_dependent_count.pm ↑ Summary App/lcpan/Cmd/related_mods.pm »
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
BranchTrueFalseTotal
if ($r->{"config"}{"include_author"}) 0 0 0
21 my $ary = ref $r->{config}{include_author} eq 'ARRAY' ?
22 0 ▶ $r->{config}{include_author} : [split /;/, $r->{config}{include_author}];
Branch: 1 branch
BranchTrueFalseTotal
ref $r->{'config'}{'include_author'} eq 'ARRAY' ? : 0 0 0
23 0 ▶ if ($url =~ m!authors/id/./../(.+)/! && !(grep { $_ eq $1 } @$ary)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[authors/id/./../(.+)/] and not grep({$_ eq $1;} @$ary)) 0 0 0
Condition0%0/3
$url =~ m[authors/id/./../(.+)/] and not grep({$_ eq $1;} @$ary)
!ll&&!rl&&r
000
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)
ABresult
0X0
100
111
24 say "mirror($url, $filename): author not included, skipping"
25 0 ▶ if $r->{config}{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"config"}{"verbose"} 0 0 0
26 0 return HTTP::Response->new(304);
27 }
28 }
29 0 ▶ if ($r->{config}{exclude_author}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"config"}{"exclude_author"}) 0 0 0
30 my $ary = ref $r->{config}{exclude_author} eq 'ARRAY' ?
31 0 ▶ $r->{config}{exclude_author} : [split /;/, $r->{config}{exclude_author}];
Branch: 1 branch
BranchTrueFalseTotal
ref $r->{'config'}{'exclude_author'} eq 'ARRAY' ? : 0 0 0
32 0 ▶ if ($url =~ m!authors/id/./../(.+)/! && (grep { $_ eq $1 } @$ary)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[authors/id/./../(.+)/] and grep {$_ eq $1;} @$ary) 0 0 0
Condition0%0/3
$url =~ m[authors/id/./../(.+)/] and grep {$_ eq $1;} @$ary
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
33 say "mirror($url, $filename): author included, skipping"
34 0 ▶ if $r->{config}{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"config"}{"verbose"} 0 0 0
35 0 return HTTP::Response->new(304);
36 }
37 }
38 0 ▶ if (my $max_size = $r->{config}{max_size}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $max_size = $r->{"config"}{"max_size"}) 0 0 0
39 0 my $size = (-s $filename);
40 0 ▶ if ($size && $size > $max_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size and $size > $max_size) 0 0 0
Condition0%0/3
$size and $size > $max_size
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
41 say "mirror($url, $filename): local size ($size) > max_size ($max_size), skipping"
42 0 ▶ if $r->{config}{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"config"}{"verbose"} 0 0 0
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
BranchTrueFalseTotal
unless $resp->is_success 0 0 0
50 0 ▶ last unless defined(my $len = $resp->header("Content-Length"));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $len = $resp->header("Content-Length")) 0 0 0
51 0 ▶ if ($len > $max_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $max_size) 0 0 0
52 say "mirror($url, $filename): remote size ($len) > max_size ($max_size), skipping"
53 0 ▶ if $r->{config}{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"config"}{"verbose"} 0 0 0
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__
« App/lcpan/Cmd/deps_by_dependent_count.pm ↑ Summary App/lcpan/Cmd/related_mods.pm »