[Bps-public-commit] r14620 - in Path-Dispatcher/trunk: lib/Path t
sartak at bestpractical.com
sartak at bestpractical.com
Tue Jul 29 16:02:40 EDT 2008
Author: sartak
Date: Tue Jul 29 16:02:35 2008
New Revision: 14620
Added:
Path-Dispatcher/trunk/t/003-404.t
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
Log:
r67909 at onn: sartak | 2008-07-29 16:02:30 -0400
Return undef when dispatch 404s, tests for it
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher.pm Tue Jul 29 16:02:35 2008
@@ -22,9 +22,12 @@
my $self = shift;
my $rule;
+
+ # they pass in an already instantiated rule..
if (@_ == 1 && blessed($_[0])) {
$rule = shift;
}
+ # or they pass in args to create a rule
else {
$rule = $self->rule_class->new(@_);
}
@@ -48,6 +51,8 @@
};
}
+ return if !@matches;
+
return $self->build_runner(
path => $path,
matches => \@matches,
@@ -89,6 +94,7 @@
sub run {
my $self = shift;
my $code = $self->dispatch(@_);
+
return $code->();
}
Added: Path-Dispatcher/trunk/t/003-404.t
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/t/003-404.t Tue Jul 29 16:02:35 2008
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 2;
+use Path::Dispatcher;
+
+my @calls;
+
+my $dispatcher = Path::Dispatcher->new;
+$dispatcher->add_rule(
+ regex => qr/foo/,
+ block => sub { push @calls, [@_] },
+);
+
+my $thunk = $dispatcher->dispatch('bar');
+is_deeply([splice @calls], [], "no calls to the rule block yet");
+
+is($thunk, undef, "no match, no coderef");
+
More information about the Bps-public-commit
mailing list