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