Skip to content

Instantly share code, notes, and snippets.

@theory
Created October 14, 2010 19:21
Show Gist options
  • Save theory/626839 to your computer and use it in GitHub Desktop.
Save theory/626839 to your computer and use it in GitHub Desktop.
use Router::Resource;
use My::Controller;
use Plack::Builder;
my $router = router {
resource '/' => sub {
GET { My::Controller->root(@_) };
};
resource '/blog/{year}/{month}' => sub {
GET { My::Controller->show_post(@_) };
POST { My::Controller->create_post(@_) };
PUT { My::Controller->update_post(@_) };
DELETE { My::Controller->delete_post(@_) };
};
};
sub app {
builder {
sub {
my $env = shift;
if (my $method = $class->router->match($env)) {
return $method->();
} else {
return [404, [], ['not found']];
}
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment