blib/lib/ASP4/StaticHandler.pm

filter: Statementstmt 100% 31 / 31 Branchbran 62.5% 5 / 8 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 86.7% 46 / 53 CC 7 SCAR 16.0
CC
7
Cov
89%
run
7.2
BEGIN
1.0
BEGIN
1.0
CRAP 4.9
« blib/lib/ASP4/SessionStateManager/Memcached.pm ↑ Summary blib/lib/ASP4/UserAgent.pm »
1  
2 package
3 ASP4::StaticHandler;
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use base 'ASP4::FormHandler';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use vars __PACKAGE__->VARS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub run
11 4 ▶{
Subroutine run: called CC=7 SCAR=19.7
Pod documented
12 4 my ($s, $context) = @_;
13
14 my $file = $ENV{SCRIPT_FILENAME} ?
15 $ENV{SCRIPT_FILENAME} :
16 4 ▶ $Server->MapPath( (split /\?/, $ENV{REQUEST_URI})[0] );
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'SCRIPT_FILENAME'} ? : 4 0 4
17
18 4 ▶ unless( $file && -f $file )
Branch: 1 branch
BranchTrueFalseTotal
unless ($file and -f $file) 2 2 4
Condition66%2/3
$file and -f $file
!ll&&!rl&&r
022
MC/DC50%1/2
$file and -f $file
$file -f $file
Truth table66%2/3
A and B
A= $fileB= -f $file
ABresult
0X0
100
111
19 {
20 2 $Response->Status( 404 );
21 2 $Response->End;
22 2 return 404;
23 }# end unless()
24 2 ▶ open my $ifh, '<', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $ifh, "<", $file or die "Cannot open '${file}' for reading: $!" 2 0 2
25 or die "Cannot open '$file' for reading: $!";
26 2 local $/;
27 2 $Response->SetHeader('content-length' => (stat($file))[7] );
28
29 2 my ($ext) = $file =~ m{\.([^\.]+)$};
30 2 my %types = (
31 swf => 'application/x-shockwave-flash',
32 xml => 'text/xml',
33 jpg => 'image/jpeg',
34 jpeg => 'image/jpeg',
35 png => 'image/png',
36 bmp => 'image/bmp',
37 gif => 'image/gif',
38 json => 'application/x-json',
39 css => 'text/css',
40 pdf => 'application/x-pdf',
41 js => 'text/javascript',
42 svg => 'image/svg+xml',
43 html => 'text/html',
44 );
45 2 ▶ my $type = $types{lc($ext)} || 'application/octet-stream';
Condition50%1/2
$types{lc $ext} || 'application/octet-stream'
l!l
02
MC/DC0%0/1
$types{lc $ext} || 'application/octet-stream'
$types{lc $ext}
Truth table50%1/2
A
A= $types{lc $ext}
Aresult
11
00
46 2 $Response->ContentType( $type );
47
48 2 my ($filename) = $file =~ m{([^/]+)$};
49 2 ▶ my $disp = lc($type) eq 'pdf' ? 'attachment' : 'inline';
Branch: 1 branch
BranchTrueFalseTotal
lc $type eq 'pdf' ? : 0 2 2
50 2 $Response->SetHeader('content-disposition' => qq($disp; filename="$filename"; yay=yay;));
51 2 $Response->Write( scalar(<$ifh>) );
52 2 close($ifh);
53 }# end run()
54  
55 3 1;# return true:
56  
« blib/lib/ASP4/SessionStateManager/Memcached.pm ↑ Summary blib/lib/ASP4/UserAgent.pm »