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 always be empty. This behavior could be configurable
67 in the future through an additional switch - for now, this behavior guarantees a
68 common interface for all plugins.
78 sub generate_subinclude {
79 my ($self, $c, $path, @params) = @_;
80 my $stash = $self->keep_stash ? { %{ $c->stash } } : {};
82 croak "subincludes through subrequests require Catalyst::Plugin::SubRequest"
83 unless $c->can('sub_request');
85 my $query = ref $params[-1] eq 'HASH' ? pop @params : {};
87 my $action = blessed($path)
89 : $c->dispatcher->get_action_by_path($path);
91 my $uri = $c->uri_for( $action, @params );
93 $c->sub_request( $uri->path, $stash, $query );
98 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
99 L<Catalyst::Plugin::SubRequest|Catalyst::Plugin::SubRequest>
103 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
107 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
109 =head1 COPYRIGHT & LICENSE
111 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
113 Copyright (C) 2009 Ionzero LLC.
115 This program is free software; you can redistribute it and/or modify it
116 under the same terms as Perl itself.
120 __PACKAGE__->meta->make_immutable;