1 package Catalyst::Plugin::SubRequest;
10 Catalyst::Plugin::SubRequest - Make subrequests to actions in Catalyst
14 use Catalyst 'SubRequest';
16 $c->subreq('/test/foo/bar', template='magic.tt');
20 Make subrequests to actions in Catalyst. Uses the catalyst
21 dispatcher, so it will work like an external url call.
27 =item subreq path, [stash]
31 Takes a full path to a path you'd like to dispatch to. Any additional
32 parameters are put into the stash.
38 *subreq = \&sub_request;
40 use Data::Dumper qw/Dumper/;
42 my ( $c, $path, $stash ) = @_;
46 $old_req{stash} = $c->{stash};$c->{stash}=$stash || {};
47 $old_req{content} = $c->res->output;$c->res->output(undef);
48 $old_req{args} = $c->req->arguments;
49 $old_req{action} = $c->req->action;$c->req->action(undef);
50 $old_req{path} = $c->req->path;$c->req->path($path);
51 $old_req{params} = $c->req->params;$c->req->{params} = {};
53 $c->log->debug("Subrequest to $path , action is ".
57 my $output = $c->res->output;
58 $c->{stash} = $old_req{stash};
59 $c->req->{params}=$old_req{params};
60 $c->req->arguments($old_req{args});
61 $c->res->output($old_req{content});
71 Marcus Ramberg, C<mramberg@cpan.org>
75 SRI, for writing the awesome Catalyst framework
79 This program is free software, you can redistribute it and/or modify it under
80 the same terms as Perl itself.