Authentication/HTDocs.pm

filter: Statementstmt 28.2% 13 / 46 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 4 / 8 Podpod 100% 4 / 4 totaltotal 29.1% 21 / 72 CC 8 SCAR 29.8
CC
8
Cov
22%
get_whitelist
42.0
get_file
12.0
new
2.0
CRAP 19.7
« Authentication/Handler/IPRev.pm ↑ Summary Authentication/Handler/XGoogleDKIM.pm »
1 package Mail::Milter::Authentication::HTDocs;
2 140 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 140 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 140 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 140 ▶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 140 our $VERSION = '4.20261111'; # VERSION
8  
9  
10  
11 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
12 0 my ( $class ) = @_;
13 0 my $self = {};
14 0 bless $self, $class;
15 0 return $self;
16 }
17  
18  
19 0 ▶sub get_whitelist {
Subroutine get_whitelist: not called CC=6 SCAR=37.4
Pod documented
20 0 my ( $self, $path ) = @_;
21  
22 0 my @whitelist;
23  
24 0 ▶ if ( opendir( my $dh, join( '/', $self->get_basedir(), $path ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, join("/", $self->get_basedir, $path)) 0 0 0
25 0 ▶ while ( my $file = readdir( $dh ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $file = readdir $dh)) 0 0 0
26 0 ▶ next if $file =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^\./u 0 0 0
27 0 my $full_path = join( '/', $self->get_basedir(), $path, $file );
28 0 ▶ if ( -f $full_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $full_path) 0 0 0
29 0 push @whitelist, join( '/', $path, $file );
30 }
31 0 ▶ if ( -d $full_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $full_path) 0 0 0
32 0 @whitelist = ( @whitelist, @{ $self->get_whitelist( join ( '/', $path, $file ) ) } );
33 }
34 }
35 }
36  
37 0 return \@whitelist;
38 }
39  
40  
41 0 ▶sub get_basedir {
Subroutine get_basedir: not called CC=1 SCAR=6.9
Pod documented
42 0 my ( $self ) = @_;
43 0 my $basedir = __FILE__;
44 0 $basedir =~ s/HTDocs\.pm$/htdocs/;
45 0 return $basedir;
46 }
47  
48  
49 0 ▶sub get_file {
Subroutine get_file: not called CC=3 SCAR=24.8
Pod documented
50 0 my ( $self, $file ) = @_;
51  
52 0 my $whitelisted = grep { $_ eq $file } @{ $self->get_whitelist( '' ) };
53 0 ▶ return if ! $whitelisted;
Branch: 1 branch
BranchTrueFalseTotal
unless $whitelisted 0 0 0
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 140 1;
67  
68 __END__
« Authentication/Handler/IPRev.pm ↑ Summary Authentication/Handler/XGoogleDKIM.pm »