Authentication/HTDocs.pm

filter: Statementstmt 82.6% 38 / 46 Branchbran 71.4% 10 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 83.3% 60 / 72 CC 8 SCAR 13.6
CC
8
Cov
80%
get_whitelist
6.0
get_file
5.4
BEGIN
1.0
CRAP 3.9
« Authentication/Handler/Blocker.pm ↑ Summary Authentication/Handler/Size.pm »
1 package Mail::Milter::Authentication::HTDocs;
2 143 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 143 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 143 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 143 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Load and serve static files via the in-built http server.
7 143 our $VERSION = '4.20261116'; # VERSION
8  
9  
10  
11 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12 1 my ( $class ) = @_;
13 1 my $self = {};
14 1 bless $self, $class;
15 1 return $self;
16 }
17  
18  
19 2 ▶sub get_whitelist {
Subroutine get_whitelist: called CC=6 SCAR=17.9
Pod documented
20 2 my ( $self, $path ) = @_;
21  
22 2 my @whitelist;
23  
24 2 ▶ if ( opendir( my $dh, join( '/', $self->get_basedir(), $path ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, join("/", $self->get_basedir, $path)) 2 0 2
25 2 ▶ while ( my $file = readdir( $dh ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $file = readdir $dh)) 8 2 10
26 8 ▶ next if $file =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^\./u 4 4 8
27 4 my $full_path = join( '/', $self->get_basedir(), $path, $file );
28 4 ▶ if ( -f $full_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $full_path) 3 1 4
29 3 push @whitelist, join( '/', $path, $file );
30 }
31 4 ▶ if ( -d $full_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $full_path) 1 3 4
32 1 @whitelist = ( @whitelist, @{ $self->get_whitelist( join ( '/', $path, $file ) ) } );
33 }
34 }
35 }
36  
37 2 return \@whitelist;
38 }
39  
40  
41 6 ▶sub get_basedir {
Subroutine get_basedir: called CC=1 SCAR=0.0
Pod documented
42 6 my ( $self ) = @_;
43 6 my $basedir = __FILE__;
44 6 $basedir =~ s/HTDocs\.pm$/htdocs/;
45 6 return $basedir;
46 }
47  
48  
49 1 ▶sub get_file {
Subroutine get_file: called CC=3 SCAR=16.9
Pod documented
50 1 my ( $self, $file ) = @_;
51  
52 1 my $whitelisted = grep { $_ eq $file } @{ $self->get_whitelist( '' ) };
53 1 ▶ return if ! $whitelisted;
Branch: 1 branch
BranchTrueFalseTotal
unless $whitelisted 1 0 1
54  
55 0 my $basefile = $self->get_basedir();
56 0 $basefile .= $file;
57 0 ▶ if ( ! -e $basefile ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $basefile) 0 0 0
58 0 return;
59 }
60 0 open my $InF, '<', $basefile;
61 0 my @Content = <$InF>;
62 0 close $InF;
63 0 return join( q{}, @Content );
64 }
65  
66 143 1;
67  
68 __END__
« Authentication/Handler/Blocker.pm ↑ Summary Authentication/Handler/Size.pm »