All docs updated.
[catagits/Catalyst-View-Component-SubInclude.git] / lib / Catalyst / View / Component / SubInclude / SubRequest.pm
1 package Catalyst::View::Component::SubInclude::SubRequest;
2 use warnings;
3 use strict;
4
5 =head1 NAME
6
7 Catalyst::View::Component::SubInclude::SubRequest - Sub-requests plugin for C::V::Component::SubInclude
8
9 =head1 VERSION
10
11 Version 0.01
12
13 =cut
14
15 our $VERSION = '0.01';
16
17 =head1 SYNOPSIS
18
19 In your application class:
20
21   package MyApp;
22
23   use Catalyst qw/
24     ConfigLoader
25     Static::Simple
26     ...
27     SubRequest
28   /;
29
30 In your view class:
31
32   package MyApp::View::TT;
33   use Moose;
34
35   extends 'Catalyst::View::TT';
36   with 'Catalyst::View::Component::SubInclude';
37
38   __PACKAGE__->config( subinclude_plugin => 'SubRequest' );
39
40 Then, somewhere in your templates:
41
42   [% subinclude('/my/widget') %]
43
44 =head1 DESCRIPTION
45
46 C<Catalyst::View::Component::SubInclude::SubRequest> uses Catalyst sub-requests
47 to render the subinclude contents. 
48
49 It requires L<Catalyst::Plugin::SubRequest>.
50
51 =head1 STASH FUNCTION
52
53 =head2 C<subinclude( $path, @args )>
54
55 This will translate to the following sub-request call:
56
57   $c->sub_request( $path, {}, @args );
58
59 Notice that the stash will always be empty. This behavior could be configurable
60 in the future through an additional switch - for now, this behavior guarantees a
61 common interface for plugins.
62
63 =cut
64
65 sub generate_subinclude {
66     my ($class, $c, $path, @params) = @_;
67     my $stash = {};
68
69     croak "subincludes through subrequests require Catalyst::Plugin::SubRequest"
70         unless $c->can('sub_request');
71
72     $c->sub_request( $path, $stash, @params );
73 }
74
75 =head1 SEE ALSO
76
77 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>, 
78 L<Catalyst::Plugin::SubRequest|Catalyst::Plugin::SubRequest>
79
80 =head1 AUTHOR
81
82 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
83
84 =head1 SPONSORSHIP
85
86 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
87
88 =head1 COPYRIGHT & LICENSE
89
90 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
91
92 Copyright (C) 2009 Ionzero LLC.
93
94 This program is free software; you can redistribute it and/or modify it
95 under the same terms as Perl itself.
96
97 =cut
98
99 1;