blib/lib/Plack/Middleware/Headers.pm

filter: Statementstmt 100% 54 / 54 Branchbran 100% 26 / 26 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 100% 108 / 108 CC 18 SCAR 17.6
CC
18
Cov
100%
__ANON__
9.0
__ANON__
8.0
prepare_app
3.0
CRAP 5.8
↑ Summary
1 package Plack::Middleware::Headers;
2 #ABSTRACT: modify HTTP response headers
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use parent qw(Plack::Middleware);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Plack::Util::Accessor qw(set append unset code when);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 our $VERSION = '0.11'; #VERSION
13  
14 16 ▶sub prepare_app {
Subroutine prepare_app: called CC=3 SCAR=11.0
Pod documented
15 16 my $self = shift;
16  
17 16 ▶ if (ref $self->when and ref $self->when eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->when and ref $self->when eq "ARRAY") 4 12 16
Condition100%3/3
ref $self->when and ref $self->when eq "ARRAY"
!ll&&!rl&&r
844
MC/DC100%2/2
ref $self->when and ref $self->when eq "ARRAY"
ref $self->when ref $self->when eq "ARRAY"
Truth table100%3/3
A and B
A= ref $self->whenB= ref $self->when eq "ARRAY"
ABresult
0X0
100
111
18 4 my @when = @{$self->when};
19 8 ▶ $self->when( sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
20 8 my @headers = @_;
21 8 my $match = 0;
22 8 ▶ for (my $i = 0; $i < @when; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @when) 18 2 20
23 18 my ($key, $check) = ($when[ $i ], $when[ $i + 1 ]);
24  
25 18 my $value = Plack::Util::header_get(\@headers, $key);
26  
27 18 ▶ if (!defined $check) { # missing header check
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $check) { } 4 14 18
elsif (not defined $value) { } 4 10 14
elsif (ref $check) { } 6 4 10
elsif ($value ne $check) { } 2 2 4
28 4 ▶ next if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 2 2 4
29 } elsif( !defined $value ) { # header missing
30 4 next;
31 } elsif( ref $check ) { # regex match header
32 6 ▶ next if $value !~ $check;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /$check/ 4 2 6
33 } elsif ( $value ne $check ) { # exact header
34 2 next;
35 }
36  
37 6 return 1;
38 }
39 2 return;
40 4 });
41 }
42 }
43  
44 32 ▶sub call {
Subroutine call: called CC=1 SCAR=0.0
Pod documented
45 32 my $self = shift;
46 32 my $res = $self->app->(@_);
47  
48 $self->response_cb(
49 $res,
50 32 ▶ sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
51 32 my $res = shift;
52  
53 32 ▶ if ($self->code and $self->code ne $res->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->code and $self->code ne $res->[0]) 1 31 32
Condition100%3/3
$self->code and $self->code ne $res->[0]
!ll&&!rl&&r
3011
MC/DC100%2/2
$self->code and $self->code ne $res->[0]
$self->code $self->code ne $res->[0]
Truth table100%3/3
A and B
A= $self->codeB= $self->code ne $res->[0]
ABresult
0X0
100
111
54 1 return;
55 }
56  
57 31 my $headers = $res->[1];
58  
59 31 ▶ if ($self->when and !$self->when->(@$headers)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->when and not $self->when->(@$headers)) 4 27 31
Condition100%3/3
$self->when and not $self->when->(@$headers)
!ll&&!rl&&r
15124
MC/DC100%2/2
$self->when and not $self->when->(@$headers)
$self->when not $self->when->(@$headers)
Truth table100%3/3
A and not(B)
A= $self->whenB= not $self->when->(@$headers)
ABresult
0X0
100
111
60 4 return;
61 }
62  
63 27 ▶ if ( $self->set ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->set) 21 6 27
64 Plack::Util::header_iter(
65 21 ▶ $self->set, sub {Plack::Util::header_set($headers, @_)}
Subroutine __ANON__: called CC=1 SCAR=0.0
66 21 );
67 }
68 27 ▶ if ( $self->append ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->append) 4 23 27
69 4 push @$headers, @{$self->append};
70 }
71 27 ▶ if ( $self->unset ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->unset) 2 25 27
72 2 Plack::Util::header_remove($headers, $_) for @{$self->unset};
73 }
74 }
75 32 );
76 }
77  
78 5 1;
79  
80 __END__
↑ Summary