[Catalyst] Calling Controller Methods from inside begin or auto.

monkey dwueppel at gmail.com
Tue Sep 29 12:34:08 GMT 2009


Hello,

So I have a site I'm building that requires authentication, but only to
selected pages. By default I want to require that an authenticated user
is found, but in certain controllers I want to disable this. I was
originally thinking about doing this by creating a auth_required()
method call in a base controller class and overriding this as needed.
Then I would write my authentication routine inside the Root controller.
Something like this:

sub begin : Private {
	my ($self, $c) = @_;

	# I created the get_user method.
	my $u = $c->get_user()

	if ($self->auth_required()) {
		# Do auth stuff.
	}
}

However the issue here is that when calling $self->auth_required() this
will always call the Root.pm's auth_required method instead of the
specific controllers.

Is there a way from inside a begin method to get the controller that is
actually going to be used to display the page? If not is there another
way to do the above without having to write the auth handling at the top
of every method used to display pages?

--
Derek Wueppelmann




More information about the Catalyst mailing list