1 package Catalyst::View::Component::SubInclude::Visit;
6 use namespace::clean qw/croak/;
10 Catalyst::View::Component::SubInclude::Visit - visit() plugin for C::V::Component::SubInclude
18 our $VERSION = '0.03';
24 package MyApp::View::TT;
27 extends 'Catalyst::View::TT';
28 with 'Catalyst::View::Component::SubInclude';
30 __PACKAGE__->config( subinclude_plugin => 'Visit' );
32 Then, somewhere in your templates:
34 [% subinclude('/my/widget') %]
38 C<Catalyst::View::Component::SubInclude::Visit> uses C<< $c->visit() >> to
39 render subinclude contents.
41 This method is only supported when using L<Catalyst> version 5.71000 or newer.
43 B<WARNING: As of Catalyst version 5.71000, this plugin doesn't work for chained
44 actions with captured arguments>. Apparently, C<visit> doesn't handle this type
49 =head2 C<generate_subinclude( $c, $path, @args )>
51 This is (roughly) equivalent to the following call:
53 $c->visit( $path, @args );
55 But it will handle all the nasty details such as localizing the stash,
56 parameters and response body. This is necessary to keep behavior consistent
57 with the other plugins.
61 sub generate_subinclude {
62 my ($class, $c, $path, @params) = @_;
64 croak "subincludes through visit() require Catalyst version 5.71000 or newer"
65 unless $c->can('visit');
67 $c->log->debug("generate subinclude: $path @params");
70 local $c->{stash} = {};
72 local $c->request->{parameters} =
73 ref $params[-1] eq 'HASH' ? pop @params : {};
75 local $c->response->{body};
77 $c->visit( $path, ( ref $params[0] eq 'ARRAY' ? shift @params : () ) );
79 return $c->response->{body};
86 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
91 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
95 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
97 =head1 COPYRIGHT & LICENSE
99 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
101 Copyright (C) 2009 Ionzero LLC.
103 This program is free software; you can redistribute it and/or modify it
104 under the same terms as Perl itself.