[dfv] Problem with basic constraints
Status: Inactive
Brought to you by:
markjugg
From: Brian E. L. <br...@ma...> - 2006-10-25 21:49:00
|
I'm having a problem getting constraints working properly. I'm following the examples and I get failures even when I use the simplest of test cases. Attached and pasted below is a Test::More test that demonstrates my problem. I get this failure every time: lozier@ruggles:~$ ./borked.t 1..2 ok 1 - use Data::FormValidator; not ok 2 - zip is valid # Failed test (./borked.t at line 27) # Looks like you failed 1 test of 2. perl -v reports: This is perl, v5.8.7 built for i686-linux I'm using 4.4. I've tracked the culprit down to two spots. First, in the BEGIN of Constraints.pm, the match_zip function is called thusly: return &{"match_$func"}(\@_); I go into the match_zip function and it looks like this: sub match_zip { my $val = shift; if ($val =~ /^(\s*\d{5}(?:[-]\d{4})?\s*)$/) { return $1; } else { return undef; } } Very straightforward. However, "val" is always the number 1. I did a Data::Dumper(\@_) inside match_zip, reran the test, and it reports that @_ contains two elements, the first is a DFV object, and the second is the actual value to be matched. If I put a my $self = shift; at the top, it works fine. All the other match_* functions suffer from the same problem. Since this is such a glaring error, I'm wondering if A) nobody else uses the built-in constraints, or B) something is wrong with the way I'm setting up the profile, or C) something is wrong with my perl. Thanks in advance for any help you can offer. Brian Here is the test in case the attachment doesn't come through: #!/usr/local/bin/perl use warnings; use strict; use Test::More tests => 2; use_ok('Data::FormValidator'); my %profile = ( optional => ['zip'], constraint_methods => { zip => ['zip'] } ); my %data = ( zip => 56567 ); my $r = Data::FormValidator->check(\%data, \%profile); my @invalid = $r->invalid(); ok(!grep(@invalid, 'zip'), 'zip is valid'); |