| 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
MC/DC0%0/1
$args{"inc"} // \@INC
$args{"inc"}
Truth table50%1/2
A
A= $args{"inc"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
defined $dir and not ref $dir and -d $dir
defined $dir and not ref $dir
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
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 24 | my $path = File::Spec->catfile($dir, @parts); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 24 | ▶ | if (-f $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 18 | ▶ | next if $self->{serve_filter} && !$self->{serve_filter}->($path); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"serve_filter"} and not $self->{"serve_filter"}->($path)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||