1 package Catalyst::View::Component::SubInclude::Visit;
4 use namespace::clean -except => 'meta';
8 Catalyst::View::Component::SubInclude::Visit - visit() plugin for C::V::Component::SubInclude
16 our $VERSION = '0.07';
22 package MyApp::View::TT;
25 extends 'Catalyst::View::TT';
26 with 'Catalyst::View::Component::SubInclude';
28 __PACKAGE__->config( subinclude_plugin => 'Visit' );
30 Then, somewhere in your templates:
32 [% subinclude('/my/widget') %]
36 C<Catalyst::View::Component::SubInclude::Visit> uses C<< $c->visit() >> to
37 render subinclude contents.
39 This method is only supported when using L<Catalyst> version 5.71000 or newer.
41 B<WARNING: As of Catalyst version 5.71000, this plugin doesn't work for chained
42 actions with captured arguments>. Apparently, C<visit> doesn't handle this type
47 =head2 C<generate_subinclude( $c, $path, @args )>
49 This is (roughly) equivalent to the following call:
51 $c->visit( $path, @args );
53 But it will handle all the nasty details such as localizing the stash,
54 parameters and response body. This is necessary to keep behavior consistent
55 with the other plugins.
59 sub generate_subinclude {
60 my ($class, $config, $c, $path, @params) = @_;
62 croak "subincludes through visit() require Catalyst version 5.71000 or newer"
63 unless $c->can('visit');
66 local $c->{stash} = $config->{keep_stash} ? $c->{stash} : {};
68 local $c->request->{parameters} =
69 ref $params[-1] eq 'HASH' ? pop @params : {};
71 local $c->response->{body};
73 my $captures = ref $params[0] eq 'ARRAY' ? shift @params : [];
74 $c->visit( $path, $captures, \@params );
76 return $c->response->{body};
83 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
88 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
92 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
94 =head1 COPYRIGHT & LICENSE
96 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
98 Copyright (C) 2009 Ionzero LLC.
100 This program is free software; you can redistribute it and/or modify it
101 under the same terms as Perl itself.
105 __PACKAGE__->meta->make_immutable;