Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add in some validations as well

  • Loading branch information...
commit 917183690429d256ad5420049152763429e54a8a 1 parent 9080a26
Stevan Little authored
Showing with 7 additions and 1 deletion.
  1. +7 −1 path-router.pl
View
8 path-router.pl
@@ -5,6 +5,7 @@
use MyApp::Hello;
use Path::Router;
+use Moose::Util::TypeConstraints;
my $router = Path::Router->new;
$router->add_route('' => (
@@ -19,6 +20,10 @@
controller => 'Blog',
action => 'monthly',
},
+ validations => {
+ year => subtype( as 'Int' => where { $_ > 0 } ),
+ month => subtype( as 'Int' => where { $_ >= 1 && $_ <= 31 } ),
+ }
));
$router->add_route('comment', => (
@@ -35,7 +40,8 @@
my $mapping = $match->mapping;
my $controller = "MyApp::" . $mapping->{controller};
- my $action = $controller->can(lc($req->method) . "_" . $mapping->{action});
+ my $action = $controller->can(lc($req->method) . "_" . $mapping->{action})
+ or return $req->new_response(404)->finalize;
my $res = $controller->$action($req, $mapping);
$res->finalize;
};
Please sign in to comment.
Something went wrong with that request. Please try again.