Commit | Line | Data |
e88af283 |
1 | package Catalyst::View::Component::SubInclude::Visit; |
2 | use warnings; |
3 | use strict; |
4 | |
5 | use Carp qw/croak/; |
6 | use namespace::clean qw/croak/; |
7 | |
8 | =head1 NAME |
9 | |
10 | Catalyst::View::Component::SubInclude::Visit - visit() plugin for C::V::Component::SubInclude |
11 | |
12 | =head1 VERSION |
13 | |
14 | Version 0.02 |
15 | |
16 | =cut |
17 | |
18 | our $VERSION = '0.02'; |
19 | |
20 | =head1 SYNOPSIS |
21 | |
22 | In 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 | |
32 | Then, somewhere in your templates: |
33 | |
34 | [% subinclude('/my/widget') %] |
35 | |
36 | =head1 DESCRIPTION |
37 | |
38 | C<Catalyst::View::Component::SubInclude::Visit> uses C<< $c->visit() >> to |
39 | render subinclude contents. |
40 | |
41 | This 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 | |
47 | This will translate to the following call: |
48 | |
49 | $c->visit( $path, @args ); |
50 | |
51 | =cut |
52 | |
53 | sub 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 | |
78 | L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>, |
79 | L<Catalyst|Catalyst> |
80 | |
81 | =head1 AUTHOR |
82 | |
83 | Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >> |
84 | |
85 | =head1 SPONSORSHIP |
86 | |
87 | Development sponsored by Ionzero LLC L<http://www.ionzero.com/>. |
88 | |
89 | =head1 COPYRIGHT & LICENSE |
90 | |
91 | Copyright (C) 2009 Nilson Santos Figueiredo Junior. |
92 | |
93 | Copyright (C) 2009 Ionzero LLC. |
94 | |
95 | This program is free software; you can redistribute it and/or modify it |
96 | under the same terms as Perl itself. |
97 | |
98 | =cut |
99 | |
100 | 1; |