View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
John Karr > String-Validator-Common > String::Validator::Common



Annotate this POD


View/Report Bugs
Module Version: 2.00   Source  


String::Validator::Common - Base Module for creating new String::Validator Modules.


version 2.00


A base module for use in creating new String Validators.

String::Validator::Common Methods and Usage ^

Public Methods

The Following Methods are meant to be provided by sublcasses as Public Methods: IsValid, IsNotValid, Errstr, Errcnt, String.

Semi-Private Methods

The remaining methods are meant for use within subclasses of String::Validator::Common. They are not preceded with _ characters because they are being exposed from SVC to the inheriting class.


Modules Using String Validator Common extend the attributes in their own new methods.

 use String::Validator::Common;
 sub new {
 my $class = shift ;
 my $self = { @_ } ;
 use parent ( 'String::Validator::Common' ) ;
 unless ( defined $self->{ some_param } )
   { $self->{ some_param } = 'somedefault'; }
 bless $self , $class ;
 return $self ;


Check is a stub subroutine, that you will replace in any Validator Module you write with the code to validate the string. Is_Valid and IsNot_Valid base their results on Check. Check returns $self->{error}, if there are no errors this will be 0. When you replace Check in your Validator Module you should implement the same behaviour so that IsValid and IsNot_Valid work.


Takes a string and optionally a second string (if you want to make sure two copies of a string are identical as well). Runs the Check subroutine and returns $self->{errstring} if there is an error, otherwise it returns 0. This will evaluate to true if there was an error and false if the string was valid.


Takes a string and optionally a second string (if you want to make sure two copies of a string are identical as well). Runs the Check subroutine and returns 1 if Check returned 0, and 0 if Check returned a true value. If you want ->Errcnt() count or ->Errstr you will need to request them via their methods before another string is processed.


A String::Validator contains two error variables error and errstring. When an error is found, simply pass a brief description to this method to increment the errorcount, and append the present description to the errstring.

 if ( 1 != 2 ) { $self->IncreaseErr( q/1 Still Doesn't equal 2!/ ) }


This method initializes three key values: $self->{errstring} , $self->{error}, and $self->{string} to NULL, 0, NULL. If no errors are found error and errstring will remain 0 and NULL. string will be used to hold the string being evaluated. Arguments are the string to be evaluated and optionally a second string to be compared with the first. If the strings are mismatched the sub will return 99, and string will remain NULL, the inheriting module should immediately return the error and not contine.


Checks $self->{ string } against $self->{ min_length } and $self->{ max_length } If the length checks pass it returns 0, if one fails it immediately returns the incremented value of error.


CheckCommon is just a shortcut to run Start and Length.

Errstr, Errcnt, String

Provides these methods for inheritance as described in the String::Validator documentation.

is_valid, isnot_valid, errcnt, errstr, string

Permit LowerCase invokation of these methods.


Please report any bugs or feature requests through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


John Karr <>


This software is Copyright (c) 2014,2018 by John Karr.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007
syntax highlighting: