Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make it compile.

default test
  • Loading branch information...
commit f7e66751aaffd18b95f92643413180b6dcbb173d 1 parent 6e73b61
@dams authored
View
15 lib/Dancer/Plugin/Params/Normalization.pm
@@ -33,15 +33,16 @@ my $normalization_fonction = $void;
if (defined $conf->{method}) {
if (defined $conf->{params_filter}) {
my $re = $conf->{params_filter};
- $params_filter = sub { scalar($_[0] =~ /$re/) }
+ $params_filter = sub { scalar($_[0] =~ /$re/) };
}
+ my $method;
if ($conf->{method} eq 'lowercase') {
- $method = sub { my ($h) = @_; $apply_on_keys($h, sub { lowercase($_[0]) } ) };
+ $method = sub { my ($h) = @_; $apply_on_keys->($h, sub { lc($_[0]) } ) };
} elsif ($conf->{method} eq 'uppercase') {
- $method = sub { my ($h) = @_; $apply_on_keys($h, sub { uppercase($_[0]) } ) };
+ $method = sub { my ($h) = @_; $apply_on_keys->($h, sub { uc($_[0]) } ) };
} elsif ($conf->{method} eq 'ucfirst') {
- $method = sub { my ($h) = @_; $apply_on_keys($h, sub { ucfirst($_[0]) } ) };
+ $method = sub { my ($h) = @_; $apply_on_keys->($h, sub { ucfirst($_[0]) } ) };
} else {
my $class = $conf->{method};
eval("require $class");
@@ -59,12 +60,12 @@ if (defined $conf->{method}) {
my $routes_filter = $void;
if (defined $conf->{routes_filter}) {
- $route_filter = sub { }
+ $routes_filter = sub { };
}
# TODO : implement route filtering
- $_normalization_fonction = sub {
+ $normalization_fonction = sub {
request->_set_query_params($method->(params('query')));
request->_set_body_params($method->(params('body')));
request->_set_route_params($method->(params('route')));
@@ -75,7 +76,7 @@ if (defined $conf->{general_rule}) {
$conf->{general_rule} =~ /^always$|^ondemand$/
or die 'configuration field general_rule must be one of : always, ondemand';
if ($conf->{general_rule} eq 'ondemand') {
- register normalize => $_normalization_fonction;
+ register normalize => sub{ $normalization_fonction->() };
} else {
before $normalization_fonction;
}
View
22 t/02_test_normalization.t
@@ -1,3 +1,25 @@
use strict;
use warnings;
use Dancer::ModuleLoader;
+use Test::More;
+
+plan tests => 1;
+
+{
+ package Webservice;
+ use Dancer;
+ use Dancer::Plugin::Params::Normalization;
+
+ get '/foo' => sub {
+ use Data::Dumper;
+ print STDERR Dumper(params);
+ return params->{test};
+ };
+}
+
+use lib 't';
+use TestUtils;
+
+# test normal params
+my $response = get_response_for_request(GET => '/foo', { test => 5 });
+ok($response->{content} == 5, "bad response : '$response'");
Please sign in to comment.
Something went wrong with that request. Please try again.