[Catalyst-commits] r11399 - Catalyst-Runtime/5.80/trunk/lib
mateu at dev.catalyst.perl.org
mateu at dev.catalyst.perl.org
Mon Sep 21 18:57:16 GMT 2009
Author: mateu
Date: 2009-09-21 18:57:14 +0000 (Mon, 21 Sep 2009)
New Revision: 11399
Modified:
Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
Log:
Update $c->forward and $c->state documentation to address scalar context.
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2009-09-21 14:05:17 UTC (rev 11398)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2009-09-21 18:57:14 UTC (rev 11399)
@@ -349,7 +349,22 @@
your code like this:
$c->forward('foo') || return;
+
+Another note is that C<< $c->forward >> always returns a scalar because it
+actually returns $c->state which operates in a scalar context.
+Thus, something like:
+ return @array;
+
+in an action that is forwarded to is going to return a scalar,
+i.e. how many items are in that array, which is probably not what you want.
+If you need to return an array then return a reference to it,
+or stash it like so:
+
+ $c->stash->{array} = \@array;
+
+and access it from the stash.
+
=cut
sub forward { my $c = shift; no warnings 'recursion'; $c->dispatcher->forward( $c, @_ ) }
@@ -490,7 +505,9 @@
=head2 $c->state
-Contains the return value of the last executed action.
+Contains the return value of the last executed action.
+Note that << $c->state >> operates in a scalar context which means that all
+values it returns are scalar.
=head2 $c->clear_errors
More information about the Catalyst-commits
mailing list