Skip to content

Commit

Permalink
inline HTTP::Router::Declare callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Mar 16, 2010
1 parent 4fc84bf commit 6b870f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 46 deletions.
31 changes: 22 additions & 9 deletions http-router-declare.pl
Expand Up @@ -8,12 +8,27 @@
use MyApp::Hello; use MyApp::Hello;


my $router = router { my $router = router {
match '/', { method => 'GET' }, match '/', { method => 'GET' }, to { action => sub {
to { controller => 'Hello', action => 'index' }; my($req, $p) = @_;
match '/blog/{year}/{month}', { method => 'GET' }, my $res = $req->new_response(200);
to { controller => 'Blog', action => 'monthly' }; $res->content_type("text/plain");
match '/comment', { method => 'POST' }, $res->content("Hello World");
to { controller => 'Blog', action => 'new_comment' }; $res;
} };
match '/blog/{year}/{month}', { method => 'GET' }, to { action => sub {
my($req, $p) = @_;
my $res = $req->new_response(200);
$res->content_type('text/html');
$res->content("Blog posts from $p->{year}/$p->{month}");
$res;
} };
match '/comment', { method => 'POST' }, to { action => sub {
my($req, $p) = @_;
my $res = $req->new_response(200);
$res->content_type('text/plain');
$res->content("Comment posted with body=" . $req->parameters->{body});
$res;
} };
}; };


sub { sub {
Expand All @@ -22,8 +37,6 @@
or return $req->new_response(404)->finalize; or return $req->new_response(404)->finalize;


my $p = $match->params; my $p = $match->params;
my $controller = "MyApp::$p->{controller}"; my $res = $p->{action}->($req, $p);
my $action = $p->{action};
my $res = $controller->$action($req, $p);
$res->finalize; $res->finalize;
}; };
24 changes: 0 additions & 24 deletions lib/MyApp/Blog.pm

This file was deleted.

13 changes: 0 additions & 13 deletions lib/MyApp/Hello.pm

This file was deleted.

0 comments on commit 6b870f2

Please sign in to comment.