Fix attribute constraint issue with newer Catalyst versions
[catagits/Catalyst-View-Component-SubInclude.git] / lib / Catalyst / View / Component / SubInclude / Visit.pm
CommitLineData
e88af283 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
7c937ccc 14Version 0.05
e88af283 15
16=cut
17
7c937ccc 18our $VERSION = '0.05';
e88af283 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
532f3bcf 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
e88af283 47=head1 CLASS METHODS
48
49=head2 C<generate_subinclude( $c, $path, @args )>
50
532f3bcf 51This is (roughly) equivalent to the following call:
e88af283 52
53 $c->visit( $path, @args );
54
532f3bcf 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
e88af283 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');
3c5cb6d6 66
67 $c->log->debug("generate subinclude: $path @params");
68
69 {
70 local $c->{stash} = {};
71
72 local $c->request->{parameters} =
73 ref $params[-1] eq 'HASH' ? pop @params : {};
74
75 local $c->response->{body};
76
77 $c->visit( $path, ( ref $params[0] eq 'ARRAY' ? shift @params : () ) );
78
79 return $c->response->{body};
80 }
e88af283 81
e88af283 82}
83
84=head1 SEE ALSO
85
86L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
87L<Catalyst|Catalyst>
88
89=head1 AUTHOR
90
91Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
92
93=head1 SPONSORSHIP
94
95Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
96
97=head1 COPYRIGHT & LICENSE
98
99Copyright (C) 2009 Nilson Santos Figueiredo Junior.
100
101Copyright (C) 2009 Ionzero LLC.
102
103This program is free software; you can redistribute it and/or modify it
104under the same terms as Perl itself.
105
106=cut
107
1081;