1 package Catalyst::View::Component::SubInclude::SubRequest;
6 use namespace::clean qw/croak/;
10 Catalyst::View::Component::SubInclude::SubRequest - Sub-requests plugin for C::V::Component::SubInclude
18 our $VERSION = '0.03';
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.
72 sub generate_subinclude {
73 my ($class, $c, $path, @params) = @_;
76 croak "subincludes through subrequests require Catalyst::Plugin::SubRequest"
77 unless $c->can('sub_request');
79 my $args = ref $params[0] eq 'ARRAY' ? shift @params : [];
81 my $dispatcher = $c->dispatcher;
82 my ($action) = $dispatcher->_invoke_as_path( $c, $path, $args );
84 my $uri = $c->uri_for( $action, $args, @params );
86 $c->sub_request( $uri->path, $stash, @params );
91 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
92 L<Catalyst::Plugin::SubRequest|Catalyst::Plugin::SubRequest>
96 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
100 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
102 =head1 COPYRIGHT & LICENSE
104 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
106 Copyright (C) 2009 Ionzero LLC.
108 This program is free software; you can redistribute it and/or modify it
109 under the same terms as Perl itself.