Skip to content

Commit

Permalink
BACKWARD INCOMPATILBE: '/' mapping now really means it only matches
Browse files Browse the repository at this point in the history
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
miyagawa committed Mar 16, 2010
1 parent e83e9a5 commit cc2a7d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Tatsumaki/Application.pm
Expand Up @@ -22,6 +22,7 @@ around BUILDARGS => sub {
my $handlers = shift @_; my $handlers = shift @_;
my @rules; my @rules;
while (my($path, $handler) = splice @$handlers, 0, 2) { while (my($path, $handler) = splice @$handlers, 0, 2) {
$path = qr@^/$@ if $path eq '/';
$path = qr/^$path/ unless ref $path eq 'RegExp'; $path = qr/^$path/ unless ref $path eq 'RegExp';
push @rules, { path => $path, handler => $handler }; push @rules, { path => $path, handler => $handler };
} }
Expand Down
31 changes: 31 additions & 0 deletions 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.