root/lang/perl/HTTP-Engine/trunk/lib/HTTP/Engine/Interface/POE.pm @ 17696

Revision 17696, 1.9 kB (checked in by tokuhirom, 5 years ago)

fix up docs.

Line 
1package HTTP::Engine::Interface::POE;
2use Moose;
3with 'HTTP::Engine::Role::Interface';
4use constant should_write_response_line => 1;
5use POE qw/
6    Component::Server::TCP
7/;
8use POE::Filter::HTTPD;
9use HTTP::Request::AsCGI;
10
11has host => (
12    is      => 'ro',
13    isa     => 'Str',
14    default => '127.0.0.1',
15);
16
17has port => (
18    is       => 'ro',
19    isa      => 'Int',
20    default  => 1978,
21);
22
23has alias => (
24    is       => 'ro',
25    isa      => 'Str | Undef',
26);
27
28sub run {
29    my ($self) = @_;
30
31    # setup poe session
32    POE::Component::Server::TCP->new(
33        Port         => $self->port,
34        Address      => $self->host,
35        ClientFilter => 'POE::Filter::HTTPD',
36        ( $self->alias ? ( Alias => $self->alias ) : () ),
37        ClientInput  => _client_input($self),
38    );
39}
40
41sub _client_input {
42    my $self = shift;
43
44    sub {
45        my ( $kernel, $heap, $request ) = @_[ KERNEL, HEAP, ARG0 ];
46
47        # Filter::HTTPD sometimes generates HTTP::Response objects.
48        # They indicate (and contain the response for) errors that occur
49        # while parsing the client's HTTP request.  It's easiest to send
50        # the responses as they are and finish up.
51        if ( $request->isa('HTTP::Response') ) {
52            $heap->{client}->put($request);
53            $kernel->yield('shutdown');
54            return;
55        }
56
57        # follow is normal workflow.
58        my $ascgi = HTTP::Request::AsCGI->new($request)->setup;
59        do {
60            $self->handle_request();
61        };
62        $ascgi->restore;
63
64        $heap->{client}->put($ascgi->response);
65        $kernel->yield('shutdown');
66    }
67}
68
691;
70__END__
71
72=head1 NAME
73
74HTTP::Engine::Interface::POE - POE interface for HTTP::Engine.
75
76=head1 DESCRIPTION
77
78This is POE interface for HTTP::Engine.
79
80=head1 ATTRIBUTES
81
82=over 4
83
84=item host
85
86The bind address of TCP server.
87
88=item port
89
90The port number of TCP server.
91
92=back
93
94=head1 SEE ALSO
95
96L<HTTP::Engine>
97
Note: See TracBrowser for help on using the browser.