1 package Catalyst::View::Component::SubInclude::Visit;
4 use MooseX::Types::Moose qw/ Bool /;
5 use namespace::clean -except => 'meta';
9 Catalyst::View::Component::SubInclude::Visit - visit() plugin for C::V::Component::SubInclude
17 our $VERSION = '0.07';
23 package MyApp::View::TT;
26 extends 'Catalyst::View::TT';
27 with 'Catalyst::View::Component::SubInclude';
29 __PACKAGE__->config( subinclude_plugin => 'Visit' );
31 Then, somewhere in your templates:
33 [% subinclude('/my/widget') %]
37 C<Catalyst::View::Component::SubInclude::Visit> uses C<< $c->visit() >> to
38 render subinclude contents.
40 This method is only supported when using L<Catalyst> version 5.71000 or newer.
42 B<WARNING: As of Catalyst version 5.71000, this plugin doesn't work for chained
43 actions with captured arguments>. Apparently, C<visit> doesn't handle this type
48 =head2 C<generate_subinclude( $c, $path, @args )>
50 This is (roughly) equivalent to the following call:
52 $c->visit( $path, @args );
54 But it will handle all the nasty details such as localizing the stash,
55 parameters and response body. This is necessary to keep behavior consistent
56 with the other plugins.
66 sub generate_subinclude {
67 my ($self, $c, $path, @params) = @_;
69 croak "subincludes through visit() require Catalyst version 5.71000 or newer"
70 unless $c->can('visit');
73 local $c->{stash} = $self->keep_stash ? $c->{stash} : {};
75 local $c->request->{parameters} =
76 ref $params[-1] eq 'HASH' ? pop @params : {};
78 local $c->response->{body};
80 my $captures = ref $params[0] eq 'ARRAY' ? shift @params : [];
81 $c->visit( $path, $captures, \@params );
83 return $c->response->{body};
90 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
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;