CleanCode Perl Libraries
Multi-Lingual Library Maintainability
available: Perl not available: Java available: JavaScript not available: Certified
not available: Testable
not available: Standalone
available: Diagnostic


CGI::PageValidator::CheckItem - Check validity of a single input item.


  use CGI::PageValidator::CheckItem;
  # prep
  . . .
  # build library
  $checkItem = CGI::PageValidator::CheckItem->new($elem, $replaced);
  . . .
  # validate with library
  $checkItem->doValidate($val, $depValue);
  . . .
  # report results
  $errList = CGI::PageValidator::CheckItem->getErrList();


Perl5.005, Data::Handy, Data::Diagnostic, CGI::PageValidator::Plugin


This module examines a single input value against the appropriate library entry, performing a series of standard tests plus an optional customized test (via a plugin). The standard tests (tested in this order) are:

If you use a plugin, it may alter the requirements for the other tests, or it may perform a test of its own.

Any validation violations are added to the class error list which may be retrieved via the getErrList method. These violations may be reported either as a message describing the violation (the default), or just the field name which had the violation. This style is controlled via the setNamesOnly method.

The public interface to this class is detailed below. However, if you are using the basic CGI::PageValidator system, you do not need to invoke those; they are invoked from within the CGI::PageValidator::LibraryMgr class.

Note on Plugins

The whole point of plugins is that they are not called directly, but rather dynamically according to your configuration. This is done by specifying the particular plugin name as the value of the plugin property to a CheckItem object. The CheckItem object, then, will assign this to a variable named $plugin, load the plugin class, create a plugin object, and invoke the examine method defined in this class. Both the class loading and the object creation are performed safely, i.e. any exceptions will be caught rather than cause an abnormal termination. The code fragment below shows how these steps are done in this class.

        $loadError = loadClass($plugin);
        eval { $pluginObj = $plugin->new(
                $this, $this->{dependsOn}, $fieldValue, $depValue, $pluginPkg); };
        $errMsg = $pluginObj->getResult();



PACKAGE->new(hashRef, replaced)

Creates a CheckItem object, a definition for a validating a single entity based on a collection of facets in the hashRef.


hashRef - reference to has containing validation facets

replaced - boolean; indicates this definition replaces a previous one for the same named entity. This is used only for diagnostic purposes in reporting about the library.


a newly created object




Resets collected list of errors to empty.



Returns collected list of errors.


Array reference to list of collected errors.



Sets error collection style when a violation is detected. Errors may be reported either as the field name only (true) or as a message describing the violation (the default).


boolValue - boolean; indicates to use names only or not.



Specifies the "parent" library manager which is manipulating a series of CheckItem objects (needed for dependency processing). This is needed only for two specialized purposes:

(1) To be able to lookup dependent objects to determine whether they are secure or not, and then mask these secure values (e.g. credit card numbers). If this method is not used, dependent values will be displayed unmasked without regard to security.

(2) To specify a non-default package for plugin libraries, which is determined by calling the getPluginPkg of the library manager.


libraryManager - LibraryMgr parent object



Create a shallow copy of the CheckItem object invoking this method. That is, only the first level of items is replicated; any references below that are references to the original.


CheckItem object that is a shallow copy of the original.



Returns the object's display name with the normalized value specified. The format is "name (value)". If the object does not have a display name, the field name itself is used. If the object is defined as a secure entity (e.g. for credit card numbers, etc.) the value is masked. This method provides a convenience for uniform name/value appearance, so its use is encouraged in any plugins, etc.


value - string; value to possibly mask and display.


Display string with name and value.



Returns the object's display group name with the normalized value specified. The format is "name (value)". If the object does not have a display group name, the display name for the object itself is examined. If the object does not have a display name, the field name is used. If the object is defined as a secure entity (e.g. for credit card numbers, etc.) the value is masked.

A display group name is a collective name for several fields, e.g. area code and phone number, two separate fields, together could be labelled as "telephone" when displaying the information. Similarly, city, state, and zip might be labelled as "post office".


value - string; value to possibly mask and display.


Display string with group name and value.



Normalizes the specified value in the sense of masking it if the object is defined as a secure entity. Otherwise the value is returned unchanged.


value - string; value to mask, if appropriate.


Secure (i.e. masked) value if object is defined as a secure entity; plain value otherwise.


OBJ->doValidate(fieldValue, depValue)

Validate the specified value using the facets of this CheckItem object. When the value fails a criterium, an error message (or just the field name) is added to the class-common error list. The first failure stops further checking, so no more than one error per field will appear on the error list.

The set of tests is listed, in order, in the introduction section of this page. The only item not listed there is the special case of plugin validation. Using a plugin allows you to connect this CheckItem object with other CheckItem objects semantically. So, for example, you could create a plugin to check a credit card expiration date where the month value and the year value are in separate fields. See the Plugin class for details on how to hookup and use plugins.


fieldValue - string; value to validate.

depValue - string or array reference of strings, which must match the defined dependencies for this entity (dependsOn property). That is, if the entity depends on exactly one other entity, then depValue must be a single string. If the entity depends on multiple other entites, depValue must be an array reference.




Michael Sorens


$Revision: 8 $ $Date: 2006-12-19 21:13:43 -0800 (Tue, 19 Dec 2006) $


CleanCode 0.9


CGI::PageValidator::Plugin, CGI::PageValidator::LibraryMgr, CGI::PageValidator::MainLib::SysLib, CGI::PageValidator::MainLib::UserLib


Hey! The above document had some coding errors, which are explained below:

Around line 212:

=back doesn't take any parameters, but you said =back -- end of CONSTRUCTOR section

Around line 562:

=back doesn't take any parameters, but you said =back -- end of METHODS section

CleanCode Perl Libraries Copyright © 2001-2013 Michael Sorens - Revised 2013.06.30 Get CleanCode at Fast, secure and Free Open Source software downloads