root/lang/perl/HTTP-Engine/branches/interface-declare/lib/HTTP/Engine/Interface/Test.pm @ 18201

Revision 18201, 1.5 kB (checked in by tokuhirom, 5 years ago)

refactoring response writer

Line 
1package HTTP::Engine::Interface::Test;
2use HTTP::Engine::Interface;
3
4use URI::WithBase;
5use IO::Scalar;
6
7builder 'NoEnv';
8
9writer {
10    finalize => sub {
11        my ( $self, $req, $res ) = @_;
12        $res->as_http_response;
13    },
14};
15
16sub run {
17    my ( $self, $request, %args ) = @_;
18
19    return $self->handle_request(
20        uri        => URI::WithBase->new( $request->uri ),
21        base       => do {
22            my $base = $request->uri->clone;
23            $base->path_query('/');
24            $base;
25        },
26        headers    => $request->headers,
27        method     => $request->method,
28        protocol   => $request->protocol,
29        address    => "127.0.0.1",
30        port       => "80",
31        user       => undef,
32        https_info => undef,
33        _connection => {
34            input_handle  => IO::Scalar->new( \( $request->content ) ),
35        },
36        %args,
37    );
38}
39
40__INTERFACE__
41
42__END__
43
44=encoding utf8
45
46=head1 NAME
47
48HTTP::Engine::Interface::Test - HTTP::Engine Test Interface
49
50=head1 SYNOPSIS
51
52  use Data::Dumper;
53  use HTTP::Engine;
54  use HTTP::Request;
55  my $response = HTTP::Engine->new(
56      interface => {
57          module => 'Test',
58      },
59      request_handler => sub {
60          my $req = shift;
61          HTTP::Engine::Response->new( body => Dumper($req) );
62      }
63  )->run(HTTP::Request->new( GET => 'http://localhost/'), \%ENV);
64
65=head1 DESCRIPTION
66
67HTTP::Engine::Interface::Test is test engine base class
68
69=head1 AUTHOR
70
71Kazuhiro Osawa E<lt>ko@yappo.ne.jpE<gt>
Note: See TracBrowser for help on using the browser.