[Catalyst] Dispatching based on path and host/domain

Curtis Fletcher curtis.fletcher at pharmaventures.com
Wed Apr 23 12:22:36 BST 2008


> Write an Action Class.
> 
> You can put whatever you want in the match() method. In your case,
> 
> return 0 if grep { $c->req->host =~ /$_/ } 
> @{$self->attributes->{Domain}||[]}

I gave this a go (in principle it looks ideal), but the documentation on
Catalyst::Action is pretty sparse and only talks about replacing the
"execute" method. I'm assuming that if ActionClass->match() returns
false the dispatcher assumes the method doesn't match, I gave that a
quick test:

package Catalyst::Action::Domain;
use strict;
use warnings;
use base 'Catalyst::Action';
sub match
{
	my $self = shift;
	my ($c) = @_;
	return 0;
};

package MyAPP::Controller::Admin::Website1::Abstract
sub index :Local
{
}

sub edit :Local :ActionClass('Domain')
{
}

http://mydomain.com/admin/website1/abstract/edit bounced me right back
to the default controller, I was kind of expecting it to behave like
NEXT in that it would fail to match
http://mydomain.com/admin/website1/abstract/edit but would then match
http://mydomain.com/admin/website1/abstract setting the first arg to
'edit'. Ah this may be specific to "index" as a "not-really" action it
doesn't accept parameters the way I thought it did 

E.G.
http://mydomain.com/admin/website1/abstract/iamnotamethod

Does not dispatch to MyAPP::Controller::Admin::Website1::Abstract->index
with ARGS being ('iamnotamethod') I think I answered my own question,
but there's no harm in having the result in the archives no? (especially
if I'm wrong)
(Also, Did someone say that "index" was a hack? And that we should use
"base" instead?)

Dumping out the Action Object I can see:
'attributes' =>
{
	'ActionClass' =>
	[
		'Catalyst::Action::Domain'
	],
	'Path' =>
	[
		'admin/website1/abstract/edit'
	]
}

But I can't seem to find anywhere that this structure is set up, given
the code in your Action example how would you go about setting the
'Domain' key in the attributes class from the Controller the Action is
used in, apologies if this is a question with an obvious answer.

Finally isn't $c->req->host the hostname of the connecting client? I
ended up mangling $c->req->base at the moment though I'm not sure that's
the best way to go.

Really finally, has anyone thought of putting together a flowchart of
the Classes/methods involved in a Catalyst request response if it's been
done I'd love to look at it and if not if might be a good exercise for
me.

Thanks again for the really sterling help/suggestions.




More information about the Catalyst mailing list