[dancer-users] Call to all Dancer2 plugin writers
Stefan Hornburg (Racke)
racke at linuxia.de
Wed Oct 14 18:49:42 BST 2015
On 10/14/2015 05:21 PM, Yanick Champoux wrote:
> 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};
> },
> );
>
> }
>
> `/.
Yanick, would you mind to enhance the POD with this example?
The second variant is more straight forward in my opinion
(getting $app from subroute parameters instead of using closure
variable).
Regards
Racke
--
Perl and Dancer Development
Visit our Perl::Dancer conference 2015.
More information on https://www.perl.dance.
More information about the dancer-users
mailing list