added support for passing stash
Marcus Ramberg [Wed, 8 Jun 2005 14:52:51 +0000 (14:52 +0000)]
prepared for release.

Changes
SubRequest.pm

diff --git a/Changes b/Changes
index ee302ac..b48c549 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,14 +1,17 @@
 Revision history for Perl extension Catalyst::Plugin::Static.
 
-0.05  Sat Mar 19 20:27:00 2005
+0.06  2005-06-xx 20:27:00 
+        - Flush params as well
+        - allow stuff to be passed to the stash
+0.05  2005-03-19 20:27:00 
         - Added a log message in debug mode.
-0.04  Sat Mar 19 20:27:00 2005
+0.04  2005-03-19 20:27:00
         - Updated forward to cat5 style
         - Using Catalyst::Dispatch::dispatch instead of forward.
-0.03  Sat Mar 19 20:27:00 2005
+0.03  2005-03-19 20:27:00
         - Fixed documentation.
-0.02  Sat Feb 19 10:32:00 2005
+0.02  2005-03-19 10:32:00
         - Ooops, missed MANIFEST
 
-0.01  Fri Mar 5 22:00:00 2005
+0.01  2005-03-05 22:00:00
         - first release
index 306b0a7..d260034 100644 (file)
@@ -13,22 +13,23 @@ Catalyst::Plugin::SubRequest - Make subrequests to actions in Catalyst
 
     use Catalyst 'SubRequest';
 
-    $c->subreq('/test/foo/bar');
+    $c->subreq('/test/foo/bar', template='magic.tt');
 
 =head1 DESCRIPTION
 
-Make subrequests to actions in Catalyst. Uses the private name of
-the action for dispatch.
+Make subrequests to actions in Catalyst. Uses the  catalyst
+dispatcher, so it will work like an external url call.
 
 =head1 METHODS
 
 =over 4 
 
-=item subreq action, args
+=item subreq path, [stash]
 
 =item sub_request
 
-Takes a full path to a path you'd like to dispatch to.
+Takes a full path to a path you'd like to dispatch to. Any additional
+parameters are put into the stash.
 
 =back 
 
@@ -36,15 +37,18 @@ Takes a full path to a path you'd like to dispatch to.
 
 *subreq = \&sub_request;
 
+use Data::Dumper qw/Dumper/;
 sub sub_request {
-    my ( $c, $path ) = @_;
+    my ( $c, $path, $stash ) = @_;
+
     my %old_req;
     $path =~ s/^\///;
-    $old_req{stash}   = $c->{stash};$c->{stash}={};
+    $old_req{stash}   = $c->{stash};$c->{stash}=$stash || {};
     $old_req{content} = $c->res->output;$c->res->output(undef);
     $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} = {};
     $c->prepare_action();
     $c->log->debug("Subrequest to $path , action is ". 
                    $c->req->action )
@@ -52,9 +56,9 @@ sub sub_request {
     $c->dispatch();
     my $output  = $c->res->output;
     $c->{stash} = $old_req{stash};
-    $c->res->output($old_req{content});
+    $c->req->{params}=$old_req{params};
     $c->req->arguments($old_req{args});
-    $c->req->action($old_req{action});
+    $c->res->output($old_req{content});
     return $output;
 }