[Catalyst] Calling a private sub - best practice

Adam Jacob adam at stalecoffee.org
Wed Mar 14 17:27:46 GMT 2007


On Mar 14, 2007, at 9:50 AM, RA Jones wrote:

> Adam Jacob wrote:
>> On Mar 14, 2007, at 9:23 AM, RA Jones wrote:
>>> Is this the correct way to call sub-routines, via $c->forward and  
>>> $c->stash? I know about TIMTOWTDI but I want to start off with  
>>> 'best practice'.
>> You can forward $c, which will let you call the form object directly.
>> Adam
> Doesn't $c get forwarded automatically? All Catalyst methods seem  
> to begin with my ($self, $c) = @_;
>
> I tried this: my $form = $c->forward('build_form'); which forwards  
> to the build_form() method which (of course) builds and returns the  
> form. It does work - is that what you had in mind?

You don't have to use forward; but if you don't, you have to pass $c  
directly:

sub foo :Local :Form {
	my ($self, $c) = @_;
	$self->_call_me($c, ..your args...);
}

sub _call_me {
	my ($self, $c) = @_;
	... do things to $c ...
}

There is nothing particularly magical about $c->forward, and in many  
cases, you are probably better off with a straight method call.  
(Rather than going through forward)

Adam



More information about the Catalyst mailing list