Dancer Recent News (1.3060 and the future 1.3070)

Dancer is moving (or dancing?). There are some news (some more relevant than others) that I would like to share here.

First some less relevant, but nevertheless useful features. Starting from 1.3060 you can access parameters values using a similar syntax with CGI:

   get "/foo" => sub {  my $name = param("name"); };

Not a killer feature, but handy. Also useful, there is an accessor for cookies:

   get "/bar" => sub {  my $cookie_value = cookie "cookie_name";  };

The location and name of the log file can be defined in the configuration file, or directly on your code. Use variables log_dir and log_file for that:

   set log_dir => "/var/log/dancer/", log_file => "app1.log";

You might also notice that set can set multiple variables at once.

Now, the most interesting feature added in the last weeks is lexical prefix. Instead of changing the route prefix from now on, it is possible to define it for a block:

    prefix "/user" => sub {
           get "/profile" => sub  { ... };
           get "/dashboard" => sub { ... };
    };

This can get even more interesting, if we tell you that you can nest prefix definitions:

    prefix "/foo" => sub {
            # some routes under /foo
            prefix "/bar" => sub {
                 # some routes under /foo/bar
            };
     };

Just note that for nested prefixes you need the current github head. But you might get a release soon.

1 Comment

Leave a comment

About Alberto Simões

user-pic I blog about Perl. D'uh!