REST-Application
view release on metacpan or search on metacpan
lib/REST/Application/Routes.pm view on Meta::CPAN
$path ||= $self->getMatchText();
my $handler = sub { $self->defaultResourceHandler(@_) };
my %vars;
# Loop through the keys of the hash returned by resourceHooks(). Each of
# the keys is a URI template, see if the current path info matches that
# template. Save the parent matches for passing into the handler.
for my $template (keys %{ $self->resourceHooks() }) {
my $regex = join "\\/",
map {/^:/ ? '([^\/]+)' : quotemeta $_}
split m{/}, $template;
$regex = "^(?:$regex)\\/?\$";
if ($self->checkMatch($path, $regex)) {
$self->{__last_match_pattern} = $template;
%vars = $self->getTemplateVars($template);
$handler = $self->_getHandlerFromHook($template);
last;
}
}
return $self->callHandler($handler, \%vars, @extraArgs);
lib/REST/Application/Routes.pm view on Meta::CPAN
}
sub _get_template_vars {
my $self = shift;
return $self->getTemplateVars(@_);
}
sub getTemplateVars {
my ($self, $route) = @_;
my @matches = $self->_getLastRegexMatches();
my @vars = map {s/^://; $_} grep /^:/, split m{/}, $route;
return map { $vars[$_] => $matches[$_] } (0 .. scalar(@matches)-1);
}
sub getLastMatchTemplate {
my $self = shift;
return $self->getLastMatchPattern();
}
1;
__END__
( run in 0.598 second using v1.01-cache-2.11-cpan-5511b514fd6 )