Catalyst-Engine-Embeddable
view release on metacpan or search on metacpan
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Catalyst-Engine-Embeddable
no_index:
directory:
- inc
- t
requires:
Catalyst::Runtime: 5.80004
HTTP::Body: 0
HTTP::Request: 0
HTTP::Response: 0
Moose: 0
URI: 0
namespace::autoclean: 0
resources:
license: http://dev.perl.org/licenses/
repository: http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Engine-Embeddable/trunk/
version: 0.000003
Makefile.PL view on Meta::CPAN
use 5.008006;
use inc::Module::Install 0.91;
name 'Catalyst-Engine-Embeddable';
all_from 'lib/Catalyst/Engine/Embeddable.pm';
requires 'Catalyst::Runtime' => '5.80004';
requires 'Moose';
requires 'namespace::autoclean' => '0';
requires 'URI' => '0';
requires 'HTTP::Response' => '0';
requires 'HTTP::Request' => '0';
requires 'HTTP::Body' => '0';
auto_install;
resources repository => 'http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Engine-Embeddable/trunk/';
WriteAll;
lib/Catalyst/Engine/Embeddable.pm view on Meta::CPAN
=head1 SUMMARY
This module provides a way to embed a Catalyst application in any
other program using standard Perl Object Orientation to do a request
and get the response.
It works by using the arguments that are passed from the
handle_request method in the Catalyst module to the prepare_request
method in the engine, which will then handle the request as coming
from the HTTP::Request object passed, instead of trying to fetch the
elements from the ENV, like the CGI engine does.
As the handle_request method only returns the response code and not
the response object at all, in the case you want the complete response
you need to pass a second argument which is a scalar ref where the
HTTP::Response object will be stored in the "finalize" phase of the
processing.
This engine provides complete compatibility with any plugin the
application may use, in a way that different embedded applications may
lib/Catalyst/Engine/Embeddable.pm view on Meta::CPAN
This method is overriden in order to store the request and the
response in $c as to continue the processing later. The scalar ref
here will be used to set the response object, as there is no other way
to obtain the response.
This information will be stored as $c->req->{_engine_embeddable}{req} and
$c->req->{_engine_embeddable}{res} for future usage.
=item $engine->prepare_headers($c)
This is where the headers are fetched from the HTTP::Request object
and set into $c->req.
=item $engine->prepare_path($c)
Get the path info from the HTTP::Request object.
=item $engine->prepare_query_parameters($c)
Set the query params from the HTTP::Request to the catalyst request.
=item $engine->prepare_body($c)
Gets the body of the HTTP::Request, creates an HTTP::Body object, and
set it in $c->req->{_body}, then being compatible with
Catalyst::Engine from now on.
=item $engine->finalize_headers($c)
Set the "Status" header in the response and store the headers from the
catalyst response object to the HTTP::Response object.
=item $engine->finalize_body($c)
Copies the body from the catalyst response to the HTTP::Response
object.
=back
=head1 SEE ALSO
L<Catalyst::Engine>, L<Catalyst::Engine::CGI>, L<HTTP::Request>,
L<HTTP::Reponse>, L<Catalyst>
=head1 AUTHORS
Daniel Ruoso C<daniel@ruoso.com>
Currently maintained by Tomas Doran (t0m) C<bobtfish@bobtfish.net>
=head1 BUG REPORTS
use strict;
use warnings;
use Test::More tests => 7;
use HTTP::Request;
BEGIN { $ENV{CATALYST_ENGINE} = 'Embeddable' };
BEGIN { use_ok('Catalyst::Engine::Embeddable') };
use lib 't/lib';
require TestApp;
my ($req, $res);
$req = HTTP::Request->new(GET => 'http://www.catalystframework.org/mkuri?foo=bar');
$res = undef;
TestApp->handle_request($req, \$res);
ok($res, 'Response object defined.');
is($res->code, 200, 'Response code correct.');
is($res->content, 'http://www.catalystframework.org/path/to/somewhere');
$req = HTTP::Request->new(GET => 'http://www.catalystframework.org/mkuriwithpath?foo=bar&foo=baz&one=two');
$res = undef;
TestApp->handle_request($req, \$res);
ok($res, 'Response object defined.');
is($res->code, 200, 'Response code correct.');
is($res->content, 'http://www.catalystframework.org/path/to/somewhere?baz=qux');
use strict;
use warnings;
use Test::More tests => 10;
use HTTP::Request;
BEGIN { $ENV{CATALYST_ENGINE} = 'Embeddable' };
BEGIN { use_ok('Catalyst::Engine::Embeddable') };
use lib 't/lib';
require TestApp;
my ($req, $res, @err);
$req = HTTP::Request->new(GET => '/eatit');
$res = undef;
TestApp->handle_request($req, \$res);
ok($res, 'Response object defined.');
is($res->code, 500, 'Response code correct.');
like($res->content, qr/Please come back later/, 'exception handled by catalyst');
cmp_ok((scalar @err), '==', 0, 'no errors returned');
TestApp->handle_request($req, \$res, \@err);
t/request.t view on Meta::CPAN
use strict;
use warnings;
use Test::More tests => 10;
use HTTP::Request;
BEGIN { $ENV{CATALYST_ENGINE} = 'Embeddable' };
BEGIN { use_ok('Catalyst::Engine::Embeddable') };
use lib 't/lib';
require TestApp;
my ($req, $res);
$req = HTTP::Request->new(GET => '/foo');
$res = undef;
TestApp->handle_request($req, \$res);
ok($res, 'Response object defined.');
is($res->code, 200, 'Response code correct.');
is($res->content, 'Hello World!', 'Resonse content correct.');
$req = HTTP::Request->new(GET => '/bar?who=Embed');
$res = undef;
TestApp->handle_request($req, \$res);
ok($res, 'Response object defined.');
is($res->code, 200, 'Response code correct.');
is($res->content, 'Hello Embed!', 'Resonse content correct.');
$req = HTTP::Request->new(POST => '/bar');
$res = undef;
$req->content_type('application/x-www-form-urlencoded');
my $post_body = 'who=Post';
$req->content($post_body);
$req->content_length(length($post_body));
TestApp->handle_request($req, \$res);
ok($res, 'Response object defined.');
( run in 0.341 second using v1.01-cache-2.11-cpan-de7293f3b23 )