Browse files

BACKWARD INCOMPATILBE: '/' mapping now really means it only matches

with the root /. Current catch-all behavior is not what you want in
90% of the use case. If you really want to write a catch-all handler
you can map '/.*'
  • Loading branch information...
1 parent e83e9a5 commit cc2a7d278d302f9ca70f612e2f11c82c3d6e181f @miyagawa committed Mar 16, 2010
Showing with 32 additions and 0 deletions.
  1. +1 −0 lib/Tatsumaki/Application.pm
  2. +31 −0 t/handler/root.t
View
1 lib/Tatsumaki/Application.pm
@@ -22,6 +22,7 @@ around BUILDARGS => sub {
my $handlers = shift @_;
my @rules;
while (my($path, $handler) = splice @$handlers, 0, 2) {
+ $path = qr@^/$@ if $path eq '/';
$path = qr/^$path/ unless ref $path eq 'RegExp';
push @rules, { path => $path, handler => $handler };
}
View
31 t/handler/root.t
@@ -0,0 +1,31 @@
+use Plack::Test;
+use Test::More;
+use HTTP::Request::Common;
+use Tatsumaki::Application;
+
+package HelloApp;
+use base qw(Tatsumaki::Handler);
+
+sub get {
+ my $self = shift;
+ $self->write("Hello World");
+}
+
+package main;
+my $app = Tatsumaki::Application->new([ '/' => 'HelloApp' ]);
+
+test_psgi $app, sub {
+ my $cb = shift;
+ my $res = $cb->(GET "http://localhost/");
+ ok $res->is_success;
+ is $res->code, 200;
+ is $res->content, 'Hello World';
+
+ $res = $cb->(GET "http://localhost/foo");
+ is $res->code, 404;
+
+ $res = $cb->(POST "http://localhost/");
+ is $res->code, 405;
+};
+
+done_testing;

0 comments on commit cc2a7d2

Please sign in to comment.