Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Catalyst / View / Component / SubInclude / Visit.pm
CommitLineData
3fea05b9 1package Catalyst::View::Component::SubInclude::Visit;
2use Moose;
3use Carp qw/croak/;
4use MooseX::Types::Moose qw/ Bool /;
5use namespace::clean -except => 'meta';
6
7=head1 NAME
8
9Catalyst::View::Component::SubInclude::Visit - visit() plugin for C::V::Component::SubInclude
10
11=head1 VERSION
12
13Version 0.07_03
14
15=cut
16
17our $VERSION = '0.07_03';
18$VERSION = eval $VERSION;
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
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
47=head1 CLASS METHODS
48
49=head2 C<generate_subinclude( $c, $path, @args )>
50
51This is (roughly) equivalent to the following call:
52
53 $c->visit( $path, @args );
54
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
59=cut
60
61has keep_stash => (
62 isa => Bool,
63 is => 'ro',
64 default => 0,
65);
66
67sub generate_subinclude {
68 my ($self, $c, $path, @params) = @_;
69
70 croak "subincludes through visit() require Catalyst version 5.71000 or newer"
71 unless $c->can('visit');
72
73 {
74 local $c->{stash} = $self->keep_stash ? $c->{stash} : {};
75
76 local $c->request->{parameters} =
77 ref $params[-1] eq 'HASH' ? pop @params : {};
78
79 local $c->response->{body};
80
81 my $captures = ref $params[0] eq 'ARRAY' ? shift @params : [];
82 $c->visit( $path, $captures, \@params );
83
84 return $c->response->{body};
85 }
86
87}
88
89=head1 SEE ALSO
90
91L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
92L<Catalyst|Catalyst>
93
94=head1 AUTHOR
95
96Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
97
98=head1 SPONSORSHIP
99
100Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
101
102=head1 COPYRIGHT & LICENSE
103
104Copyright (C) 2009 Nilson Santos Figueiredo Junior.
105
106Copyright (C) 2009 Ionzero LLC.
107
108This program is free software; you can redistribute it and/or modify it
109under the same terms as Perl itself.
110
111=cut
112
113__PACKAGE__->meta->make_immutable;
1141;