blib/lib/Plack/Middleware/XSendfile.pm

filter: Statementstmt 80.0% 44 / 55 Branchbran 38.8% 7 / 18 Conditioncond 35.7% 5 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 91.6% 11 / 12 Podpod 66.6% 2 / 3 totaltotal 62.1% 69 / 111 CC 15 SCAR 26.4
CC
15
Cov
64%
__ANON__
27.7
map_accel_path
6.0
_variation
3.7
CRAP 14.0
« blib/lib/Plack/Middleware/ContentMD5.pm ↑ Summary blib/lib/Plack/HTTPParser/PP.pm »
1 package Plack::Middleware::XSendfile;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use parent qw(Plack::Middleware);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Plack::Util::Accessor qw( variation );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12 1 my $class = shift;
13 1 Carp::carp("Plack::Middleware::XSendfile is deprecated and will be removed in a future release");
14 1 $class->SUPER::new(@_);
15 }
16  
17 1 ▶sub call {
Subroutine call: called CC=1 SCAR=0.8
Pod documented
18 1 my $self = shift;
19 1 my $env = shift;
20  
21 1 my $res = $self->app->($env);
22 1 ▶ $self->response_cb($res, sub {
Subroutine __ANON__: called CC=12 SCAR=33.2
23 1 my $res = shift;
24 1 my($status, $headers, $body) = @$res;
25 1 ▶ return unless defined $body;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 0 1 1
26  
27 1 ▶ if (Scalar::Util::blessed($body) && $body->can('path')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($body) and $body->can("path")) 1 0 1
Condition33%1/3
builtin::blessed($body) and $body->can("path")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($body) and $body->can("path")
builtin::blessed($body) $body->can("path")
Truth table33%1/3
A and B
A= builtin::blessed($body)B= $body->can("path")
ABresult
0X0
100
111
28 1 ▶ my $type = $self->_variation($env) || '';
Condition50%1/2
$self->_variation($env) || ''
l!l
10
MC/DC0%0/1
$self->_variation($env) || ''
$self->_variation($env)
Truth table50%1/2
A
A= $self->_variation($env)
Aresult
11
00
29 1 my $h = Plack::Util::headers($headers);
30 1 ▶ if ($type && !$h->exists($type)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and not $h->exists($type)) 1 0 1
Condition33%1/3
$type and not $h->exists($type)
!ll&&!rl&&r
001
MC/DC0%0/2
$type and not $h->exists($type)
$type not $h->exists($type)
Truth table33%1/3
A and not(B)
A= $typeB= not $h->exists($type)
ABresult
0X0
100
111
31 1 ▶ if ($type eq 'X-Accel-Redirect') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'X-Accel-Redirect') { } 0 1 1
elsif ($type eq 'X-Sendfile' or $type eq 'X-Lighttpd-Send-File') { } 1 0 1
32 0 my $path = $body->path;
33 0 my $url = $self->map_accel_path($env, $path);
34 0 ▶ $h->set($type => $url) if $url;
Branch: 1 branch
BranchTrueFalseTotal
if $url 0 0 0
35 0 $h->set('Content-Length', 0);
36 0 $body = [];
37 ▶ } elsif ($type eq 'X-Sendfile' or $type eq 'X-Lighttpd-Send-File') {
Condition33%1/3
$type eq "X-Sendfile" or $type eq "X-Lighttpd-Send-File"
l!l&&r!l&&!r
100
MC/DC0%0/2
$type eq "X-Sendfile" or $type eq "X-Lighttpd-Send-File"
$type eq "X-Sendfile" $type eq "X-Lighttpd-Send-File"
Truth table33%1/3
A or B
A= $type eq "X-Sendfile"B= $type eq "X-Lighttpd-Send-File"
ABresult
1X1
011
000
38 1 my $path = $body->path;
39 1 ▶ $h->set($type => $path) if defined $path;
Branch: 1 branch
BranchTrueFalseTotal
if defined $path 1 0 1
40 1 $h->set('Content-Length', 0);
41 1 $body = [];
42 } else {
43 0 $env->{'psgi.errors'}->print("Unknown x-sendfile variation: $type");
44 }
45 }
46 }
47  
48 1 @$res = ( $status, $headers, $body );
49 1 });
50 }
51  
52 0 ▶sub map_accel_path {
Subroutine map_accel_path: not called CC=2 SCAR=17.9
Pod undocumented
53 0 my($self, $env, $path) = @_;
54  
55 0 ▶ if (my $mapping = $env->{HTTP_X_ACCEL_MAPPING}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mapping = $env->{"HTTP_X_ACCEL_MAPPING"}) 0 0 0
56 0 my($internal, $external) = split /=/, $mapping, 2;
57 0 $path =~ s!^\Q$internal\E!$external!i;
58 }
59  
60 0 return $path;
61 }
62  
63 1 ▶sub _variation {
Subroutine _variation: called CC=3 SCAR=13.1
64 1 my($self, $env) = @_;
65 1 ▶ $self->variation || $env->{'plack.xsendfile.type'} || $env->{HTTP_X_SENDFILE_TYPE};
Branch: 1 branch
BranchTrueFalseTotal
$self->variation or $env->{"plack.xsendfile.type"} or $env->{"HTTP_X_SENDFILE_TYPE"} 0 1 1
Condition33%1/3
$self->variation or $env->{"plack.xsendfile.type"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->variation or $env->{"plack.xsendfile.type"}
$self->variation $env->{"plack.xsendfile.type"}
Truth table33%1/3
A or B
A= $self->variationB= $env->{"plack.xsendfile.type"}
ABresult
1X1
011
000
66 }
67  
68 1 1;
69  
70 __END__
« blib/lib/Plack/Middleware/ContentMD5.pm ↑ Summary blib/lib/Plack/HTTPParser/PP.pm »