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_03';
18 $VERSION = eval $VERSION;
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.
67 sub generate_subinclude {
68 my ($self, $c, $path, @params) = @_;
70 croak "subincludes through visit() require Catalyst version 5.71000 or newer"
71 unless $c->can('visit');
74 local $c->{stash} = $self->keep_stash ? $c->{stash} : {};
76 local $c->request->{parameters} =
77 ref $params[-1] eq 'HASH' ? pop @params : {};
79 local $c->response->{body};
81 my $captures = ref $params[0] eq 'ARRAY' ? shift @params : [];
82 $c->visit( $path, $captures, \@params );
84 return $c->response->{body};
91 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
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.
113 __PACKAGE__->meta->make_immutable;