Data::Validator::Item is a Factory Class to validate data items.
This is an attempt to create an object which will permit semi-automatic verification of a data value.
my $item = Data::Validator::Item->new(); #Create a new Data::Validator::Item, called $item.
$item->values([1,2,3]); or $item->values(@array);
$item->missing('*'); or $item->missing(''); #undef is unlikely to be sensible!
$item->verify($reference_to_subroutine); #Used in the $item->validate() function
$item->transform($reference_to_subroutine); #Used in the $item->put() function
my $name = $item->name();
my @values = $item->values();
my $missing = $item->missing();
#Use it.. $item->validate(); #Returns 1 for success, 0 for failure $item->error(); #Returns the correct error message $item->put();
Many people work with data organised as records, each containing (potentially many) variables. It is often necessary to process files of such records, and to test every variable within every record to ensure that each one is valid. I do this before putting data from very large flat files into my databases. For each variable I had a need to define specific, sometimes complex rules for validity, then implement them, and check them. This is what Data::Validator::Item is for.
Note carefully that Data::Validator::Item handles only one scalar vlaue at a time. This value could come from a file, a database, an array, a hash or your granny's parrot. Data::Validator::Item doesn't care.
I use Data::Validator::Item as follows. I create one for every named variable in my data file. In many real applications most of this setup can be done by looping over a list of variable names, creating many Data::Validator::Items each named for the corresponding variable. Common features, like missing values, and names can be set in this loop.
Specifics, like values(), min(), max(), verify() and so on can be set individually. I then create a hash to hold all of the Data::Validator::Items for a particular data source, The keys of this hash are the names of the variables, and the values are the Data:Validators themselves. Y.M.M.V.