lib/Remote/Perl/ModuleServer.pm

filter: Statementstmt 100% 24 / 24 Branchbran 87.5% 7 / 8 Conditioncond 54.5% 6 / 11 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 78.5% 44 / 56 CC 10 SCAR 18.8
CC
10
Cov
86%
find
9.4
new
2.1
BEGIN
1.0
CRAP 6.5
« lib/Remote/Perl.pm ↑ Summary lib/Remote/Perl/Transport.pm »
1 132 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Remote::Perl::ModuleServer;
3 132 our $VERSION = '0.005';
4  
5 132 ▶use autodie qw(open close);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 132 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Searches a list of directories for a module file and returns its source.
9 #
10 # new(inc => \@dirs, serve_filter => sub($path){...})
11 # inc -- dirs to search; defaults to \@INC if omitted
12 # serve_filter -- optional callback: receives the resolved file path,
13 # returns true to allow serving, false to deny
14 # find($filename) -- returns source string, or undef if not found/denied
15  
16 38 ▶sub new($class, %args) {
Subroutine new: called CC=2 SCAR=7.6
Pod undocumented
17 return bless {
18 inc => $args{inc} // \@INC,
19 serve_filter => $args{serve_filter},
20 38 ▶ }, $class;
Condition50%1/2
$args{"inc"} // \@INC
l!l
380
MC/DC0%0/1
$args{"inc"} // \@INC
$args{"inc"}
Truth table50%1/2
A
A= $args{"inc"}
Aresult
11
00
21 }
22  
23 # Search for $filename (e.g. 'Foo/Bar.pm') in the configured directories.
24 # Returns the file's raw bytes, or undef if not found.
25 # Rejects filenames containing path traversal sequences.
26 28 ▶sub find($self, $filename) {
Subroutine find: called CC=9 SCAR=22.4
Pod undocumented
27 # Reject any filename with directory traversal components.
28 28 my @parts = File::Spec->splitdir($filename);
29 28 ▶ return if grep { $_ eq '..' } @parts;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "..";} @parts 4 24 28
30  
31 24 for my $dir (@{ $self->{inc} }) {
32 # @INC entries can be code refs or objects (handled by Perl itself);
33 # we only search plain directory strings.
34 24 ▶ next unless defined $dir && !ref($dir) && -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir and not ref $dir and -d $dir 0 24 24
Condition33%2/6
defined $dir and not ref $dir and -d $dir
!ll&&!rl&&r
0024
defined $dir and not ref $dir
!ll&&!rl&&r
0024
MC/DC0%0/3
defined $dir and not ref $dir and -d $dir
defined $dir not ref $dir -d $dir
Truth table25%1/4
A and not(B) and C
A= defined $dirB= not ref $dirC= -d $dir
ABCresult
0XX0
10X0
1100
1111
35 24 my $path = File::Spec->catfile($dir, @parts);
36 24 ▶ if (-f $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $path) 18 6 24
37 18 ▶ next if $self->{serve_filter} && !$self->{serve_filter}->($path);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"serve_filter"} and not $self->{"serve_filter"}->($path) 2 16 18
Condition100%3/3
$self->{"serve_filter"} and not $self->{"serve_filter"}->($path)
!ll&&!rl&&r
1512
MC/DC100%2/2
$self->{"serve_filter"} and not $self->{"serve_filter"}->($path)
$self->{"serve_filter"} not $self->{"serve_filter"}->($path)
Truth table100%3/3
A and not(B)
A= $self->{"serve_filter"}B= not $self->{"serve_filter"}->($path)
ABresult
0X0
100
111
38 16 open(my $fh, '<', $path);
39 16 local $/;
40 16 return scalar <$fh>;
41 }
42 }
43 8 return;
44 }
45  
46 132 1;
47  
48 __END__
« lib/Remote/Perl.pm ↑ Summary lib/Remote/Perl/Transport.pm »