| 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
Condition100%3/3
ref $self->when and ref $self->when eq "ARRAY"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 28 | 4 | ▶ | next if defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$self->code and $self->code ne $res->[0]
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]
| |||||||||||||||||||||||||||||
| 54 | 1 | return; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 31 | my $headers = $res->[1]; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 31 | ▶ | if ($self->when and !$self->when->(@$headers)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->when and not $self->when->(@$headers)
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)
| |||||||||||||||||||||||||||||
| 60 | 4 | return; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 27 | ▶ | if ( $self->set ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 69 | 4 | push @$headers, @{$self->append}; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 27 | ▶ | if ( $self->unset ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 2 | Plack::Util::header_remove($headers, $_) for @{$self->unset}; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 32 | ); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 5 | 1; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||