Add Visit Plugin, fix SubRequest plugin bump version to 0.02
Nilson Santos Figueiredo JĂșnior [Thu, 5 Feb 2009 21:41:12 +0000 (21:41 +0000)]
lib/Catalyst/View/Component/SubInclude.pm
lib/Catalyst/View/Component/SubInclude/ESI.pm
lib/Catalyst/View/Component/SubInclude/SubRequest.pm
lib/Catalyst/View/Component/SubInclude/Visit.pm [new file with mode: 0644]
t/ESITest/esitest.conf
t/ESITest/lib/ESITest/Controller/Root.pm

index 94f7faa..77c5945 100644 (file)
@@ -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<SubRequest|Catalyst::Plugin::View::Component::SubRequest> and 
+L<SubRequest|Catalyst::Plugin::View::Component::SubRequest>,
+L<Visit|Catalyst::Plugin::View::Component::Visit> and 
 L<ESI|Catalyst::Plugin::View::Component::ESI>.
 
 By default, the SubRequest plugin will be used. This can be changed in the 
index 5af70c1..1c98d62 100644 (file)
@@ -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
 
index c40a77d..2e97236 100644 (file)
@@ -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 (file)
index 0000000..1855589
--- /dev/null
@@ -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<Catalyst::View::Component::SubInclude::Visit> uses C<< $c->visit() >> to 
+render subinclude contents.
+
+This method is only supported when using L<Catalyst> version 5.71000 or newer.
+
+=head1 CLASS METHODS
+
+=head2 C<generate_subinclude( $c, $path, @args )>
+
+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<Catalyst::View::Component::SubInclude|Catalyst::View::Component::SubInclude>, 
+L<Catalyst|Catalyst>
+
+=head1 AUTHOR
+
+Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >>
+
+=head1 SPONSORSHIP
+
+Development sponsored by Ionzero LLC L<http://www.ionzero.com/>.
+
+=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;
index 851c247..a594520 100644 (file)
@@ -1,5 +1,5 @@
 name ESITest
 
 <View::TT>
-  subinclude_plugin   SubRequest
+  subinclude_plugin   Visit
 </View::TT>
index 97945ac..41b0ee8 100644 (file)
@@ -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();
 }