Commit | Line | Data |
30726632 |
1 | package Catalyst::View::Component::SubInclude::ESI; |
8bbd65bf |
2 | use Moose; |
3 | use namespace::clean -except => 'meta'; |
30726632 |
4 | |
4e327756 |
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 | |
9399de67 |
11 | Version 0.07 |
4e327756 |
12 | |
13 | =cut |
14 | |
9399de67 |
15 | our $VERSION = '0.07'; |
4e327756 |
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 | |
11a93ea1 |
40 | =head1 CLASS METHODS |
4e327756 |
41 | |
532f3bcf |
42 | =head2 C<generate_subinclude( $c, $path, @args )> |
4e327756 |
43 | |
532f3bcf |
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: |
4e327756 |
47 | |
532f3bcf |
48 | my $url = $c->uri_for( $translated_path, @args )->path_query; |
11a93ea1 |
49 | return '<!--esi <esi:include src="$url" /> -->'; |
4e327756 |
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 | |
30726632 |
57 | sub generate_subinclude { |
f97c7165 |
58 | my ($self, $c, $path, @params) = @_; |
aea6a2da |
59 | |
edc887a1 |
60 | my $uri = $c->uri_for_action( $path, @params ); |
aea6a2da |
61 | |
3c5cb6d6 |
62 | return '<!--esi <esi:include src="' . $uri->path_query . '" /> -->'; |
30726632 |
63 | } |
64 | |
4e327756 |
65 | =head1 SEE ALSO |
66 | |
67 | L<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>, |
68 | L<http://www.catalystframework.org/calendar/2008/17>, |
69 | L<http://varnish.projects.linpro.no/> |
70 | |
71 | =head1 AUTHOR |
72 | |
73 | Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >> |
74 | |
75 | =head1 SPONSORSHIP |
76 | |
77 | Development sponsored by Ionzero LLC L<http://www.ionzero.com/>. |
78 | |
79 | =head1 COPYRIGHT & LICENSE |
80 | |
81 | Copyright (C) 2009 Nilson Santos Figueiredo Junior. |
82 | |
83 | Copyright (C) 2009 Ionzero LLC. |
84 | |
85 | This program is free software; you can redistribute it and/or modify it |
86 | under the same terms as Perl itself. |
87 | |
88 | =cut |
89 | |
8bbd65bf |
90 | __PACKAGE__->meta->make_immutable; |
30726632 |
91 | 1; |