very minor cleanup to SubRequest
[catagits/Catalyst-Plugin-SubRequest.git] / SubRequest.pm
CommitLineData
aae30f91 1package Catalyst::Plugin::SubRequest;
2
3use strict;
4
a23f7a97 5our $VERSION = '0.09';
aae30f91 6
aae30f91 7=head1 NAME
8
9Catalyst::Plugin::SubRequest - Make subrequests to actions in Catalyst
10
11=head1 SYNOPSIS
12
13 use Catalyst 'SubRequest';
14
885f6da0 15 $c->subreq('/test/foo/bar', { template => 'magic.tt' });
aae30f91 16
17=head1 DESCRIPTION
18
8c464987 19Make subrequests to actions in Catalyst. Uses the catalyst
20dispatcher, so it will work like an external url call.
aae30f91 21
22=head1 METHODS
23
24=over 4
25
885f6da0 26=item subreq path, [stash as hash ref], [parameters as hash ref]
aae30f91 27
28=item sub_request
29
8c464987 30Takes a full path to a path you'd like to dispatch to. Any additional
31parameters are put into the stash.
aae30f91 32
33=back
34
35=cut
36
37*subreq = \&sub_request;
38
39sub sub_request {
885f6da0 40 my ( $c, $path, $stash, $params ) = @_;
8c464987 41
5bd316a5 42 $path =~ s#^/##;
cf71661b 43 local $c->{stash} = $stash || {};
a23f7a97 44 local $c->res->{body} = undef;
cf71661b 45 local $c->req->{arguments} = $c->req->{arguments};
46 local $c->req->{action};
47 local $c->req->{path};
48 local $c->req->{params};
49
50 $c->req->path($path);
51 $c->req->params($params || {});
5bd316a5 52 $c->prepare_action;
53 $c->log->debug("Subrequest to ${path}, action is ". $c->req->action )
885f6da0 54 if $c->debug;
c82d9501 55 # FIXME: Hack until proper patch in NEXT.
56 local $NEXT::NEXT{$c,'dispatch'};
5bd316a5 57 $c->dispatch;
a23f7a97 58 return $c->res->body;
aae30f91 59}
60
61=head1 SEE ALSO
62
63L<Catalyst>.
64
65=head1 AUTHOR
66
67Marcus Ramberg, C<mramberg@cpan.org>
68
69=head1 THANK YOU
70
71SRI, for writing the awesome Catalyst framework
72
73=head1 COPYRIGHT
74
75This program is free software, you can redistribute it and/or modify it under
76the same terms as Perl itself.
77
78=cut
79
801;