Fix attribute constraint issue with newer Catalyst versions
[catagits/Catalyst-View-Component-SubInclude.git] / lib / Catalyst / View / Component / SubInclude / Visit.pm
index 1855589..52ed67d 100644 (file)
@@ -11,11 +11,11 @@ Catalyst::View::Component::SubInclude::Visit - visit() plugin for C::V::Componen
 
 =head1 VERSION
 
-Version 0.02
+Version 0.05
 
 =cut
 
-our $VERSION = '0.02';
+our $VERSION = '0.05';
 
 =head1 SYNOPSIS
 
@@ -40,14 +40,22 @@ render subinclude contents.
 
 This method is only supported when using L<Catalyst> version 5.71000 or newer.
 
+B<WARNING: As of Catalyst version 5.71000, this plugin doesn't work for chained 
+actions with captured arguments>. Apparently, C<visit> doesn't handle this type 
+of actions yet.
+
 =head1 CLASS METHODS
 
 =head2 C<generate_subinclude( $c, $path, @args )>
 
-This will translate to the following call:
+This is (roughly) equivalent to the following call:
 
   $c->visit( $path, @args );
 
+But it will handle all the nasty details such as localizing the stash, 
+parameters and response body. This is necessary to keep behavior consistent 
+with the other plugins.
+
 =cut
 
 sub generate_subinclude {
@@ -55,9 +63,22 @@ sub generate_subinclude {
 
     croak "subincludes through visit() require Catalyst version 5.71000 or newer"
         unless $c->can('visit');
+    
+    $c->log->debug("generate subinclude: $path @params");
+
+    {
+        local $c->{stash} = {};
+        
+        local $c->request->{parameters} = 
+            ref $params[-1] eq 'HASH' ? pop @params : {};
+
+        local $c->response->{body};
+
+        $c->visit( $path, ( ref $params[0] eq 'ARRAY' ? shift @params : () ) );
+
+        return $c->response->{body};
+    }
 
-    $c->visit( $path, @params );
-    $c->res->{body};
 }
 
 =head1 SEE ALSO