X-Git-Url: http://git.shiar.nl/perl/plp/.git/blobdiff_plain/b485fa6bb934e79d44a1be1b5e41e31f4e7129b1..bf62119532c8dec24b9e534996fb2b8ba8448366:/lib/PLP/Tie/Headers.pm diff --git a/lib/PLP/Tie/Headers.pm b/lib/PLP/Tie/Headers.pm index c675f8a..ea2f172 100644 --- a/lib/PLP/Tie/Headers.pm +++ b/lib/PLP/Tie/Headers.pm @@ -26,14 +26,21 @@ sub TIEHASH { { 'content-type' => 'Content-Type', 'x-plp-version' => 'X-PLP-Version', - } + }, + 1 # = content-type untouched ], $_[0]; } sub FETCH { my ($self, $key) = @_; + if ($self->[2] and defined $self->[0]->{'Content-Type'}) { + my $utf8 = eval { grep {$_ eq "utf8"} PerlIO::get_layers(*STDOUT) }; + $self->[0]->{'Content-Type'} .= '; charset=utf-8' if $utf8; + $self->[2] = 0; + } $key =~ tr/_/-/; - return $self->[0]->{ $self->[1]->{lc $key} }; + defined ($key = $self->[1]->{lc $key}) or return; + return $self->[0]->{$key}; } sub STORE { @@ -50,6 +57,7 @@ sub STORE { } else { $self->[1]->{lc $key} = $key; } + $self->[2] = 0 if $key eq 'Content-Type'; return ($self->[0]->{$key} = $value); }