On Jan 5, 2008, at 6:48 PM, Joe Landman wrote:
Hi folks:
Thought I had this nailed, but it looks like I really didn't
understand it as I should have.
Here is the problem. I want to forward to some private actions to
simplify the application (and avoid repeating myself). I want to be
able to do this from any controller in the code. So in reading the
manual, I thought I was supposed to do
$c->forward('MyApp::Root::do_something');
Close, but it should be $c->forward( 'MyApp::Root', 'do_something' );
From Catalyst.pm:
$c->forward( $class, $method, [, [EMAIL PROTECTED] ] )
Forwards processing to another action, by its private name. If
you give
a class name but no method, "process()" is called. You may also
optionally pass arguments in an arrayref. The action will
receive the
arguments in @_ and "$c->req->args". Upon returning from the
function,
"$c->req->args" will be restored to the previous values.
Any data "return"ed from the action forwarded to, will be
returned by
the call to forward.
my $foodata = $c->forward('/foo');
$c->forward('index');
$c->forward(qw/MyApp::Model::DBIC::Foo do_stuff/); #
<--------
$c->forward('MyApp::View::TT');
and not
$c->forward('/do_something');
The latter works, the former does not. Is this intended? Are both
supposed to work?
On a related note, I like naming my internal methods with an
underscore up front. Yeah, maybe not the best practice these days,
but call it an old habit. What I noticed was that private methods
named _do_something didn't seem to show up in the private list.
Confused me a bit. Should I avoid that practice with Catalyst?
Just name them INTERNAL_METHOD_do_something or something like
that? Well, you get the idea ...
There is a configuration option you can set to not have actions
starting with an underscore supressed (MyApp->config-
>{ 'show_internal_actions' } = 1), but if you enable it you will also
get all of Catalyst's internal actions (_DISPATCH, _BEGIN, _AUTO,
_ACTION, _END)
Besides, if you are forwarding to them, they aren't really internal,
are they?
--
Jason Kohles, RHCA RHCDS RHCE
[EMAIL PROTECTED] - http://www.jasonkohles.com/
"A witty saying proves nothing." -- Voltaire
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/