X-Git-Url: http://git.shiar.nl/perl/plp/.git/blobdiff_plain/0f5e78a789961923b45cae1a881c655fff9e7283..5ab467e41cb66512bdd8ddbb9b3f0504aed448da:/PLP/Tie/Headers.pm?ds=sidebyside diff --git a/PLP/Tie/Headers.pm b/PLP/Tie/Headers.pm index e5f79a8..566b198 100644 --- a/PLP/Tie/Headers.pm +++ b/PLP/Tie/Headers.pm @@ -1,6 +1,5 @@ -#----------------------------# - package PLP::Tie::Headers; -#----------------------------# +package PLP::Tie::Headers; + use strict; use Carp; @@ -11,16 +10,12 @@ the same as C<$foo{'Content-Type'}>. tie %somehash, 'PLP::Tie::Headers'; -=cut +This module is part of the PLP internals and probably not of much use to others. -sub _lc($) { - local $_ = $_[0]; - tr/_/-/; - return lc; -} +=cut sub TIEHASH { - return bless [ # Defaults. + return bless [ # Defaults { 'Content-Type' => 'text/html', 'X-PLP-Version' => $PLP::VERSION, @@ -34,15 +29,22 @@ sub TIEHASH { sub FETCH { my ($self, $key) = @_; - return $self->[0]->{ $self->[1]->{_lc $key} }; + $key =~ tr/_/-/; + return $self->[0]->{ $self->[1]->{lc $key} }; } sub STORE { my ($self, $key, $value) = @_; - croak 'Can\'t set headers after sending them!' if $PLP::sentheaders; - if (defined $self->[1]->{_lc $key}){ - $key = $self->[1]->{_lc $key}; - }else{ + $key =~ tr/_/-/; + if ($PLP::sentheaders) { + my @caller = caller; + die "Can't set headers after sending them at " . + "$caller[1] line $caller[2].\n(Output started at " . + "$PLP::sentheaders->[0] line $PLP::sentheaders->[1].)\n" + } + if (defined $self->[1]->{lc $key}){ + $key = $self->[1]->{lc $key}; + } else { $self->[1]->{lc $key} = $key; } return ($self->[0]->{$key} = $value); @@ -50,8 +52,9 @@ sub STORE { sub DELETE { my ($self, $key) = @_; + $key =~ tr/_/-/; delete $self->[0]->{$key}; - return delete $self->[1]->{_lc $key}; + return delete $self->[1]->{lc $key}; } sub CLEAR { @@ -61,7 +64,8 @@ sub CLEAR { sub EXISTS { my ($self, $key) = @_; - return exists $self->[1]->{_lc $key}; + $key =~ tr/_/-/; + return exists $self->[1]->{lc $key}; } sub FIRSTKEY {