1 package Catalyst::View::Component::SubInclude::SubRequest;
4 use MooseX::Types::Moose qw/ Bool /;
5 use namespace::clean -except => 'meta';
9 Catalyst::View::Component::SubInclude::SubRequest - Sub-requests plugin for C::V::Component::SubInclude
17 our $VERSION = '0.07_03';
18 $VERSION = eval $VERSION;
22 In your application class:
35 package MyApp::View::TT;
38 extends 'Catalyst::View::TT';
39 with 'Catalyst::View::Component::SubInclude';
41 __PACKAGE__->config( subinclude_plugin => 'SubRequest' );
43 Then, somewhere in your templates:
45 [% subinclude('/my/widget') %]
49 C<Catalyst::View::Component::SubInclude::SubRequest> uses Catalyst sub-requests
50 to render the subinclude contents.
52 It requires L<Catalyst::Plugin::SubRequest>.
56 =head2 C<generate_subinclude( $c, $path, @args )>
58 This will make a sub-request call to the action specified by C<$path>. Note that
59 C<$path> should be the private action path - translation to the public path is
62 So, after path translation, the call will be (roughly) equivalent to:
64 $c->sub_request( $translated_path, {}, @args );
66 Notice that the stash will be empty by default. This behavior is configurable
73 You can choose to not localize the stash for SubRequests' subinclude calls. The subrequest
74 will have the same stash as the request that spawned it. Configure the keep_stash key
85 Note: the stash that the subrequest recieves is a shallow copy of the original stash. That
86 means that changes to values of keys on the first level of the stash will be lost when the
87 subrequest call returns. Don't count on this behaviour, as it may change in the future.
97 sub generate_subinclude {
98 my ($self, $c, $path, @params) = @_;
99 my $stash = $self->keep_stash ? $c->stash : {};
101 croak "subincludes through subrequests require Catalyst::Plugin::SubRequest"
102 unless $c->can('sub_request');
104 my $query = ref $params[-1] eq 'HASH' ? pop @params : {};
106 my $action = blessed($path)
108 : $c->dispatcher->get_action_by_path($path);
110 my $uri = $c->uri_for( $action, @params );
112 $c->sub_request( $uri->path, $stash, $query );
117 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
118 L<Catalyst::Plugin::SubRequest|Catalyst::Plugin::SubRequest>
122 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
126 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
128 =head1 COPYRIGHT & LICENSE
130 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
132 Copyright (C) 2009 Ionzero LLC.
134 This program is free software; you can redistribute it and/or modify it
135 under the same terms as Perl itself.
139 __PACKAGE__->meta->make_immutable;