[Catalyst-commits] r14307 - in trunk/Catalyst-Plugin-SubRequest:
lib/Catalyst/Plugin t
edenc at dev.catalyst.perl.org
edenc at dev.catalyst.perl.org
Wed Jun 20 11:39:00 GMT 2012
Author: edenc
Date: 2012-06-20 11:39:00 +0000 (Wed, 20 Jun 2012)
New Revision: 14307
Modified:
trunk/Catalyst-Plugin-SubRequest/lib/Catalyst/Plugin/SubRequest.pm
trunk/Catalyst-Plugin-SubRequest/t/02subreq.t
Log:
major refactor, all tests passing
Modified: trunk/Catalyst-Plugin-SubRequest/lib/Catalyst/Plugin/SubRequest.pm
===================================================================
--- trunk/Catalyst-Plugin-SubRequest/lib/Catalyst/Plugin/SubRequest.pm 2012-06-14 19:41:17 UTC (rev 14306)
+++ trunk/Catalyst-Plugin-SubRequest/lib/Catalyst/Plugin/SubRequest.pm 2012-06-20 11:39:00 UTC (rev 14307)
@@ -2,7 +2,6 @@
use strict;
use warnings;
-use Time::HiRes qw/tv_interval/;
our $VERSION = '0.17';
@@ -84,56 +83,27 @@
sub sub_request_response {
my ( $c, $path, $stash, $params ) = @_;
+ $stash ||= {};
+ my $env = $c->request->env;
+ local $env->{PATH_INFO} = $path;
+ local $env->{REQUEST_URI} = $env->{SCRIPT_NAME} . $path;
+ $env->{REQUEST_URI} =~ s|//|/|g;
+ my $response_cb = $c->response->_response_cb;
+ my $class = ref($c) || $c;
- $path =~ s#^/##;
-
- $params ||= {};
-
- my %request_mods = (
- body => undef,
- action => undef,
- match => undef,
- parameters => $params,
- );
-
- if (ref $path eq 'HASH') {
- @request_mods{keys %$path} = values %$path;
- $path = $path->{path};
- } else {
- $request_mods{path} = $path;
- }
- $request_mods{_body} = delete $request_mods{body};
-
- my $fake_engine = bless(
- {
- orig_request => $c->req,
- request_mods => \%request_mods,
- },
- 'Catalyst::Plugin::SubRequest::Internal::FakeEngine'
- );
-
- my $class = ref($c);
-
- no strict 'refs';
- no warnings 'redefine';
-
- local *{"${class}::engine"} = sub { $fake_engine };
-
- my $inner_ctx = $class->prepare;
-
- $inner_ctx->stash($stash || {});
-
-
$c->stats->profile(
- begin => 'subrequest: /' . $path,
+ begin => 'subrequest: ' . $path,
comment => '',
) if ($c->debug);
- $inner_ctx->dispatch;
+ my $i_ctx = $class->prepare(env => $env, response_cb => $response_cb);
+ $i_ctx->stash($stash);
+ $i_ctx->dispatch;
+ $i_ctx->finalize;
- $c->stats->profile( end => 'subrequest: /' . $path ) if ($c->debug);
+ $c->stats->profile( end => 'subrequest: ' . $path ) if $c->debug;
- return $inner_ctx->response;
+ return $i_ctx->response;
}
=head1 SEE ALSO
@@ -146,9 +116,14 @@
Tomas Doran (t0m) C<< bobtfish at bobtfish.net >>
+=head1 MAINTAINERS
+
+Eden Cardim (edenc) C<eden at insoli.de>
+
=head1 THANK YOU
SRI, for writing the awesome Catalyst framework
+MIYAGAWA, for writing the awesome Plack toolkit
=head1 COPYRIGHT
@@ -163,23 +138,4 @@
=cut
-package # hide from PAUSE
- Catalyst::Plugin::SubRequest::Internal::FakeEngine;
-
-sub AUTOLOAD { return 1; } # yeah yeah yeah
-
-sub prepare {
- my ($self, $c) = @_;
- my $req = $c->request;
-
- @{$req}{keys %{$self->{orig_request}}} = values %{$self->{orig_request}};
- while (my ($key,$value) = each %{$self->{request_mods}}) {
- if (my $mut = $req->can($key)) {
- $req->$mut($value);
- } else {
- $req->{$key} = $value;
- }
- }
-}
-
1;
Modified: trunk/Catalyst-Plugin-SubRequest/t/02subreq.t
===================================================================
--- trunk/Catalyst-Plugin-SubRequest/t/02subreq.t 2012-06-14 19:41:17 UTC (rev 14306)
+++ trunk/Catalyst-Plugin-SubRequest/t/02subreq.t 2012-06-20 11:39:00 UTC (rev 14307)
@@ -29,7 +29,7 @@
{
ok( my $response = request('/subtest_req'), 'Sub request not stomping original request object' );
is( $response->code, 200, 'OK status code' );
- is( $response->content, '/subtest_req', 'Normal request content' );
+ is( $response->content, '/subtest_req3', 'Normal request content' );
}
{
More information about the Catalyst-commits
mailing list