Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 30 lines (26 sloc) 0.869 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#!/usr/bin/perl
use strict;
use Plack::Request;
use Plack::Response;
use Router::Simple 0.03;
use Router::Simple::Declare;
use MyApp::Blog;
use MyApp::Hello;

my $router = router {
    connect '/',
        { controller => 'Hello', action => 'index' }, { method => 'GET' };
    connect '/blog/{year:\d{4}}/{month:\d{2}}',
        { controller => 'Blog', action => 'monthly' }, { method => 'GET' };
    connect '/comment',
        { controller => 'Blog', action => 'comment' }, { method => 'POST' };
};

sub {
    my $env = shift;
    my $p = $router->match($env)
        or return Plack::Response->new(404)->finalize;

    my $req = Plack::Request->new($env);
    my $controller = "MyApp::" . delete $p->{controller};
    my $action = $controller->can(lc($req->method) . "_" . delete $p->{action});
    my $res = $controller->$action($req, $p);
    $res->finalize;
};
Something went wrong with that request. Please try again.