1 package Catalyst::View::Component::SubInclude::SubRequest;
4 use namespace::clean -except => 'meta';
8 Catalyst::View::Component::SubInclude::SubRequest - Sub-requests plugin for C::V::Component::SubInclude
16 our $VERSION = '0.07';
20 In your application class:
33 package MyApp::View::TT;
36 extends 'Catalyst::View::TT';
37 with 'Catalyst::View::Component::SubInclude';
39 __PACKAGE__->config( subinclude_plugin => 'SubRequest' );
41 Then, somewhere in your templates:
43 [% subinclude('/my/widget') %]
47 C<Catalyst::View::Component::SubInclude::SubRequest> uses Catalyst sub-requests
48 to render the subinclude contents.
50 It requires L<Catalyst::Plugin::SubRequest>.
54 =head2 C<generate_subinclude( $c, $path, @args )>
56 This will make a sub-request call to the action specified by C<$path>. Note that
57 C<$path> should be the private action path - translation to the public path is
60 So, after path translation, the call will be (roughly) equivalent to:
62 $c->sub_request( $translated_path, {}, @args );
64 Notice that the stash will always be empty. This behavior could be configurable
65 in the future through an additional switch - for now, this behavior guarantees a
66 common interface for all plugins.
70 sub generate_subinclude {
71 my ($class, $config, $c, $path, @params) = @_;
72 my $stash = $config->{keep_stash} ? { %{ $c->stash } } : {};
74 croak "subincludes through subrequests require Catalyst::Plugin::SubRequest"
75 unless $c->can('sub_request');
77 my $query = ref $params[-1] eq 'HASH' ? pop @params : {};
79 my $action = blessed($path)
81 : $c->dispatcher->get_action_by_path($path);
83 my $uri = $c->uri_for( $action, @params );
85 $c->sub_request( $uri->path, $stash, $query );
90 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
91 L<Catalyst::Plugin::SubRequest|Catalyst::Plugin::SubRequest>
95 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
99 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
101 =head1 COPYRIGHT & LICENSE
103 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
105 Copyright (C) 2009 Ionzero LLC.
107 This program is free software; you can redistribute it and/or modify it
108 under the same terms as Perl itself.
112 __PACKAGE__->meta->make_immutable;