Skip to content

Instantly share code, notes, and snippets.

@aerith
Created September 6, 2011 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aerith/1196933 to your computer and use it in GitHub Desktop.
Save aerith/1196933 to your computer and use it in GitHub Desktop.
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