| 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
Condition66%2/3
$self->[2] and defined $self->[0]{"Content-Type"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 39 | 23 | $self->[2] = 0; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 52 | $key =~ tr/_/-/; | |||||||||||||||||||||||||||
| 42 | 52 | ▶ | defined ($key = $self->[1]->{lc $key}) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||