Skip to content

Instantly share code, notes, and snippets.

@Htbaa
Created August 12, 2012 10:56
Show Gist options
  • Save Htbaa/3331284 to your computer and use it in GitHub Desktop.
Save Htbaa/3331284 to your computer and use it in GitHub Desktop.
More Validation::Class woes
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