root/lang/perl/HTTP-Engine/trunk/lib/HTTP/Engine.pm @ 12621

Revision 12621, 5.0 kB (checked in by yappo, 6 years ago)

lang/perl/HTTP-Engine: Checking in changes prior to tagging of version 0.0.9. Changelog diff is:

=== Changes
==================================================================
--- Changes (revision 13205)
+++ Changes (local)
@@ -1,5 +1,9 @@

Revision history for Perl extension HTTP::Engine


+0.0.9 2008-05-28T21:22:52+09:00
+ - fix Interface::POE cannot get query string bug tokuhirom++
+ - fix more dependence on Makefile.PL
+

0.0.8 2008-05-18T13:50:36+09:00

  • Middleware API more simply
  • fix Interface::FCGI dont work lopnor++
Line 
1package HTTP::Engine;
2use Moose;
3use HTTP::Engine::Types::Core qw( Interface );
4our $VERSION = '0.0.9';
5use HTTP::Engine::Context;
6use HTTP::Engine::Request;
7use HTTP::Engine::Request::Upload;
8use HTTP::Engine::Response;
9use HTTP::Engine::RequestProcessor;
10
11has 'interface' => (
12    is      => 'ro',
13    does    => 'Interface',
14    coerce  => 1,
15    handles => [ qw(run load_plugins) ],
16);
17
18sub import {
19    my($class, %args) = @_;
20    return unless $args{middlewares} && ref $args{middlewares} eq 'ARRAY';
21    $class->load_middlewares(@{ $args{middlewares} });
22}
23
24sub load_middlewares {
25    my ($class, @middlewares) = @_;
26    for my $middleware (@middlewares) {
27        $class->load_middleware( $middleware );
28    }
29}
30
31sub load_middleware {
32    my ($class, $middleware) = @_;
33
34    require UNIVERSAL::require;
35
36    my $pkg;
37    if (($pkg = $middleware) =~ s/^(\+)//) {
38        $pkg->require or die $@;
39    } else {
40        $pkg = 'HTTP::Engine::Middleware::' . $middleware;
41        unless ($pkg->require) {
42            $pkg = 'HTTPEx::Middleware::' . $middleware;
43            $pkg->require or die $@;
44        }
45    }
46
47    if ($pkg->meta->has_method('setup')) {
48        $pkg->setup();
49    }
50
51    if ($pkg->meta->has_method('wrap')) {
52        HTTP::Engine::RequestProcessor->meta->add_around_method_modifier(
53            call_handler => $pkg->meta->get_method('wrap')->body
54        );
55    }
56}
57
581;
59__END__
60
61=for stopwords middlewares Middleware middleware
62
63=encoding utf8
64
65=head1 NAME
66
67HTTP::Engine - Web Server Gateway Interface and HTTP Server Engine Drivers (Yet Another Catalyst::Engine)
68
69=head1 SYNOPSIS
70
71  use HTTP::Engine;
72  my $engine = HTTP::Engine->new(
73      interface => {
74          module => 'ServerSimple',
75          args   => {
76              host => 'localhost',
77              port =>  1978,
78          },
79          request_handler => 'main::handle_request',# or CODE ref
80      },
81  );
82  $engine->run;
83
84  use Data::Dumper;
85  sub handle_request {
86      my $c = shift;
87      $c->res->body( Dumper($c->req) );
88  }
89
90
91=head1 CONCEPT RELEASE
92
93Version 0.0.x is a concept release, the internal interface is still fluid.
94It is mostly based on the code of Catalyst::Engine.
95
96=head1 DESCRIPTION
97
98HTTP::Engine is a bare-bones, extensible HTTP engine. It is not a
99socket binding server.
100
101The purpose of this module is to be an adaptor between various HTTP-based
102logic layers and the actual implementation of an HTTP server, such as,
103mod_perl and FastCGI.
104
105Internally, the only thing HTTP::Engine will do is to prepare a
106HTTP::Engine::Request object for you to handle, and pass to your handler's
107C<TBD> method. In turn your C<TBD> method should return a fully prepared
108HTTP::Engine::Response object.
109
110HTTP::Engine will handle absorbing the differences between the environment,
111the I/O, etc. Your application can focus on creating response objects
112(which is pretty much what your typical webapp is doing)
113
114=head1 INTERFACES
115
116Interfaces are the actual environment-dependent components which handles
117the actual interaction between your clients and the application.
118
119For example, in CGI mode, you can write to STDOUT and expect your clients to
120see it, but in mod_perl, you may need to use $r-E<gt>print instead.
121
122Interfaces are the actual layers that does the interaction. HTTP::Engine
123currently supports the following:
124
125# XXX TODO: Update the list
126
127=over 4
128
129=item HTTP::Engine::Interface::ServerSimple
130
131=item HTTP::Engine::Interface::FastCGI
132
133=item HTTP::Engine::Interface::CGI
134
135=item HTTP::Engine::Interface::Test
136
137for test code interface
138
139=item HTTP::Engine::Interface::ModPerl
140
141experimental
142
143=item HTTP::Engine::Interface::Standalone
144
145old style
146
147=back
148
149Interfaces can be specified as part of the HTTP::Engine constructor:
150
151  my $interface = HTTP::Engine::Interface::FastCGI->new(
152    handler => ...
153  );
154  HTTP::Engine->new(
155    interface => $interface
156  )->run();
157
158Or you can let HTTP::Engine instantiate the interface for you:
159
160  HTTP::Engine->new(
161    interface => {
162      module => 'FastCGI',
163      args   => {
164        handler => ...
165      }
166    }
167  )->run();
168
169=head1 MIDDLEWARES
170
171For all non-core middlewares (consult #codrepos first), use the HTTPEx::
172namespace. For example, if you have a plugin module named "HTTPEx::Middleware::Foo",
173you could load it as
174
175  use HTTP::Engine middlewares => [ qw( +HTTPEx::Plugin::Foo ) ];
176
177=head1 METHODS
178
179=over 4
180
181=item load_middleware(middleware)
182
183=item load_middlewares(qw/ middleware middleware /)
184
185Loads the given middleware into the HTTP::Engine.
186
187=back
188
189=head1 AUTHOR
190
191Kazuhiro Osawa E<lt>ko@yappo.ne.jpE<gt>
192
193Daisuke Maki
194
195tokuhirom
196
197nyarla
198
199marcus
200
201hidek
202
203dann
204
205typester (Interface::FCGI)
206
207lopnor
208
209=head1 SEE ALSO
210
211wiki page L<http://coderepos.org/share/wiki/HTTP%3A%3AEngine>
212
213L<Moose>
214
215=head1 REPOSITORY
216
217  svn co http://svn.coderepos.org/share/lang/perl/HTTP-Engine/trunk HTTP-Engine
218
219HTTP::Engine's Subversion repository is hosted at L<http://coderepos.org/share/>.
220patches and collaborators are welcome.
221
222=head1 LICENSE
223
224This library is free software; you can redistribute it and/or modify
225it under the same terms as Perl itself.
226
227=cut
Note: See TracBrowser for help on using the browser.