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

NAME

CGI::PageValidator - Top-level object for validating data.

SYNOPSIS

  use CGI::PageValidator;
  $validator = CGI::PageValidator->new($inputData,$libMgr,$namesOnly);
  $validator->process();
  if (!$validator->success()) {
    $errListRef = $validator->errors();
    print @$errListRef;
  }

REQUIRES

Perl5.005, Data::Diagnostic, CGI::PageValidator::CheckItem

DESCRIPTION

This is the main object to process a web form or other input data for validation. As shown in the synopsis, create an object with appropriate parameters, invoke the process method to do the validation, then handle the resultant list of validation errors (if any).

See the top-level validate.pl program for a working example on how to set up validation, use this class, and process the results.

CONSTRUCTOR

new

PACKAGE->new(inputData, libMgr, namesOnly)

Creates a PageValidator object that may be used to validate a series of input data items against a library of constraints. The output is a list of violations each of which may be either a string describing the violation, or just the field name (based on the namesOnly parameter).

Parameters:

inputData - an InputOptions object; the getDataKeySet and getProperty methods are needed to retrieve the list of field names and the value of each field, respectively.

libMgr - a LibraryMgr object; the getItem method is needed to retrieve a definition from the library (in the form of a CheckItem object).

namesOnly - optional; boolean; as the list of validation errors is accumulated, this flag indicates to include only the field names, or a complete message describing the violation.

METHODS

process

OBJ->process()

This method clears the error list which will be generated during validation, then validates each input item by calling the doValidate method of each CheckItem object in the libMgr provided through the constructor. The generated error list is actually accumulated in the CheckItem class, so after all items are processed, the error list is retrieved from the library and made available via the errors method.

success

OBJ->success()

Indicates whether the primary method of this object ran without error.

Returns:

Boolean indicating whether process method executed successfully.

errors

OBJ->errors()

If success reports failure, this method returns the list of errors for display or other processing.

Returns:

Reference to array of error message strings; each is either a field name or a descriptive message describing each violation, depending on the namesOnly flag passed in to the constructor.

BUGS

None

AUTHOR

Michael Sorens

VERSION

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

SINCE

CleanCode 0.9

SEE ALSO

bin::validate, CGI::PageValidator::LibraryMgr, CGI::PageValidator::CheckItem, CGI::PageValidator::Plugin, CGI::PageValidator::MainLib::SysLib, CGI::PageValidator::MainLib::UserLib

POD ERRORS

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

Around line 124:

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

Around line 227:

=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 SourceForge.net. Fast, secure and Free Open Source software downloads