Bump version number and prepare for release
[catagits/Catalyst-View-Component-SubInclude.git] / lib / Catalyst / View / Component / SubInclude / SubRequest.pm
CommitLineData
eb99eb06 1package Catalyst::View::Component::SubInclude::SubRequest;
2use warnings;
3use strict;
4
8dbcfa50 5use Carp qw/croak/;
6use namespace::clean qw/croak/;
7
62ebc3f4 8=head1 NAME
9
10Catalyst::View::Component::SubInclude::SubRequest - Sub-requests plugin for C::V::Component::SubInclude
11
12=head1 VERSION
13
f71ea072 14Version 0.07
62ebc3f4 15
16=cut
17
f71ea072 18our $VERSION = '0.07';
62ebc3f4 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
8dbcfa50 54=head1 CLASS METHODS
62ebc3f4 55
8dbcfa50 56=head2 C<generate_subinclude( $c, $path, @args )>
62ebc3f4 57
7ccbc329 58This will make a sub-request call to the action specified by C<$path>. Note that
59C<$path> should be the private action path - translation to the public path is
60handled internally.
62ebc3f4 61
7ccbc329 62So, after path translation, the call will be (roughly) equivalent to:
63
64 $c->sub_request( $translated_path, {}, @args );
62ebc3f4 65
66Notice that the stash will always be empty. This behavior could be configurable
67in the future through an additional switch - for now, this behavior guarantees a
7ccbc329 68common interface for all plugins.
62ebc3f4 69
70=cut
71
eb99eb06 72sub generate_subinclude {
62ebc3f4 73 my ($class, $c, $path, @params) = @_;
eb99eb06 74 my $stash = {};
75
76 croak "subincludes through subrequests require Catalyst::Plugin::SubRequest"
77 unless $c->can('sub_request');
6e96f4bf 78
bdbd995d 79 my $args = ref $params[0] eq 'ARRAY' ? shift @params : [];
80 my $query = ref $params[-1] eq 'HASH' ? pop @params : {};
6cb4b001 81
82 my $dispatcher = $c->dispatcher;
6e96f4bf 83 my ($action) = $dispatcher->_invoke_as_path( $c, $path, $args );
eb99eb06 84
6e96f4bf 85 my $uri = $c->uri_for( $action, $args, @params );
6cb4b001 86
bdbd995d 87 $c->sub_request( $uri->path, $stash, $query );
eb99eb06 88}
89
62ebc3f4 90=head1 SEE ALSO
91
92L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>,
93L<Catalyst::Plugin::SubRequest|Catalyst::Plugin::SubRequest>
94
95=head1 AUTHOR
96
97Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
98
99=head1 SPONSORSHIP
100
101Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
102
103=head1 COPYRIGHT & LICENSE
104
105Copyright (C) 2009 Nilson Santos Figueiredo Junior.
106
107Copyright (C) 2009 Ionzero LLC.
108
109This program is free software; you can redistribute it and/or modify it
110under the same terms as Perl itself.
111
112=cut
113
eb99eb06 1141;