Bump to 0.04
[catagits/Catalyst-View-Component-SubInclude.git] / lib / Catalyst / View / Component / SubInclude / ESI.pm
1 package Catalyst::View::Component::SubInclude::ESI;
2 use warnings;
3 use strict;
4
5 =head1 NAME
6
7 Catalyst::View::Component::SubInclude::ESI - Edge Side Includes (ESI) plugin for C::V::Component::SubInclude
8
9 =head1 VERSION
10
11 Version 0.04
12
13 =cut
14
15 our $VERSION = '0.04';
16
17 =head1 SYNOPSIS
18
19 In your view class:
20
21   package MyApp::View::TT;
22   use Moose;
23
24   extends 'Catalyst::View::TT';
25   with 'Catalyst::View::Component::SubInclude';
26
27   __PACKAGE__->config( subinclude_plugin => 'ESI' );
28
29 Then, somewhere in your templates:
30
31   [% subinclude('/my/widget') %]
32
33 =head1 DESCRIPTION
34
35 C<Catalyst::View::Component::SubInclude::ESI> renders C<subinclude> calls as 
36 Edge Side Includes (ESI) include directives. This is a feature implemented by 
37 Varnish (L<http://varnish.projects.linpro.no/>) which allows cache-efficient 
38 uses of includes.
39
40 =head1 CLASS METHODS
41
42 =head2 C<generate_subinclude( $c, $path, @args )>
43
44 Note that C<$path> should be the private action path - translation to the public
45 path is handled internally. After translation, this will roughly translate to 
46 the following code:
47
48   my $url = $c->uri_for( $translated_path, @args )->path_query;
49   return '<!--esi <esi:include src="$url" /> -->';
50
51 Notice that the stash will always be empty. This behavior could be configurable
52 in the future through an additional switch - for now, this behavior guarantees a
53 common interface for plugins.
54
55 =cut
56
57 sub generate_subinclude {
58     my ($class, $c, $path, @params) = @_;
59
60     my $args = ref $params[0] eq 'ARRAY' ? shift @params : [];
61     
62     my $dispatcher = $c->dispatcher;
63     my ($action) = $dispatcher->_invoke_as_path( $c, $path, $args );
64
65     my $uri = $c->uri_for( $action, $args, @params );
66
67     return '<!--esi <esi:include src="' . $uri->path_query . '" /> -->';
68 }
69
70 =head1 SEE ALSO
71
72 L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>, 
73 L<http://www.catalystframework.org/calendar/2008/17>,
74 L<http://varnish.projects.linpro.no/>
75
76 =head1 AUTHOR
77
78 Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
79
80 =head1 SPONSORSHIP
81
82 Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
83
84 =head1 COPYRIGHT & LICENSE
85
86 Copyright (C) 2009 Nilson Santos Figueiredo Junior.
87
88 Copyright (C) 2009 Ionzero LLC.
89
90 This program is free software; you can redistribute it and/or modify it
91 under the same terms as Perl itself.
92
93 =cut
94
95 1;