Catalyst::Action::SubDomain - Match action against names of subdomains
Version 0.07
Match subdomain name
sub method : ActionClass('SubDomain') :SubDomain('level,regexp') { my ( $self, $c ) = @_; .. }
Get number of domain levels and subdomain name at last level.
sub method : ActionClass('SubDomain') { my ( $self, $c ) = @_; my $max_level = $c->action->number_of_domains($c); my $subdomain = $c->action->domain($c, $max_level); }
Root controller action for main site and subdomain with no more than 3 chars
sub default :Path('/') : ActionClass('SubDomain') : SubDomain('3,^\w{0,3}$') { my ( $self, $c ) = @_; }
Foo controller action for rest subdomains
sub index :Path('/') :ActionClass('SubDomain') :SubDomain('3,^\w{4,}$') { my ( $self, $c ) = @_; }
This example shows that actions will be match only when 3-rd level domain exists and contains alpha-numerical chars (foo123.example.com).
sub index :Path('/') :Args(0) :ActionClass('SubDomain') :SubDomain('3,^\w+$') { my ( $self, $c ) = @_; $c->response->body('Matched My::App::Controller'); }
foo123.example.com/test
sub test :Path('/test') :ActionClass('SubDomain') :SubDomain('3,^\w+$') { my ( $self, $c, @args ) = @_; $c->response->body(join('.', map($c->action->domain($c, $_), 1..$c->action->number_of_domains($c)))); }
You can specify more that one subdomain constraint.
sub test :Local :ActionClass('SubDomain') :SubDomain('3,^\w+$') :SubDomain('2,^example$') { my ( $self, $c, @args ) = @_; my $name = $self->action->domain($c, 3); }
Note: When combining :ActionClass('SubDomain') with :Chained action you should access action a little bit different way
.. my $action = $c->action->isa('Catalyst::ActionChain')?$c->action->chain->[-1]:$c->action; my $name = $action->domain($c, 3); ..
Returns domain name of specified level. Works only for matched action.
Get number of domain levels
See "METHODS/match" in Catalyst::Action.
Check subdomains constraints
Cached domains
Egor Korablev, <egor.korablev at gmail.com>
<egor.korablev at gmail.com>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Catalyst::Action::SubDomain, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Action::SubDomain
CPAN shell
perl -MCPAN -e shell install Catalyst::Action::SubDomain
For more information on module installation, please visit the detailed CPAN module installation guide.