Fix everything but visit is broken
[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
14Version 0.02
15
16=cut
17
18our $VERSION = '0.02';
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
43=head1 CLASS METHODS
44
45=head2 C<generate_subinclude( $c, $path, @args )>
46
47This will translate to the following call:
48
49 $c->visit( $path, @args );
50
51=cut
52
53sub generate_subinclude {
54 my ($class, $c, $path, @params) = @_;
55
56 croak "subincludes through visit() require Catalyst version 5.71000 or newer"
57 unless $c->can('visit');
3c5cb6d6 58
59 $c->log->debug("generate subinclude: $path @params");
60
61 {
62 local $c->{stash} = {};
63
64 local $c->request->{parameters} =
65 ref $params[-1] eq 'HASH' ? pop @params : {};
66
67 local $c->response->{body};
68
69 $c->visit( $path, ( ref $params[0] eq 'ARRAY' ? shift @params : () ) );
70
71 return $c->response->{body};
72 }
e88af283 73
e88af283 74}
75
76=head1 SEE ALSO
77
78L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
79L<Catalyst|Catalyst>
80
81=head1 AUTHOR
82
83Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
84
85=head1 SPONSORSHIP
86
87Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
88
89=head1 COPYRIGHT & LICENSE
90
91Copyright (C) 2009 Nilson Santos Figueiredo Junior.
92
93Copyright (C) 2009 Ionzero LLC.
94
95This program is free software; you can redistribute it and/or modify it
96under the same terms as Perl itself.
97
98=cut
99
1001;