| 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
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4 | ▶ | unless( $file && -f $file ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$file and -f $file
MC/DC50%1/2
$file and -f $file
$file
-f $file
Truth table66%2/3
A and B
A= $fileB= -f $file
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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'
MC/DC0%0/1
$types{lc $ext} || 'application/octet-stream'
$types{lc $ext}
Truth table50%1/2
A
A= $types{lc $ext}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||