Skip to content

Instantly share code, notes, and snippets.

/json.diff Secret

Created July 7, 2015 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/97f7d055a6c450079069 to your computer and use it in GitHub Desktop.
Save anonymous/97f7d055a6c450079069 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojolicious/Validator/Validation.pm b/lib/Mojolicious/Validator/Validation.pm
index ac1c410..5d28115 100644
--- a/lib/Mojolicious/Validator/Validation.pm
+++ b/lib/Mojolicious/Validator/Validation.pm
@@ -1,7 +1,8 @@
package Mojolicious::Validator::Validation;
use Mojo::Base -base;
-use Carp ();
+use Carp ();
+use Mojo::JSON::Pointer;
use Scalar::Util ();
has [qw(csrf_token topic validator)];
@@ -23,9 +24,12 @@ sub check {
return $self unless $self->is_valid;
- my $cb = $self->validator->checks->{$check};
- my $name = $self->topic;
- my $input = $self->input->{$name};
+ my $cb = $self->validator->checks->{$check};
+ my $name = $self->topic;
+ my $input
+ = $name =~ m!^/!
+ ? Mojo::JSON::Pointer->new($self->input)->get($name)
+ : $self->input->{$name};
for my $value (ref $input eq 'ARRAY' ? @$input : $input) {
next unless my $result = $self->$cb($name, $value, @_);
return $self->error($name => [$check, $result, @_]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment