[dfv] Data::FormValidator::Constraints::Upload
Status: Inactive
Brought to you by:
markjugg
|
From: Jiří P. <ji...@ge...> - 2011-02-20 20:09:19
|
Hello,
I want to use Data::FormValidator::Constraints::Upload to validate photo
upload. I want to check the image type and optionally (based on other
parameter) its dimensions).
I'm not quite sure what is the best way to handle the optional
conditional constraint.
What I did was to store the constraint subroutines returned by the
appropriate methods in a variable and wrote my own constrain methods.
I'm just not sure whether it is the best approach.
Here is what I have:
my $image_type_constraint = file_format(mime_types => ['image/png'] );
my $image_size_constraint = image_max_dimensions(200,200);
...
constraint_methods => {
photo_file => {
constraint_method => sub {
my ( $dfv, $photo_file, $main_web_photo,) = @_;
return 0 unless $image_type_constraint->($dfv,
$photo_file);
if ($main_web_photo) {
return 0 unless $image_size_constraint->($dfv,
$photo_file);
}
return 1;
},
params => [ qw( photo_file main_web_photo ) ],
},
},
|