From: Nilson Santos Figueiredo JĂșnior Date: Thu, 5 Feb 2009 21:41:12 +0000 (+0000) Subject: Add Visit Plugin, fix SubRequest plugin bump version to 0.02 X-Git-Tag: 0.07_01~38 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-View-Component-SubInclude.git;a=commitdiff_plain;h=e88af2835e002b378e700d70a81912b493b40b1f Add Visit Plugin, fix SubRequest plugin bump version to 0.02 --- diff --git a/lib/Catalyst/View/Component/SubInclude.pm b/lib/Catalyst/View/Component/SubInclude.pm index 94f7faa..77c5945 100644 --- a/lib/Catalyst/View/Component/SubInclude.pm +++ b/lib/Catalyst/View/Component/SubInclude.pm @@ -10,11 +10,11 @@ Catalyst::View::Component::SubInclude - Use subincludes in your Catalyst views =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 SYNOPSIS @@ -59,7 +59,8 @@ C<$path>). =head1 SUBINCLUDE PLUGINS The module comes with two subinclude plugins: -L and +L, +L and L. By default, the SubRequest plugin will be used. This can be changed in the diff --git a/lib/Catalyst/View/Component/SubInclude/ESI.pm b/lib/Catalyst/View/Component/SubInclude/ESI.pm index 5af70c1..1c98d62 100644 --- a/lib/Catalyst/View/Component/SubInclude/ESI.pm +++ b/lib/Catalyst/View/Component/SubInclude/ESI.pm @@ -8,11 +8,11 @@ Catalyst::View::Component::SubInclude::ESI - Edge Side Includes (ESI) plugin for =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 SYNOPSIS diff --git a/lib/Catalyst/View/Component/SubInclude/SubRequest.pm b/lib/Catalyst/View/Component/SubInclude/SubRequest.pm index c40a77d..2e97236 100644 --- a/lib/Catalyst/View/Component/SubInclude/SubRequest.pm +++ b/lib/Catalyst/View/Component/SubInclude/SubRequest.pm @@ -11,11 +11,11 @@ Catalyst::View::Component::SubInclude::SubRequest - Sub-requests plugin for C::V =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 SYNOPSIS @@ -71,8 +71,13 @@ sub generate_subinclude { croak "subincludes through subrequests require Catalyst::Plugin::SubRequest" unless $c->can('sub_request'); + + my $dispatcher = $c->dispatcher; + my ($action, $args) = $dispatcher->_invoke_as_path( $c, $path, @params ); - $c->sub_request( $path, $stash, @params ); + my $uri = $c->uri_for( $action, $args ); + + $c->sub_request( $uri->path, $stash, @params ); } =head1 SEE ALSO diff --git a/lib/Catalyst/View/Component/SubInclude/Visit.pm b/lib/Catalyst/View/Component/SubInclude/Visit.pm new file mode 100644 index 0000000..1855589 --- /dev/null +++ b/lib/Catalyst/View/Component/SubInclude/Visit.pm @@ -0,0 +1,87 @@ +package Catalyst::View::Component::SubInclude::Visit; +use warnings; +use strict; + +use Carp qw/croak/; +use namespace::clean qw/croak/; + +=head1 NAME + +Catalyst::View::Component::SubInclude::Visit - visit() plugin for C::V::Component::SubInclude + +=head1 VERSION + +Version 0.02 + +=cut + +our $VERSION = '0.02'; + +=head1 SYNOPSIS + +In your view class: + + package MyApp::View::TT; + use Moose; + + extends 'Catalyst::View::TT'; + with 'Catalyst::View::Component::SubInclude'; + + __PACKAGE__->config( subinclude_plugin => 'Visit' ); + +Then, somewhere in your templates: + + [% subinclude('/my/widget') %] + +=head1 DESCRIPTION + +C uses C<< $c->visit() >> to +render subinclude contents. + +This method is only supported when using L version 5.71000 or newer. + +=head1 CLASS METHODS + +=head2 C + +This will translate to the following call: + + $c->visit( $path, @args ); + +=cut + +sub generate_subinclude { + my ($class, $c, $path, @params) = @_; + + croak "subincludes through visit() require Catalyst version 5.71000 or newer" + unless $c->can('visit'); + + $c->visit( $path, @params ); + $c->res->{body}; +} + +=head1 SEE ALSO + +L, +L + +=head1 AUTHOR + +Nilson Santos Figueiredo Junior, C<< >> + +=head1 SPONSORSHIP + +Development sponsored by Ionzero LLC L. + +=head1 COPYRIGHT & LICENSE + +Copyright (C) 2009 Nilson Santos Figueiredo Junior. + +Copyright (C) 2009 Ionzero LLC. + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + +=cut + +1; diff --git a/t/ESITest/esitest.conf b/t/ESITest/esitest.conf index 851c247..a594520 100644 --- a/t/ESITest/esitest.conf +++ b/t/ESITest/esitest.conf @@ -1,5 +1,5 @@ name ESITest - subinclude_plugin SubRequest + subinclude_plugin Visit diff --git a/t/ESITest/lib/ESITest/Controller/Root.pm b/t/ESITest/lib/ESITest/Controller/Root.pm index 97945ac..41b0ee8 100644 --- a/t/ESITest/lib/ESITest/Controller/Root.pm +++ b/t/ESITest/lib/ESITest/Controller/Root.pm @@ -6,11 +6,15 @@ use parent 'Catalyst::Controller'; __PACKAGE__->config->{namespace} = ''; -sub index :Path :Args(0) { +sub index :Path Args(0) { my ( $self, $c ) = @_; } -sub time_include : Local Args(0) { +sub base : Chained('/') PathPart('') CaptureArgs(0) { + my ( $self, $c ) = @_; +} + +sub time_include : Chained('base') PathPart('time') Args(0) { my ( $self, $c ) = @_; $c->stash->{current_time} = localtime(); }