Apache2-Dummy-RequestRec

 view release on metacpan or  search on metacpan

RequestRec.pm  view on Meta::CPAN


    return length($_[0]);
}

sub print
{
    my ($self, $out) = @_;

    $self->body($out) if $out;

    print map { "$_: " . $self->headers_out->{$_} . "\n" } keys %{ $self->headers_out };
    print "\n";
    print $self->body;
}

sub AUTOLOAD
{
    my $self = shift;

    my $method = $Apache2::Dummy::RequestRec::AUTOLOAD;
    $method =~ s/.*:://;

    $self->{$method} = $_[0] if $_[0];

    # always return undef
    return $self->{$method};
}

sub DESTROY
{
    my ($self) = @_;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME 

Apache2::Dummy::RequestRec - dummy Apache request record class for testing

=head1 VERSION

version 1.0

=head1 SYNOPSIS

Test and debug Apache2 mod_perl handlers without running an apache server.

=head1 USAGE

 use JSON;
 use Test::More;

 sub catch_stdout { ... }

 sub unescapeURIString { ... }

 sub test_http_handler
 {
     my ($handler, $exp_res, $cl, $ct, @params) = @_;
 
     my $r = Apache2::Dummy::RequestRec->new(ref($params[0]) ? { params => $params[0] } : @params);
 
     my $params = ref($params[0]) ? { params => $params[0] } : { @params };
 
     my $ares = catch_stdout(sub { &$handler($r); });
 
     my $body = $r->body;
     
     ok($r->headers_out->{'Content-Length'} == $cl, "Content-Length == $cl");
     
     ok($r->headers_out->{'Content-Type'} eq $ct, "Content-Type: '$ct'");
     
     my $result = $ct =~ /json/i ? from_json(unescapeURIString($body)) : $body;
     
     ok(Compare($result, $exp_res), "body");
 }
 
 test_http_handler('My::Apache::Request::handler', { redirect => "https://localhost/" }, 55, 'application/json', login => 'mylogin', password => 'mypasswd');

=head1 DESCRIPTION

B<Apache2::Dummy::RequestRec> can be used to test Apache2 mod_perl request handlers without an actual web server running. The difference to other similar modules is, that it uses L<APR::Table> and L<APR::Pool> to act much more like a real Apache.

=head1 AUTHOR

Jens Fischer <jeff@lipsia.de>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by Jens Fischer.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut



( run in 1.329 second using v1.01-cache-2.11-cpan-39bf76dae61 )