in reply to proper Sub::Contract use
As to your bigger question, if you want to identify the 'row' as well as the 'column' where the wrong value occurs, you could let information flow either way: You could pass &array_of_scalars the index of the row it's checking, so that it can incorporate that in the error message; or you could provide a way (by exception-throwing, probably) for &array_of_scalars to indicate to its caller the objectionable column, and adjust &array_of_array_of_scalar's error message accordingly. Also, yes, it looks (at a cursory scan) as if Sub::Contract can do what you want; but, if you are just concerned with checking for AoAs, then a simple grep is probably closer to what you want.
UPDATE: On further reading, Sub::Contract still requires you to write your own tests; and, since it says of error messages:
When a call to a contractor breaks the contract, the constraint code will return false or croak. If it returns false, Sub::Contract will emit an error looking as if the contractor croaked.it sounds as if it won't give (on its own) the sort of specific error messages you want. Thus, you'll still need to write the tests (which you've mostly already done). If you want (as you seem to do, and should!) to use a module rather than rolling your own, Data::Validate::Struct might help (although, again, it seems to be going a bit overboard in this case).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: proper Sub::Contract use
by Anonymous Monk on Sep 03, 2008 at 07:07 UTC | |
by JadeNB (Chaplain) on Sep 03, 2008 at 19:36 UTC |