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.
63 sub generate_subinclude {
64 my ($self, $c, $path, @params) = @_;
66 croak "subincludes through visit() require Catalyst version 5.71000 or newer"
67 unless $c->can('visit');
70 local $c->{stash} = $self->keep_stash ? $c->{stash} : {};
72 local $c->request->{parameters} =
73 ref $params[-1] eq 'HASH' ? pop @params : {};
75 local $c->response->{body};
77 my $captures = ref $params[0] eq 'ARRAY' ? shift @params : [];
78 $c->visit( $path, $captures, \@params );
80 return $c->response->{body};
87 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
92 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
96 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
98 =head1 COPYRIGHT & LICENSE
100 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
102 Copyright (C) 2009 Ionzero LLC.
104 This program is free software; you can redistribute it and/or modify it
105 under the same terms as Perl itself.
109 __PACKAGE__->meta->make_immutable;