[dancer-users] Call to all Dancer2 plugin writers

Yanick Champoux yanick at babyl.dyndns.org
Wed Oct 14 16:21:57 BST 2015


On 2015-10-14 10:38 AM, Stefan Hornburg (Racke) wrote:
>> I have a question about the add_route functionality,  how can I access to the DSL keywords? eg. param('param_name') when I'm defining the code for a new route?

> The first parameter for the route sub is an $app object, so you can do for example:

Yup. The 'app' object is the way to go. As Racke mentioned, it's passed
to the coderef, and it's also available as an attribute of the plugin
object:

    sub BUILD {
        my $plugin = shift;

        $plugin->app->add_route(
            method => 'get',
            regexp => '/goodbye',
            code   => sub {
		'farewell ' . $plugin->app->request->params->{name};
		# or
                my $app = shift;
		'farewell ' . $app->request->params->{name};
	    },
        );

    }

`/.




More information about the dancer-users mailing list