1 package PLP::Tie::Headers;
9 =head1 PLP::Tie::Headers
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'}>.
14 tie %somehash, 'PLP::Tie::Headers';
16 This module is part of the PLP internals and probably not of much use to others.
21 return bless [ # Defaults
23 'Content-Type' => 'text/html',
24 'X-PLP-Version' => $PLP::VERSION,
27 'content-type' => 'Content-Type',
28 'x-plp-version' => 'X-PLP-Version',
30 1 # = content-type untouched
35 my ($self, $key) = @_;
36 if ($self->[2] and defined $self->[0]->{'Content-Type'}) {
37 my $utf8 = eval { grep {$_ eq "utf8"} PerlIO::get_layers(*STDOUT) };
38 $self->[0]->{'Content-Type'} .= '; charset=utf-8' if $utf8;
42 defined ($key = $self->[1]->{lc $key}) or return;
43 return $self->[0]->{$key};
47 my ($self, $key, $value) = @_;
49 if ($PLP::sentheaders) {
51 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"
55 if (defined $self->[1]->{lc $key}){
56 $key = $self->[1]->{lc $key};
58 $self->[1]->{lc $key} = $key;
60 $self->[2] = 0 if $key eq 'Content-Type';
61 return ($self->[0]->{$key} = $value);
65 my ($self, $key) = @_;
67 defined ($key = delete $self->[1]->{lc $key}) or return;
68 return delete $self->[0]->{$key};
77 my ($self, $key) = @_;
79 return exists $self->[1]->{lc $key};
85 return each %{ $self->[0] }; # Key only, Tie::Hash doc is wrong.
89 return each %{ $_[0]->[0] };