Directory.pm

filter: Statementstmt 31.7% 20 / 63 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 30.0% 6 / 20 Podpod 0.0% 0 / 6 totaltotal 19.7% 26 / 132 CC 23 SCAR 35.2
CC
23
Cov
19%
_allow_cleanup
90.0
init
56.0
allow
30.0
CRAP 33.8
« Directory/UserDirs.pm ↑ Summary Session.pm »
1 # Copyrights 2008 by Mark Overmeer.
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 1.05.
5 package HTTP::Server::Directory;
6 1 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $VERSION = '0.11';
8  
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Log::Report 'httpd-multiplex', syntax => 'SHORT';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Net::CIDR qw/cidrlookup/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub _allow_cleanup($);
18 sub _allow_match($$$$);
19 sub _filename_trans($$);
20  
21  
22 sub new(@)
23 0 ▶{ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
24 0 ▶ my $args = @_==1 ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
25 0 (bless {}, $class)->init($args);
26 }
27  
28 sub init($)
29 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=7 SCAR=40.3
Pod undocumented
30  
31 0 ▶ my $path = $self->{HSD_path} = $args->{path} || '/';
Condition0%0/2
$args->{'path'} || '/'
l!l
00
MC/DC0%0/1
$args->{'path'} || '/'
$args->{'path'}
Truth table0%0/2
A
A= $args->{'path'}
Aresult
11
00
32 my $loc = $args->{location}
33 0 ▶ or error __x"directory definition requires location";
Branch: 1 branch
BranchTrueFalseTotal
my $loc = $args->{"location"} or &error(&__x("directory definition requires location")) 0 0 0
34  
35 0 ▶ if(ref $loc eq 'CODE') {;}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $loc eq 'CODE') { } 0 0 0
36 else
37 0 ▶ { File::Spec->file_name_is_absolute($loc)
Branch: 1 branch
BranchTrueFalseTotal
"File::Spec"->file_name_is_absolute($loc) or &error(&__x("directory location {loc} for path {path} not absolute", "loc", $loc, "path", $path)) 0 0 0
38 or error __x"directory location {loc} for path {path} not absolute"
39 , loc => $loc, path => $path;
40 0 ▶ -d $loc
Branch: 1 branch
BranchTrueFalseTotal
-d $loc or &error(&__x("directory location {loc} for path {path} does not exist", "loc", $loc, "path", $path)) 0 0 0
41 or error __x"directory location {loc} for path {path} does not exist"
42 , loc => $loc, path => $path;
43  
44 0 ▶ substr($loc,-1) eq '/' or $loc .= '/';
Branch: 1 branch
BranchTrueFalseTotal
substr($loc, -1) eq "/" or $loc .= '/' 0 0 0
45 }
46 0 $self->{HSD_loc} = $loc;
47 0 $self->{HSD_fn} = _filename_trans $path, $loc;
48  
49 0 $self->{HSD_allow} = _allow_cleanup $args->{allow};
50 0 $self->{HSD_deny} = _allow_cleanup $args->{deny};
51  
52 0 $self;
53 }
54  
55 #-----------------
56  
57 0 ▶sub path() {shift->{HSD_path}}
Subroutine path: not called CC=1 SCAR=6.9
Pod undocumented
58 0 ▶sub location() {shift->{HSD_location}}
Subroutine location: not called CC=1 SCAR=6.9
Pod undocumented
59  
60 #-----------------
61  
62 sub allow($$$$)
63 0 ▶{ my ($self, $client, $session, $req, $uri) = @_;
Subroutine allow: not called CC=5 SCAR=34.0
Pod undocumented
64 0 ▶ if(my $allow = $self->{HSD_allow})
Branch: 1 branch
BranchTrueFalseTotal
if (my $allow = $self->{"HSD_allow"}) 0 0 0
65 0 ▶ { $self->_allow_match($client, $session, $uri, $allow) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_allow_match($client, $session, $uri, $allow) or return 0 0 0 0
66 }
67 0 ▶ if(my $deny = $self->{HSD_deny})
Branch: 1 branch
BranchTrueFalseTotal
if (my $deny = $self->{"HSD_deny"}) 0 0 0
68 0 ▶ { $self->_allow_match($client, $session, $uri, $deny) and return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_allow_match($client, $session, $uri, $deny) and return 0 0 0 0
69 }
70 0 1;
71 }
72  
73 sub _allow_match($$$$)
74 0 ▶{ my ($self, $client, $session, $uri, $rules) = @_;
Subroutine _allow_match: not called CC=2 SCAR=17.9
75 0 my ($ip, $host) = @$client{'ip', 'host'};
76 0 ▶ first { $_->($ip, $host, $session, $uri) } @$rules ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@$rules ? : 0 0 0
77 }
78  
79 sub _allow_cleanup($)
80 0 ▶{ my $p = shift or return;
Subroutine _allow_cleanup: not called CC=9 SCAR=45.0
Branch: 1 branch
BranchTrueFalseTotal
my $p = shift() or return 0 0 0
81 0 my @p;
82 0 ▶ foreach my $r (ref $p eq 'ARRAY' ? @$p : $p)
Branch: 1 branch
BranchTrueFalseTotal
ref $p eq 'ARRAY' ? : 0 0 0
83 { push @p
84 , ref $r eq 'CODE' ? $r
85 0 ▶ : index($r, ':') >= 0 ? sub {cidrlookup $_[0], $r} # IPv6
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 0 ▶ : $r !~ m/[a-zA-Z]/ ? sub {cidrlookup $_[0], $r} # IPv4
Subroutine __ANON__: not called CC=1 SCAR=6.9
87 0 ▶ : $r =~ s/^\.// ? sub {$_[1] =~ qr/(^|\.)\Q$r\E$/i} # Domain
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 0 ▶ : sub {lc($_[1]) eq lc($r)} # hostname
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 0 ▶ }
Branch: 4 branches
BranchTrueFalseTotal
ref $r eq 'CODE' ? : 0 0 0
index($r, ':') != -1 ? : 0 0 0
!($r =~ /[a-zA-Z]/) ? : 0 0 0
$r =~ s/^\.// ? : 0 0 0
90 0 ▶ @p ? \@p : undef;
Branch: 1 branch
BranchTrueFalseTotal
@p ? : 0 0 0
91 }
92  
93  
94 0 ▶sub filename($) { $_[0]->{HSD_fn}->($_[1]) }
Subroutine filename: not called CC=1 SCAR=6.9
Pod undocumented
95  
96 sub _filename_trans($$)
97 0 ▶{ my ($path, $loc) = @_;
Subroutine _filename_trans: not called CC=2 SCAR=17.9
98 0 ▶ return $loc if ref $loc eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $loc eq "CODE" 0 0 0
99 sub
100 0 ▶ { my $x = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
101 0 ▶ $x =~ s!^\Q$path!$loc! or panic "path $x not within $path";
Branch: 1 branch
BranchTrueFalseTotal
$x =~ s/^\Q$path\E/$loc/ or &panic("path $x not within $path") 0 0 0
102 0 $x;
103 0 };
104 }
105  
106  
107 1 1;
« Directory/UserDirs.pm ↑ Summary Session.pm »