Search code examples
perldancer

perl dancer - "any" method - which actual method called?


Using Perl's Dancer module, if you have an "any" method (which will match get/post/put/delete), how can you determine which actual method the browser used?

#!/usr/bin/perl

use Dancer;

my $instance = someclass->new();

any('/' => sub{
  my $method = ???
  my $params = params();
  return($instance->$method($params));
});  

Solution

  • I think it's

    my $method = request->method;
    

    Although the docs suggest you should use the following if possible (doesn't make sense for your general proxy/delegate):

    request->is_get();
    request->is_post();
    # etc . .