blib/lib/PLP/Tie/Headers.pm

filter: Statementstmt 89.5% 43 / 48 Branchbran 78.5% 11 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 81.8% 9 / 11 Podpod n/a totaltotal 84.6% 66 / 78 CC 9 SCAR 10.7
CC
9
Cov
86%
FETCH
5.0
STORE
4.0
DELETE
2.0
CRAP 2.9
« blib/lib/PLP/Tie/Print.pm ↑ Summary blib/lib/PLP/Backend/FastCGI.pm »
1 package PLP::Tie::Headers;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '1.01';
8  
9 =head1 PLP::Tie::Headers
10  
11 Makes a hash case insensitive, and sets some headers. <_> equals <->, so C<$foo{CONTENT_TYPE}> is
12 the same as C<$foo{'Content-Type'}>.
13  
14 tie %somehash, 'PLP::Tie::Headers';
15  
16 This module is part of the PLP internals and probably not of much use to others.
17  
18 =cut
19  
20 23 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=1 SCAR=0.0
21 23 return bless [ # Defaults
22 {
23 'Content-Type' => 'text/html',
24 'X-PLP-Version' => $PLP::VERSION,
25 },
26 {
27 'content-type' => 'Content-Type',
28 'x-plp-version' => 'X-PLP-Version',
29 },
30 1 # = content-type untouched
31 ], $_[0];
32 }
33  
34 52 ▶sub FETCH {
Subroutine FETCH: called CC=5 SCAR=16.2
35 52 my ($self, $key) = @_;
36 52 ▶ if ($self->[2] and defined $self->[0]->{'Content-Type'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[2] and defined $self->[0]{"Content-Type"}) 23 29 52
Condition66%2/3
$self->[2] and defined $self->[0]{"Content-Type"}
!ll&&!rl&&r
29023
MC/DC50%1/2
$self->[2] and defined $self->[0]{"Content-Type"}
$self->[2] defined $self->[0]{"Content-Type"}
Truth table66%2/3
A and B
A= $self->[2]B= defined $self->[0]{"Content-Type"}
ABresult
0X0
100
111
37 23 my $utf8 = eval { grep {$_ eq "utf8"} PerlIO::get_layers(*STDOUT) };
38 23 ▶ $self->[0]->{'Content-Type'} .= '; charset=utf-8' if $utf8;
Branch: 1 branch
BranchTrueFalseTotal
if $utf8 1 22 23
39 23 $self->[2] = 0;
40 }
41 52 $key =~ tr/_/-/;
42 52 ▶ defined ($key = $self->[1]->{lc $key}) or return;
Branch: 1 branch
BranchTrueFalseTotal
defined($key = $self->[1]{lc $key}) or return 52 0 52
43 52 return $self->[0]->{$key};
44 }
45  
46 4 ▶sub STORE {
Subroutine STORE: called CC=4 SCAR=13.9
47 4 my ($self, $key, $value) = @_;
48 4 $key =~ tr/_/-/;
49 4 ▶ if ($PLP::sentheaders) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PLP::sentheaders) 1 3 4
50 1 my @caller = caller;
51 1 die "Can't set headers after sending them at " .
52 "$caller[1] line $caller[2].\n(Output started at " .
53 "$PLP::sentheaders->[0] line $PLP::sentheaders->[1].)\n"
54 }
55 3 ▶ if (defined $self->[1]->{lc $key}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[1]{lc $key}) { } 1 2 3
56 1 $key = $self->[1]->{lc $key};
57 } else {
58 2 $self->[1]->{lc $key} = $key;
59 }
60 3 ▶ $self->[2] = 0 if $key eq 'Content-Type';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "Content-Type" 0 3 3
61 3 return ($self->[0]->{$key} = $value);
62 }
63  
64 1 ▶sub DELETE {
Subroutine DELETE: called CC=2 SCAR=7.0
65 1 my ($self, $key) = @_;
66 1 $key =~ tr/_/-/;
67 1 ▶ defined ($key = delete $self->[1]->{lc $key}) or return;
Branch: 1 branch
BranchTrueFalseTotal
defined($key = delete $self->[1]{lc $key}) or return 1 0 1
68 1 return delete $self->[0]->{$key};
69 }
70  
71 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=1 SCAR=6.9
72 0 my $self = $_[0];
73 0 return (@$self = ());
74 }
75  
76 0 ▶sub EXISTS {
Subroutine EXISTS: not called CC=1 SCAR=6.9
77 0 my ($self, $key) = @_;
78 0 $key =~ tr/_/-/;
79 0 return exists $self->[1]->{lc $key};
80 }
81  
82 24 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
83 24 my $self = $_[0];
84 24 keys %{$self->[0]};
85 24 return each %{ $self->[0] }; # Key only, Tie::Hash doc is wrong.
86 }
87  
88 49 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=1 SCAR=0.0
89 49 return each %{ $_[0]->[0] };
90 }
91  
92 2 1;
93  
« blib/lib/PLP/Tie/Print.pm ↑ Summary blib/lib/PLP/Backend/FastCGI.pm »