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';
21 In your application class:
34 package MyApp::View::TT;
37 extends 'Catalyst::View::TT';
38 with 'Catalyst::View::Component::SubInclude';
40 __PACKAGE__->config( subinclude_plugin => 'SubRequest' );
42 Then, somewhere in your templates:
44 [% subinclude('/my/widget') %]
48 C<Catalyst::View::Component::SubInclude::SubRequest> uses Catalyst sub-requests
49 to render the subinclude contents.
51 It requires L<Catalyst::Plugin::SubRequest>.
55 =head2 C<generate_subinclude( $c, $path, @args )>
57 This will make a sub-request call to the action specified by C<$path>. Note that
58 C<$path> should be the private action path - translation to the public path is
61 So, after path translation, the call will be (roughly) equivalent to:
63 $c->sub_request( $translated_path, {}, @args );
65 Notice that the stash will always be empty. This behavior could be configurable
66 in the future through an additional switch - for now, this behavior guarantees a
67 common interface for all plugins.
77 sub generate_subinclude {
78 my ($self, $c, $path, @params) = @_;
79 my $stash = $self->keep_stash ? { %{ $c->stash } } : {};
81 croak "subincludes through subrequests require Catalyst::Plugin::SubRequest"
82 unless $c->can('sub_request');
84 my $query = ref $params[-1] eq 'HASH' ? pop @params : {};
86 my $action = blessed($path)
88 : $c->dispatcher->get_action_by_path($path);
90 my $uri = $c->uri_for( $action, @params );
92 $c->sub_request( $uri->path, $stash, $query );
97 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
98 L<Catalyst::Plugin::SubRequest|Catalyst::Plugin::SubRequest>
102 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
106 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
108 =head1 COPYRIGHT & LICENSE
110 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
112 Copyright (C) 2009 Ionzero LLC.
114 This program is free software; you can redistribute it and/or modify it
115 under the same terms as Perl itself.
119 __PACKAGE__->meta->make_immutable;