Bloodnok has asked for the wisdom of the Perl Monks concerning the following question:
If a field type validation is declared as follows:
the following error is seen when OIO calls the sub with a value of undef (aka the constructor is called with type => undef) ...sub validate_max_size { my $val = shift; ! defined $val || $val > 0; } . . # Then later ... . my @data :Field :Type( \&package::validate_max_size );
The problem is that no error unsues from running similar code as a one-liner e.g.# Failed test 'Valid max_size: undef' # at (eval 4) line 43. # died: OIO::Code error: Problem with type check routine for initializ +er 'max_size' for class 'IBM::Common::Collection # Error: Argument "undef" isn't numeric in numeric gt (>) # Package: main # File: t/IBM-Common-Collection.t # Line: 68
perl -Mstrict -we 'sub f {my $v = shift; ! defined $v || $v > 0}; f(un +def)'
Here's the rub: Has anybody else encountered (and hopefully, overcome) this problem ??
TIA ,
Update: Thanx, once again to ikegami who noticed a disparity between the use of or and ||. Having now tried all combinations of the 2 in the 2 circumstances, exasperatingly, the principle problem remains.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Object::InsideOut field type validation
by ikegami (Patriarch) on Feb 05, 2009 at 19:25 UTC | |
by Bloodnok (Vicar) on Feb 05, 2009 at 19:49 UTC | |
by gone2015 (Deacon) on Feb 05, 2009 at 20:51 UTC |