Leyland
view release on metacpan or search on metacpan
lib/Leyland/Negotiator.pm view on Meta::CPAN
=head2 find_options( $c, $app_routes )
Finds all routes that match a certain path when an HTTP OPTIONS request
is received.
=cut
sub find_options {
my ($class, $c, $app_routes) = @_;
my $routes = $class->matching_routes($app_routes, $class->prefs_and_routes($c->path));
# have we found any matching routes?
$c->exception({ code => 404 }) unless scalar @$routes;
# okay, we have, let's see which HTTP methods are supported by
# these routes
my %meths = ( 'OPTIONS' => 1 );
foreach (@$routes) {
$meths{$class->method_name($_->{method})} = 1;
}
lib/Leyland/Negotiator.pm view on Meta::CPAN
return uc($meth);
}
sub _negotiate_path {
my ($class, $c, $args) = @_;
$args->{path} ||= $c->path;
# let's find all possible prefix/route combinations
# from the request path and then find all routes matching the request path
my $routes = $class->_matching_routes($args->{app_routes}, $class->_prefs_and_routes($args->{path}), $args->{internal});
if ($args->{method}) {
return $class->_negotiate_method($args->{method}, $routes);
} else {
return $routes;
}
}
sub _prefs_and_routes {
my ($class, $path) = @_;
my $pref_routes = [{ prefix => '', route => $path }];
my ($prefix) = ($path =~ m!^(/[^/]+)!);
my $route = $' || '/';
my $i = 0; # counter to prevent infinite loops, probably should be removed
while ($prefix && $i < 1000) {
push(@$pref_routes, { prefix => $prefix, route => $route });
my ($suffix) = ($route =~ m!^(/[^/]+)!);
( run in 2.129 seconds using v1.01-cache-2.11-cpan-0bb4e1dffa6 )