[Catalyst] Patch to Catalyst::Plugin::SubReq to restore original path

Rusty Conover rconover at infogears.com
Sat Jul 30 09:28:03 CEST 2005


In additional to fixing the path, its also a good idea IMHO to 
optionally allow request parameters to be passed as a third argument to 
the sub_request method.  The attached patch folds this feature in along 
with the path restoration fix along with a fix to the POD documentation 
for the method.

Thanks,

Rusty

-- 
Rusty Conover
InfoGears Inc.
http://www.infogears.com
406-587-5432


-------------- next part --------------
--- SubRequest.pm	2005-06-08 08:53:26.000000000 -0600
+++ /root/fixed.Subrequest.pl	2005-07-30 01:24:56.000000000 -0600
@@ -2,7 +2,7 @@
 
 use strict;
 
-our $VERSION = '0.06';
+our $VERSION = '0.07';
 
 
 =head1 NAME
@@ -13,7 +13,7 @@
 
     use Catalyst 'SubRequest';
 
-    $c->subreq('/test/foo/bar', template='magic.tt');
+    $c->subreq('/test/foo/bar', { template => 'magic.tt' });
 
 =head1 DESCRIPTION
 
@@ -24,7 +24,7 @@
 
 =over 4 
 
-=item subreq path, [stash]
+=item subreq path, [stash as hash ref], [parameters as hash ref]
 
 =item sub_request
 
@@ -39,7 +39,7 @@
 
 use Data::Dumper qw/Dumper/;
 sub sub_request {
-    my ( $c, $path, $stash ) = @_;
+    my ( $c, $path, $stash, $params ) = @_;
 
     my %old_req;
     $path =~ s/^\///;
@@ -48,16 +48,17 @@
     $old_req{args}    = $c->req->arguments;
     $old_req{action}  = $c->req->action;$c->req->action(undef);
     $old_req{path}  = $c->req->path;$c->req->path($path);
-    $old_req{params}  = $c->req->params;$c->req->{params} = {};
+    $old_req{params}  = $c->req->params;$c->req->params($params || {});
     $c->prepare_action();
     $c->log->debug("Subrequest to $path , action is ". 
-                   $c->req->action )
+                   $c->req->action)
       if $c->debug;
     $c->dispatch();
     my $output  = $c->res->output;
     $c->{stash} = $old_req{stash};
     $c->req->{params}=$old_req{params};
     $c->req->arguments($old_req{args});
+    $c->req->path($old_req{path});
     $c->res->output($old_req{content});
     return $output;
 }


More information about the Catalyst mailing list