Dancer2::Plugin::ParamKeywords - Sugar for the params() keyword
version v0.1.4
use Dancer2; use Dancer2::Plugin::ParamKeywords; any '/:some_named_parameter' => sub { my $route_param = route_param('some_named_parameter'); my $get_param = query_param('some_named_parameter'); my $post_param = body_param('some_named_parameter'); };
The default Dancer2::Core::Request params accessor munges parameters in the following precedence from highest to lowest: POST parameters, named route parameters, and GET parameters.
POST
GET
Consider the following route:
post '/people/:person_id' => sub { my $person_id = param('person_id'); ... # Perform some operation using $person_id as a key };
In the above example, if the browser/client sends a parameter person_id with a value of 2 in the POST body to route /people/1, $person_id will equal 2 while still matching the route /people/1.
person_id
/people/1
$person_id
This plugin provides keywords that wrap around params($source) for convenience to fetch parameter values from specific sources.
params($source)
The "munged_params" and "munged_param" keywords require you to configure an order of precedence by which to prefer parameter sources. Please see Dancer2::Core::Request params accessor for a list of valid sources.
# In config.yml plugins: ParamKeywords: munge_precedence: - route - body - query
If you won't be using the munged_* keywords, you don't need to bother configuring this plugin.
Returns the value of a given parameter from the "munged_params" hash.
Returns a hash in list context or a hash reference in scalar context of parameters munged according to the precedence provided in the configuration file (from highest to lowest).
Returns the value supplied for a given parameter in the query string.
Returns the arguments and values supplied by query string. Returns a hash in list context or a hasref in scalar context.
Returns the value supplied for a given parameter in the POST arguments.
Returns arguments and values supplied by a POST request. Returns a hash in list context or a hasref in scalar context.
Returns the value supplied for a given named parameter in the route.
Returns the arguments and values suppled by the route. Returns a hash in list context or a hasref in scalar context.
This module follows semantic versioning (http://www.semver.org).
Chris Tijerina
This software is copyright (c) 2015 by Chris Tijerina.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Dancer2::Plugin::ParamKeywords, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer2::Plugin::ParamKeywords
CPAN shell
perl -MCPAN -e shell install Dancer2::Plugin::ParamKeywords
For more information on module installation, please visit the detailed CPAN module installation guide.