Skip to content

Commit

Permalink
added two more TODO tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Mar 16, 2010
1 parent 846175e commit bb19442
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
50 changes: 48 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,57 @@ This is a collection of URI dispatching using Plack::Request and various CPAN mo

Most examples would do:

GET / => "Hello World"
GET / => "Hello World" in text/plain
GET /blog/{year}/{month} => Get the list of blog posts in year/month
POST /comment => Post a comment with parameters id, name and body

Nice to have:

/blog/{year}/{month} should be limited to 4-digit year and 2-digit month
POST to GET-only endpoints should raise 405

You can run tests against the dispatcher using:

perl tester.pl <dispatcher.pl>
perl tester.pl <dispatcher.psgi>

NOTES

Here're some notes and observations. This is not a check-no-check
comparison. When it says "Can't do ...", it doesn't necessarily mean a
minus - it means it's application's responsibility, which could mean
more flexibilities.

dancer:
(Dancer doesn't use Plack::Request -- here's for the comparison)
Can use named capture and regexp based dispatching
POST to GET endpoints gives 404 by default

HTTP::Router::Declare:
Can dispatch using HTTP methods as well
(You can remove { method => 'GET' } requirement to make 405 fallbacks work)
Can specify requirement like routes.py

HTTPx::Dispatcher:
Can't use HTTP method as a dispatcher rule - it's an app's responsibility
Can't use regular expressions / requirements

Mojolicious::Lite:
(Mojolicious doesn't use Plack::Request -- here's for the comparison)
Can use named capture + regexp requirement like Merb / HTTP::Router
POST to GET endpoints gives 404 by default

Path::Dispatcher:
Passing PSGI env to the metadata for REQUEST_METHOD matching
(You can omit that to make 405 fallbacks on the app work)

Path::Router:
Can use Moose based constraints to validate path chunks
Can't use HTTP method as a dispatcher rule - it's an app's reponsibility

Tatsumaki:
Can't use HTTP method as a dispatcher rule - app handlers need to define the verbs
Default '/' is catch-all as of 0.1009 -- needs to be qr/^\/$/ (will be fixed in 0.1010)
The mapping order matters -- sometimes confusing

Web::Simple:
Can't use regexp for dispatcher rules -- app's responsibility
5 changes: 3 additions & 2 deletions http-router-declare.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use MyApp::Hello;
my $router = router {
match '/', { method => 'GET' },
to { controller => 'Hello', action => 'index' };
match '/blog/{year}/{month}', { method => 'GET' },
match '/blog/{year}/{month}', { method => 'GET', year => qr/^\d{4}$/, month => qr/^\d{2}$/ },
to { controller => 'Blog', action => 'monthly' };
match '/comment', { method => 'POST' },
to { controller => 'Blog', action => 'comment' };
Expand All @@ -21,7 +21,8 @@ sub {

my $p = $match->params;
my $controller = "MyApp::" . $p->{controller};
my $action = $controller->can(lc($req->method) . "_" . $p->{action});
my $action = $controller->can(lc($req->method) . "_" . $p->{action})
or return $req->new_response(405)->finalize;
my $res = $controller->$action($req, $p);
$res->finalize;
};
3 changes: 2 additions & 1 deletion httpx-dispatcher.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ sub {
or return $req->new_response(404)->finalize;

my $controller = "MyApp::$match->{controller}";
my $action = $controller->can(lc($req->method) . "_" . $match->{action});
my $action = $controller->can(lc($req->method) . "_" . $match->{action})
or return $req->new_response(405)->finalize;
my $res = $controller->$action($req, $match->{args});
$res->finalize;
};
2 changes: 1 addition & 1 deletion path-router.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sub {
my $mapping = $match->mapping;
my $controller = "MyApp::" . $mapping->{controller};
my $action = $controller->can(lc($req->method) . "_" . $mapping->{action})
or return $req->new_response(404)->finalize;
or return $req->new_response(405)->finalize;
my $res = $controller->$action($req, $mapping);
$res->finalize;
};
9 changes: 9 additions & 0 deletions tester.pl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@

$res = $cb->(GET "/nonexistent");
is $res->code, 404;

TODO: {
local $TODO = "Nice to have";
$res = $cb->(POST "/blog/2009/01");
is $res->code, 405, '405 on POST requests against GET only endpoints';

$res = $cb->(GET "/blog/now/today");
is $res->code, 404, 'year & month can specify digits';
}
};

done_testing;
Expand Down

0 comments on commit bb19442

Please sign in to comment.