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.
45 =head2 C<generate_subinclude( $c, $path, @args )>
47 This is (roughly) equivalent to the following call:
49 $c->visit( $path, @args );
51 But it will handle all the nasty details such as localizing the stash,
52 parameters and response body. This is necessary to keep behavior consistent
53 with the other plugins.
59 You can choose to not localize the stash for Visits' subinclude calls. The subrequest
60 will have the same stash as the request that spawned it. Configure the keep_stash key
71 Note: changes in the stash during a Visit subinclude will be visible after the include
82 sub generate_subinclude {
83 my ($self, $c, $path, @params) = @_;
85 croak "subincludes through visit() require Catalyst version 5.71000 or newer"
86 unless $c->can('visit');
89 local $c->{stash} = $self->keep_stash ? $c->{stash} : {};
91 local $c->request->{parameters} =
92 ref $params[-1] eq 'HASH' ? pop @params : {};
94 local $c->response->{body};
96 my $captures = ref $params[0] eq 'ARRAY' ? shift @params : [];
97 $c->visit( $path, $captures, \@params );
99 return $c->response->{body};
106 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
111 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
115 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
117 =head1 COPYRIGHT & LICENSE
119 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
121 Copyright (C) 2009 Ionzero LLC.
123 This program is free software; you can redistribute it and/or modify it
124 under the same terms as Perl itself.
128 __PACKAGE__->meta->make_immutable;