Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 29 lines (25 sloc) 0.903 kb
ab6264e Tatsuhiko Miyagawa initial commit. HTTP::Router::Declare and tester.pl
authored
1 #!/usr/bin/perl
2 use strict;
3 use Plack::Request;
4 use HTTP::Router::Declare;
f45bc6f Tatsuhiko Miyagawa share the controller backend in Path::Dispatcher, HTTPx::Dispatcher and ...
authored
5 use MyApp::Blog;
6 use MyApp::Hello;
ab6264e Tatsuhiko Miyagawa initial commit. HTTP::Router::Declare and tester.pl
authored
7
8 my $router = router {
f45bc6f Tatsuhiko Miyagawa share the controller backend in Path::Dispatcher, HTTPx::Dispatcher and ...
authored
9 match '/', { method => 'GET' },
10 to { controller => 'Hello', action => 'index' };
bb19442 Tatsuhiko Miyagawa added two more TODO tests
authored
11 match '/blog/{year}/{month}', { method => 'GET', year => qr/^\d{4}$/, month => qr/^\d{2}$/ },
f45bc6f Tatsuhiko Miyagawa share the controller backend in Path::Dispatcher, HTTPx::Dispatcher and ...
authored
12 to { controller => 'Blog', action => 'monthly' };
13 match '/comment', { method => 'POST' },
14 to { controller => 'Blog', action => 'comment' };
ab6264e Tatsuhiko Miyagawa initial commit. HTTP::Router::Declare and tester.pl
authored
15 };
16
17 sub {
18 my $req = Plack::Request->new(shift);
19 my $match = $router->match($req)
20 or return $req->new_response(404)->finalize;
21
22 my $p = $match->params;
f45bc6f Tatsuhiko Miyagawa share the controller backend in Path::Dispatcher, HTTPx::Dispatcher and ...
authored
23 my $controller = "MyApp::" . $p->{controller};
bb19442 Tatsuhiko Miyagawa added two more TODO tests
authored
24 my $action = $controller->can(lc($req->method) . "_" . $p->{action})
25 or return $req->new_response(405)->finalize;
f45bc6f Tatsuhiko Miyagawa share the controller backend in Path::Dispatcher, HTTPx::Dispatcher and ...
authored
26 my $res = $controller->$action($req, $p);
ab6264e Tatsuhiko Miyagawa initial commit. HTTP::Router::Declare and tester.pl
authored
27 $res->finalize;
28 };
Something went wrong with that request. Please try again.