File Coverage

blib/lib/Dancer2/Plugin/ParamKeywords.pm
Criterion Covered Total %
statement 28 28 100.0
branch 3 6 50.0
condition n/a
subroutine 8 8 100.0
pod n/a
total 39 42 92.8


line stmt bran cond sub pod time code
1 1     1   489063 use 5.16.0;
  1         5  
  1         40  
2 1     1   4 use strict;
  1         1  
  1         29  
3 1     1   3 use warnings;
  1         5  
  1         31  
4              
5             package Dancer2::Plugin::ParamKeywords;
6 1     1   493 use Dancer2::Plugin;
  1         2224  
  1         4  
7              
8             our $VERSION = 'v0.1.0';
9              
10             foreach my $source ( qw( route query body ) ) {
11             register "$source\_param" => sub {
12 3     3   1284230 my ($dsl, $param) = @_;
13 3         32 $dsl->app->request->params($source)->{$param};
14             };
15            
16             register "$source\_params" => sub {
17 3     3   10467 my $dsl = shift;
18 3         14 $dsl->app->request->params($source);
19             };
20             }
21              
22             register munged_params => sub {
23 3     3   29079 my $dsl = shift;
24 3         20 my $conf = plugin_setting->{munge_precedence};
25 3 50       337 die 'Please configure the plugin settings for ParamKeywords to use munged_params'
26             unless ref($conf) eq 'ARRAY';
27              
28 3         11 my %params = map { $dsl->app->request->params($_) } reverse @$conf;
  9         91  
29 3 50       47 wantarray ? %params : \%params;
30             };
31              
32             register munged_param => sub {
33 3     3   28464 my ($dsl, $param) = @_;
34 3         17 my $conf = plugin_setting->{munge_precedence};
35 3 50       223 die 'Please configure the plugin settings for ParamKeywords to use munged_param'
36             unless ref($conf) eq 'ARRAY';
37              
38 3         9 my %params = map { $dsl->app->request->params($_) } reverse @$conf;
  9         125  
39 3         46 $params{$param};
40             };
41              
42             register_plugin for_versions => [ 2 ] ;
43              
44             1;
45              
46             # ABSTRACT: Sugar for the params() keyword
47             # PODNAME: Dancer2::Plugin::ParamKeywords
48              
49             __END__