hunk ./lib/Data/FormValidator/Results.pm 22 -use vars qw/$AUTOLOAD $VERSION/; hunk ./lib/Data/FormValidator/Results.pm 26 -$VERSION = 4.65; +our $VERSION = 4.65; hunk ./Build.PL 38 + configure_requires => { 'Module::Build' => 0.38 }, hunk ./Changes 1 -4.77 11/11/11 + +4.70 11/11/11 + + [NEW FEATURES] + - Built-in constraints in Constraints.pm can now be renamed: + + constraint_methods => { + first_names => { + constraint_method => FV_max_length(3), + name => 'custom_length', + } + }, + + (Thanks to heinst@arqs.com.br for the suggestion, RT#49477) + + [INTERNALS] + - modernize Constraints.pm and Results.pm a bit. + - Module::Build added to configure_requires in Build.PL + +4.67 11/11/11 hunk ./lib/Data/FormValidator.pm 35 -our $VERSION = '4.67'; +our $VERSION = '4.70'; hunk ./lib/Data/FormValidator/Constraints.pm 23 +use base 'Exporter'; hunk ./lib/Data/FormValidator/Constraints.pm 25 -use vars qw/$AUTOLOAD @ISA @EXPORT_OK %EXPORT_TAGS $VERSION/; +our $AUTOLOAD; hunk ./lib/Data/FormValidator/Constraints.pm 27 -$VERSION = 4.65; - -require Exporter; -@ISA = qw(Exporter); +our $VERSION = 4.70; hunk ./lib/Data/FormValidator/Constraints.pm 63 - \$dfv->name_this('$func'); + \$dfv->name_this('$func') unless \$dfv->get_current_constraint_name(); hunk ./lib/Data/FormValidator/Constraints.pm 82 - @EXPORT_OK = ( + our @EXPORT_OK = ( hunk ./lib/Data/FormValidator/Constraints.pm 114 - %EXPORT_TAGS = ( + our %EXPORT_TAGS = ( hunk ./lib/Data/FormValidator/Constraints.pm 167 - $dfv->name_this($new_name); + $dfv->name_this($new_name) unless $dfv->get_current_constraint_name(); hunk ./lib/Data/FormValidator/Constraints.pm 200 - fax => american_phone(), hunk ./lib/Data/FormValidator/Constraints.pm 201 - state => state(), + first_names => { + constraint_method => FV_max_length(3), + name => 'my_custom_name', + }, + }, + msgs => { + constraints => { + my_custom_name => 'My message', + }, hunk ./lib/Data/FormValidator/Constraints.pm 213 + hunk ./lib/Data/FormValidator/Constraints.pm 285 - $dfv->name_this('length_between'); + $dfv->name_this('length_between') unless $dfv->get_current_constraint_name(); hunk ./lib/Data/FormValidator/Constraints.pm 298 - $dfv->name_this('max_length'); + $dfv->name_this('max_length') unless $dfv->get_current_constraint_name(); hunk ./lib/Data/FormValidator/Constraints.pm 311 - $dfv->name_this('min_length'); + $dfv->name_this('min_length') unless $dfv->get_current_constraint_name(); hunk ./lib/Data/FormValidator/Constraints.pm 334 - return sub { - my $dfv = shift; - $dfv->name_this('eq_with'); + return sub { + my $dfv = shift; + $dfv->name_this('eq_with') unless $dfv->get_current_constraint_name(); hunk ./lib/Data/FormValidator/Constraints.pm 679 +=head1 RENAMING BUILT-IN CONSTAINTS + +If you'd like, you can rename any of the built-in constraints. Just define the constraint_method and name +in a hashref, like this: + + constraint_methods => { + first_names => { + constraint_method => FV_max_length(3), + name => 'custom_length', + } + }, + + hunk ./lib/Data/FormValidator/Results.pm 26 -our $VERSION = 4.65; +our $VERSION = 4.70; addfile ./t/rename_builtin_constraints.t hunk ./t/rename_builtin_constraints.t 1 +#!perl +use Test::More 'no_plan'; + +use Data::FormValidator; +use Data::FormValidator::Constraints qw( + FV_max_length +); + +my $result = Data::FormValidator->check({ + first_names => 'Too long', + }, + { + required => [qw/first_names/], + constraint_methods => { + first_names => { + constraint_method => FV_max_length(3), + name => 'custom_length', + } + }, + msgs => { + constraints => { + custom_length => 'Custom length msg', + } + }, + }); + +like( $result->msgs->{'first_names'}, qr/Custom length msg/, "built-ins can have custom names" ); + +