String::Validator
You have a string and you need to know if it is what you need it to be. You just wasted three hours before you realized it was going to take longer than you thought and just started to poke around cpan to find something to use instead. The String Validator Collection is what you are looking for.
Since as often as not you're not just validating strings, but also trying to get them into a specific format, many String::Validator Modules will do this.
The Core Module, String::Validator is empty. It contains some common documentation, and all other String::Validator Modules are dependencies to install it. You can type cpanm String::Validator to install the current version of all of the Modules.
The new method for String-Validators takes as an argument a hash of parameters, these will be different for each module. See the specific Module's Documentation.
The negative method IsNot_Valid will return 0 (false) for a valid string and the reason as a string for an invalid one.
The positive method Is_Valid will return 1 (true) and 0 (false). To find out why a string failed use the errstr method.
Both Is_Valid and IsNot_Valid will take either one string or two strings as arguments. If two strings are provided they are compared. When two strings are provided and do not match only 1 error is observed, because String::Validator cannot know which (if either) to continue evaluating. If called subsequently the String() method will return Null and the errorcnt() method will return 1.
errcnt returns the number of errors seen on the last call to Is/IsNot_Valid. errstr returns a string describing the errors encountered.
The String method always returns the internal representation of the last string evaluated by Is/IsNot_Valid. The exceptions are that a new String::Validator Object will return a NULL value, as it will following a mismatch error when the string is passed twice. String-Validators may provide reformat methods appropriate to their purpose and will be documented in their own POD.
my $Validator = String::Validator::Demo->new( format => 'fake', min_length => 6, max_length => 17 ) ; if ( $Validator->IsNot_Valid('ThisString') { do something } or unless ( $Validator->IsNot_Valid('ThatString') { die $Validator->errstr() } maybe if ( $Validator->IsNot_Valid('ThisString', 'RepeatThisString') { do something } say $Validator->String ;
The base class String::Validator::Common provides both the CamelCase and lowercase versions of the methods it provides for use by the end user of the inheriting module, this is done to make it even more convenient.
Everything Validator does is a waste of time (if you had to do it yourself). So if you find you've wasted time validating something that fits with the Validator theme, write it up and send it in. If you think Validator does a poor job of something, send us a better solution. If you already made a module even better, Validator is all about dependency on other modules that do validation just suggest. If you read the sub-modules you'll see that many of them are just wrappers around other validation modules.
Version 0.97
John Karr, <brainbuz at brainbuz.org>
<brainbuz at brainbuz.org>
Please report any bugs or feature requests to bug-validor at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Validator. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-validor at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Validator
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Validator
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Validator
CPAN Ratings
http://cpanratings.perl.org/d/Validator
Search CPAN
http://search.cpan.org/dist/Validator/
Copyright 2011 John Karr.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 3 or at your option any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
A copy of the GNU General Public License is available in the source tree; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
To install String::Validator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::Validator
CPAN shell
perl -MCPAN -e shell install String::Validator
For more information on module installation, please visit the detailed CPAN module installation guide.