Skip to content

Commit

Permalink
a few more validation examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 2, 2013
1 parent 9ba4e88 commit d2fbc3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/Mojolicious/Validator.pm
Expand Up @@ -52,6 +52,9 @@ Mojolicious::Validator - Validate form data
my $validator = Mojolicious::Validator->new;
my $validation = $validator->validation;
$validation->input({foo => 'bar'});
$validation->required('foo')->regex(qr/ar$/);
say $validation->param('foo');
=head1 DESCRIPTION
Expand All @@ -70,7 +73,7 @@ Value needs to be equal to the value of another field.
=head2 in
$validation->in('foo', 'bar', 'baz');
$validation->in(qw(foo bar baz));
Value needs to match one of the values in the list.
Expand Down
7 changes: 5 additions & 2 deletions lib/Mojolicious/Validator/Validation.pm
Expand Up @@ -11,8 +11,8 @@ sub AUTOLOAD {
my $self = shift;

my ($package, $method) = our $AUTOLOAD =~ /^([\w:]+)::(\w+)$/;
Carp::croak "Undefined subroutine &${package}::$method called"
unless Scalar::Util::blessed $self && $self->isa(__PACKAGE__);
croak "Undefined subroutine &${package}::$method called"
unless blessed $self && $self->isa(__PACKAGE__);

croak qq{Can't locate object method "$method" via package "$package"}
unless $self->validator->checks->{$method};
Expand Down Expand Up @@ -94,6 +94,9 @@ Mojolicious::Validator::Validation - Perform validations
my $validator = Mojolicious::Validator->new;
my $validation
= Mojolicious::Validator::Validation->new(validator => $validator);
$validation->input({foo => 'bar'});
$validation->required('foo')->in(qw(bar baz));
say $validation->param('foo');
=head1 DESCRIPTION
Expand Down

0 comments on commit d2fbc3b

Please sign in to comment.