Created
August 12, 2012 10:56
-
-
Save Htbaa/3331284 to your computer and use it in GitHub Desktop.
More Validation::Class woes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Foo; | |
use Validation::Class; | |
directive 'is_troll' => sub { | |
my ($dir, $value, $field, $self) = @_; | |
foreach (@{$value}) { | |
if ($_->[1] !~ /application\/(x-)?pdf/i) { | |
$field->{errors}->add(sprintf('Error for %s', $_->[0])); | |
} | |
} | |
return scalar @{$field->{errors}}; | |
}; | |
field 'foobar' => { | |
required => 1, | |
default => [ | |
['something.pdf', 'application/pdf'], | |
['something3.pdf', 'application/pdf'] | |
], | |
is_troll => 1, | |
}; | |
profile 'bar' => sub { | |
return shift->validate(qw/+foobar/); | |
}; | |
package main; | |
use v5.12; | |
use Data::Dumper; | |
use strict; | |
my $input = Foo->new( | |
params => { | |
foobar => | |
[['foo.pdf', 'application/pdf'], ['bar.pdf', 'application/pdf']] | |
} | |
); | |
my $foobar = $input->foobar(); | |
say Dumper($foobar); | |
say "yes 1" if ($input->validate('foobar')); | |
say "yes 2" if ($input->validate_profile('bar')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment