1 package Catalyst::View::Component::SubInclude::SubRequest;
6 use Scalar::Util qw/blessed/;
11 Catalyst::View::Component::SubInclude::SubRequest - Sub-requests plugin for C::V::Component::SubInclude
19 our $VERSION = '0.07';
23 In your application class:
36 package MyApp::View::TT;
39 extends 'Catalyst::View::TT';
40 with 'Catalyst::View::Component::SubInclude';
42 __PACKAGE__->config( subinclude_plugin => 'SubRequest' );
44 Then, somewhere in your templates:
46 [% subinclude('/my/widget') %]
50 C<Catalyst::View::Component::SubInclude::SubRequest> uses Catalyst sub-requests
51 to render the subinclude contents.
53 It requires L<Catalyst::Plugin::SubRequest>.
57 =head2 C<generate_subinclude( $c, $path, @args )>
59 This will make a sub-request call to the action specified by C<$path>. Note that
60 C<$path> should be the private action path - translation to the public path is
63 So, after path translation, the call will be (roughly) equivalent to:
65 $c->sub_request( $translated_path, {}, @args );
67 Notice that the stash will always be empty. This behavior could be configurable
68 in the future through an additional switch - for now, this behavior guarantees a
69 common interface for all plugins.
73 sub generate_subinclude {
74 my ($class, $config, $c, $path, @params) = @_;
75 my $stash = $config->{keep_stash} ? { %{ $c->stash } } : {};
77 croak "subincludes through subrequests require Catalyst::Plugin::SubRequest"
78 unless $c->can('sub_request');
80 my $query = ref $params[-1] eq 'HASH' ? pop @params : {};
82 my $action = blessed($path)
84 : $c->dispatcher->get_action_by_path($path);
86 my $uri = $c->uri_for( $action, @params );
88 $c->sub_request( $uri->path, $stash, $query );
93 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
94 L<Catalyst::Plugin::SubRequest|Catalyst::Plugin::SubRequest>
98 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
102 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
104 =head1 COPYRIGHT & LICENSE
106 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
108 Copyright (C) 2009 Ionzero LLC.
110 This program is free software; you can redistribute it and/or modify it
111 under the same terms as Perl itself.