| Test-Environment documentation | Contained in the Test-Environment distribution. |
Test::Environment::Plugin::Apache2::Apache2::RequestRec - fake Apache2::RequestRec for Test::Environment
use Test::Environment qw{
Apache2
};
my $request = Apache2::RequestRec->new(
'headers_in' => {
'Accept-Encoding' => 'xyz,gzip'
},
'hostname' => 'with.the.man.sk',
'uri' => '/index.html',
'args' => 'id=me',
);
is(
My::App:Apache2::Index::handler($request),
Apache2::Const::REDIRECT,
);
is(
$request->headers_out->get('Location'),
'http://with.the.man.sk/me/',
);
Will populate Apache2::RequestRec namespace with fake methods that can be used for testing.
hostname
uri
apr_pool
args
get_server_port
dir_config
status
content_type
method
Object constructor.
Get/Set pnote.
just calls $self->request_rec(@_);
Returns Apache2::RequestRec.
Jozef Kutej
| Test-Environment documentation | Contained in the Test-Environment distribution. |
package Test::Environment::Plugin::Apache2::Apache2::RequestRec; our $VERSION = '0.06'; 1; package Apache2::RequestRec;
use warnings; use strict; our $VERSION = '0.06'; use APR::Pool; use APR::Table; use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors(qw{ hostname uri apr_pool args get_server_port dir_config status content_type method });
sub new { my $class = shift; my $self = $class->SUPER::new({ 'get_server_port' => 80, 'apr_pool' => APR::Pool->new, 'method' => 'GET', @_, }); # initialize all apr tables foreach my $apt_table_name (qw(apr_table headers_in headers_out subprocess_env dir_config)) { my $apr_table = $self->{$apt_table_name} || APR::Table::make($self->apr_pool, 100); # if the parameter is plain HASH, convert it to APR::Table if (ref $apr_table eq 'HASH') { my $hash = $apr_table; $apr_table = APR::Table::make($self->apr_pool, 100); while (my ($key, $value) = each(%{$hash})) { $apr_table->add($key => $value); } } $self->{$apt_table_name} = $apr_table; } return $self; }
sub pnotes { my $self = shift; my $note_name = shift; if (@_ > 0) { $self->{'pnotes'}->{$note_name} = shift; } return $self->{'pnotes'}->{$note_name}; } sub unparsed_uri { my $self = shift; return $self->uri.($self->args ? '?'.$self->args : '' ); }
sub apr_table { return shift->_get_set('apr_table', @_) }; sub subprocess_env { return shift->_get_set('subprocess_env', @_) }; sub headers_in { return shift->_get_set('headers_in', @_) }; sub headers_out { return shift->_get_set('headers_out', @_) }; sub dir_config { return shift->_get_set('dir_config', @_) }; sub err_headers_out { my $self = shift; $self->headers_out(@_); } sub _get_set { my $self = shift; my $name = shift; if (@_ > 0) { my $key_name = shift; if (@_ > 0) { $self->{$name}->add($key_name => shift); } return $self->{$name}->get($key_name); } else { return $self->{$name}; } }
sub Apache2::Filter::r { my $self = shift; $self->request_rec(@_); }
sub Apache2::Filter::request_rec { my $self = shift; if (@_ > 0) { $self->{'request_rec'} = shift; } if (ref $self->{'request_rec'} ne __PACKAGE__) { $self->{'request_rec'} = bless $self->{'request_rec'}, __PACKAGE__; } return $self->{'request_rec'}; } 'writing on the wall'; __END__