diff --git a/lib/HTTP/Router.pm b/lib/HTTP/Router.pm index 51a724f..23d2d6f 100644 --- a/lib/HTTP/Router.pm +++ b/lib/HTTP/Router.pm @@ -83,7 +83,12 @@ sub match { push @match, $match; } if (@match > 1) { - # TODO: sort + # FIXME: sort + for my $match (@match) { + my @vars = $match->route->templates->variables; + $match = [ $match, scalar grep { exists $match->route->conditions->{$_} } @vars ]; + } + @match = map { $_->[0] } sort { $b->[1] <=> $a->[1] } @match; } return wantarray ? @match : $match[0]; } diff --git a/tools/benchmark_match.pl b/tools/benchmark_match.pl index 503ab32..d397a01 100755 --- a/tools/benchmark_match.pl +++ b/tools/benchmark_match.pl @@ -28,6 +28,7 @@ sub request { my $conditions_request = request(path => '/account/login', method => 'POST'); my $validate_request = request(path => '/archives/2009'); my $resources_request = request(path => '/users/new', method => 'GET'); +my $resource_request = request(path => '/admin/edit', method => 'GET'); my $var_resources = request(path => '/users/masaki', method => 'GET'); timethese(10000, {