1 package Catalyst::View::Component::SubInclude;
5 use namespace::clean qw/croak/;
9 Catalyst::View::Component::SubInclude - Use subincludes in your Catalyst views
17 our $VERSION = '0.02';
21 package MyApp::View::TT;
24 extends 'Catalyst::View::TT';
25 with 'Catalyst::View::Component::SubInclude';
27 __PACKAGE__->config( subinclude_plugin => 'SubRequest' );
29 Then, somewhere in your templates:
31 [% subinclude('/my/widget') %]
35 C<Catalyst::View::Component::SubInclude> allows you to include content in your
36 templates (or, more generally, somewhere in your view's C<render> processing)
37 which comes from another action in your application. It's implemented as a
38 L<Moose::Role|Moose::Role>, so using L<Moose|Moose> in your view is required.
40 Simply put, it's a way to include the output of a Catalyst sub-request somewhere
43 It's built in an extensible way so that you're free to use sub-requests, Varnish
44 ESI (L<http://www.catalystframework.org/calendar/2008/17>) or any other
45 sub-include plugin you might want to implement. An LWP plugin seems useful and
46 might be developed in the future.
50 This component does its magic by exporting a C<subinclude> coderef entry to the
51 stash. This way, it's easily accessible by the templates (which is the most
54 =head2 C<subinclude( $path, @args )>
56 This will render and return the body of the included resource (as specified by
59 =head1 SUBINCLUDE PLUGINS
61 The module comes with two subinclude plugins:
62 L<SubRequest|Catalyst::Plugin::View::Component::SubRequest>,
63 L<Visit|Catalyst::Plugin::View::Component::Visit> and
64 L<ESI|Catalyst::Plugin::View::Component::ESI>.
66 By default, the SubRequest plugin will be used. This can be changed in the
67 view's configuration options (either in the config file or in the view module
70 Configuration file example:
76 If writing your own plugin, keep in kind plugins are required to implement a
77 class method C<generate_subinclude> with the following signature:
79 sub generate_subinclude {
80 my ($class, $c, @args) = @_;
85 has 'subinclude_plugin' => (
94 my $self = $class->$next( @_ );
96 my $subinclude_plugin = $self->config->{subinclude_plugin} || 'SubRequest';
97 my $subinclude_class = __PACKAGE__ . '::' . $subinclude_plugin;
99 eval "require $subinclude_class";
100 croak "Error requiring $subinclude_class: $@" if $@;
102 $self->subinclude_plugin( $subinclude_class );
107 around 'render' => sub {
109 my ($self, $c, @args) = @_;
111 $c->stash->{subinclude} = sub {
112 $self->subinclude_plugin->generate_subinclude( $c, @_ );
115 $self->$next( $c, @args );
120 L<Catalyst::Plugin::SubRequest|Catalyst::Plugin::SubRequest>,
121 L<Moose::Role|Moose::Role>, L<Moose|Moose>,
122 L<http://www.catalystframework.org/calendar/2008/17>
126 Please report any bugs or feature requests to
127 C<bug-catalyst-view-component-subinclude at rt.cpan.org>, or through the web interface at
128 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-View-Component-SubInclude>.
129 I will be notified, and then you'll automatically be notified of progress on
130 your bug as I make changes.
134 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
138 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
140 =head1 COPYRIGHT & LICENSE
142 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
144 Copyright (C) 2009 Ionzero LLC.
146 This program is free software; you can redistribute it and/or modify it
147 under the same terms as Perl itself.