Permalink
Browse files

added Router::Simple code.

  • Loading branch information...
1 parent 75d8c08 commit 80ece366533fa7d64060ac95b058244f5329746a @tokuhirom tokuhirom committed Mar 17, 2010
Showing with 26 additions and 0 deletions.
  1. +26 −0 router-simple-declare.psgi
View
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+use strict;
+use Plack::Request;
+use Router::Simple::Declare;
+use MyApp::Blog;
+use MyApp::Hello;
+
+my $router = router {
+ connect '/',
+ { controller => 'Hello', action => 'index' }, { method => 'GET' };
+ connect '/blog/{year}/{month}',
+ { controller => 'Blog', action => 'monthly' }, { method => 'GET' };
+ connect '/comment',
+ { controller => 'Blog', action => 'comment' }, { method => 'POST' };
+};
+
+sub {
+ my $req = Plack::Request->new(shift);
+ my $p = $router->match($req)
+ or return $req->new_response(404)->finalize;
+
+ my $controller = "MyApp::" . $p->{controller};
+ my $action = $controller->can(lc($req->method) . "_" . $p->{action});
+ my $res = $controller->$action($req, $p->{args});
+ $res->finalize;
+};

0 comments on commit 80ece36

Please sign in to comment.