APR-HTTP-Headers-Compat
view release on metacpan or search on metacpan
lib/APR/HTTP/Headers/Compat.pm view on Meta::CPAN
package APR::HTTP::Headers::Compat;
use warnings;
use strict;
use Carp;
use APR::HTTP::Headers::Compat::MagicHash;
use base qw( HTTP::Headers );
=head1 NAME
APR::HTTP::Headers::Compat - Make an APR::Table look like an HTTP::Headers
=head1 VERSION
This document describes APR::HTTP::Headers::Compat version 0.02
=cut
our $VERSION = '0.02';
=head1 SYNOPSIS
use APR::HTTP::Headers::Compat;
# We're running under mod_perl2...
my $hdrs = APR::HTTP::Headers::Compat->new( $r->headers_out );
# Now we can treat $hdrs as if it was an HTTP::Headers
$hdrs->header( 'Content-Type' => 'text/plain' );
=head1 DESCRIPTION
Under mod_perl HTTP headers are stashed in L<APR::Table> objects.
Sometimes you will encounter code (such as L<FirePHP::Dispatcher>) that
needs an L<HTTP::Headers>. This module wraps an C<APR::Table> in a
subclass of C<HTTP::Headers> so that it can be used wherever an
C<HTTP::Headers> is expected.
Synchronisation is bi-directional; changes via the C<HTTP::Headers>
interface are reflected immediately in the underlying C<APR::Table> and
direct changes to the table show up immediately in the wrapper.
=head1 INTERFACE
Unless otherwise stated below all methods are inherited from
C<HTTP::Headers>.
=head2 C<< new >>
Create a new wrapper around an existing C<APR::Table>.
# Normally you'll be given the table - we're creating one here for the
# sake of the example
my $table = APR::Table::make( APR::Pool->new, 1 );
# Wrap the table so it can be used as an HTTP::Headers instance
my $h = APR::HTTP::Headers::Compat->new( $table );
Optionally header initialisers may be passed:
my $h = APR::HTTP::Headers::Compat->new( $table,
'Content-type' => 'text/plain'
);
=cut
sub new {
my ( $class, $table ) = ( shift, shift );
my %self = %{ $class->SUPER::new( @_ ) };
tie %self, 'APR::HTTP::Headers::Compat::MagicHash', $table, %self;
return bless \%self, $class;
}
sub _magic { tied %{ shift() } }
=head2 C<< clone >>
Clone this object. The clone is a regular L<HTTP::Headers> object rather
than an C<APR::HTTP::Headers::Compat>.
=cut
sub clone { bless { %{ shift() } }, 'HTTP::Headers' }
=head2 C<< table >>
Get the underlying L<APR::Table> object. Changes made in either the
table or the wrapper are reflected immediately in the other.
=cut
sub table { shift->_magic->table }
=head2 C<< remove_content_headers >>
This will remove all the header fields used to describe the content of a
message. All header field names prefixed with Content- falls into this
category, as well as Allow, Expires and Last-Modified. RFC 2616 denote
these fields as Entity Header Fields.
The return value is a new C<HTTP::Headers> object that contains the
( run in 1.423 second using v1.01-cache-2.11-cpan-22024b96cdf )