Created
September 6, 2011 08:17
-
-
Save aerith/1196933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Asayake::Web::Dispatcher; | |
use strict; | |
use warnings; | |
use Asayake::DB; | |
use Amon2::Web::Dispatcher::RouterSimple; | |
use Scalar::Util; | |
{ | |
no warnings qw/redefine/; | |
sub dispatch { | |
my ($class, $c) = @_; | |
my $req = $c->request; | |
if (my $p = $class->match($req->env)) { | |
my $action = $p->{action}; | |
$c->{args} = $p; | |
my $stuff; | |
foreach my $code ($c->get_trigger_code('BEFORE_ACTION')) { | |
$stuff = $code->($c, $p); | |
goto ACTION_END if Scalar::Util::blessed($stuff) && $stuff->isa('Plack::Response'); | |
} | |
$stuff = "@{[ ref Amon2->context ]}::C::$p->{controller}"->$action($c, $p); | |
ACTION_END: | |
$stuff; | |
} else { | |
$c->res_404(); | |
} | |
} | |
} | |
submapper('', { controller => 'Manage::Root' }, { 'host' => 'manage.aerith.sc' }) | |
->connect('/' => { action => 'index' }) | |
->connect('/login' => { action => 'login' }) | |
->connect('/logout' => { action => 'logout' }); | |
submapper('/blog', { controller => 'Manage::Blog' }, { 'host' => 'manage.aerith.sc' }) | |
->connect('' => { action => 'index' }) | |
->connect('/' => { action => 'index' }); | |
submapper('/note/{path:[a-zA-Z0-9_-]+}/post', { controller => 'Manage::Post' }, { 'host' => 'manage.aerith.sc' }) | |
->connect('' => { action => 'index' }) | |
->connect('/' => { action => 'index' }); | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment