Bump version number and prepare for release
[catagits/Catalyst-View-Component-SubInclude.git] / lib / Catalyst / View / Component / SubInclude / Visit.pm
CommitLineData
6cb4b001 1package Catalyst::View::Component::SubInclude::Visit;
2use warnings;
3use strict;
4
5use Carp qw/croak/;
6use namespace::clean qw/croak/;
7
8=head1 NAME
9
10Catalyst::View::Component::SubInclude::Visit - visit() plugin for C::V::Component::SubInclude
11
12=head1 VERSION
13
f71ea072 14Version 0.07
6cb4b001 15
16=cut
17
f71ea072 18our $VERSION = '0.07';
6cb4b001 19
20=head1 SYNOPSIS
21
22In your view class:
23
24 package MyApp::View::TT;
25 use Moose;
26
27 extends 'Catalyst::View::TT';
28 with 'Catalyst::View::Component::SubInclude';
29
30 __PACKAGE__->config( subinclude_plugin => 'Visit' );
31
32Then, somewhere in your templates:
33
34 [% subinclude('/my/widget') %]
35
36=head1 DESCRIPTION
37
38C<Catalyst::View::Component::SubInclude::Visit> uses C<< $c->visit() >> to
39render subinclude contents.
40
41This method is only supported when using L<Catalyst> version 5.71000 or newer.
42
7ccbc329 43B<WARNING: As of Catalyst version 5.71000, this plugin doesn't work for chained
44actions with captured arguments>. Apparently, C<visit> doesn't handle this type
45of actions yet.
46
6cb4b001 47=head1 CLASS METHODS
48
49=head2 C<generate_subinclude( $c, $path, @args )>
50
7ccbc329 51This is (roughly) equivalent to the following call:
6cb4b001 52
53 $c->visit( $path, @args );
54
7ccbc329 55But it will handle all the nasty details such as localizing the stash,
56parameters and response body. This is necessary to keep behavior consistent
57with the other plugins.
58
6cb4b001 59=cut
60
61sub generate_subinclude {
62 my ($class, $c, $path, @params) = @_;
63
64 croak "subincludes through visit() require Catalyst version 5.71000 or newer"
65 unless $c->can('visit');
6e96f4bf 66
67 {
68 local $c->{stash} = {};
69
70 local $c->request->{parameters} =
71 ref $params[-1] eq 'HASH' ? pop @params : {};
72
73 local $c->response->{body};
74
bdbd995d 75 my $captures = ref $params[0] eq 'ARRAY' ? shift @params : [];
76 $c->visit( $path, \@params, $captures );
6e96f4bf 77
78 return $c->response->{body};
79 }
6cb4b001 80
6cb4b001 81}
82
83=head1 SEE ALSO
84
85L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
86L<Catalyst|Catalyst>
87
88=head1 AUTHOR
89
90Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
91
92=head1 SPONSORSHIP
93
94Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
95
96=head1 COPYRIGHT & LICENSE
97
98Copyright (C) 2009 Nilson Santos Figueiredo Junior.
99
100Copyright (C) 2009 Ionzero LLC.
101
102This program is free software; you can redistribute it and/or modify it
103under the same terms as Perl itself.
104
105=cut
106
1071;