CleanCode Perl Libraries |
Home | Perl | Java | PowerShell | C# | SQL | Index | Tools | Download | What's New |
Multi-Lingual Library | Maintainability | ||||||||||||
Perl | Java | JavaScript | Certified Class |
Testable Class |
Standalone Mode |
Diagnostic Enabled |
validate.pl - A sample interface to the CleanCode Validation Engine.
validate.pl [ -h ] { <name>=<value>... }
Perl5.005, CGI, Getopt::Std, Data::Diagnostic, Data::InputOptions, CGI::PageValidator, CGI::PageValidator::LibraryMgr, Data::Handy,
This file is a working sample of the CleanCode validation engine interface. It may be executed from the shell command line, or as a CGI program to serve web pages. This validation engine is available in both Perl and JavaScript, providing front-end and back-end validation with the same engine. Front-end processing provides speed of response, while back-end provides security and robustness.
When run from the command line, one may either use the syntax shown above, or for more extensive argument lists, place the 'name-value' pairs in a data file, one entry per line, and redirect standard input from the file. Program output is sent to stdout.
When run by a web server, the parameters come from the HTTP GET or POST, and output of course is sent back to the client browser.
The input parameters may be either configuration values or data values, distinguished by the case of the name. All capitals are recognized as configuration values and become part of the system configuration during initialization. Mixed case or lower case are passed on as data values.
For adapting to production use, hook your web page generation into the validateForm
, cgiInit
, and cgiOutput
functions in this file. In this sample program, the validation results--good or bad--are simply presented on an otherwise blank web page.
The main routine in this file simply initializes a few variables, executes a call to the validateForm
function, and exits. The single parameter to validateForm
is a reference to an array containing the names of the required fields for one particular web page. This array should be tailored to your application, and, when run by a web server, must be synchronized with the form on your web page which invoked this program.
All named fields in the array must exist in the validation library (either the system library SysLib or the user library UserLib). A web form invoking this script will, of course, provide a list of input field names, but one cannot rely on the integrity of that list, since it could be easily manipulated. Providing the list of field names to validateForm
also provides a double-check on what the web form provides, allowing us to report any missing fields.
This validation engine is available for both front-end use (in a client browser) and back-end use (such as this program). In order to have only a single library used by both either client or server, the validation library is written in JavaScript so it may be directly attached to a web page like any other code file. For back-end use, the library is converted on-the-fly to Perl, and then used.
As indicated previously, configuration settings may be set from the command line, or equivalently by the web page invoking this program. But the more usual way is to use a configuration file (CONFIG_FILE_NAME
in this program). The configuration file is used to define your default settings; any command-line values override these settings (if you've set up permissions to allow this). This configuration data is managed by an InputOptions object.
An InputOptions object manages configuration, as mentioned above.
Detailed, selectable, directable diagnostics are manipulated via a Diagnostic object.
A LibraryMgr object manages the validation library.
A PageValidator object performs the actual validation.
In this sample program, the result of the validation is simply displayed on an otherwise empty web page (along with whatever diagnostics are enabled).
TBD For the front-end exerciser, load the VExerciser.html web page in your browser.
None
Michael Sorens
$Revision: 380 $ $Date: 2008-08-07 07:02:51 -0700 (Thu, 07 Aug 2008) $
CleanCode 0.9
Home | Perl | Java | PowerShell | C# | SQL | Index | Tools | Download | What's New |
CleanCode Perl Libraries | Copyright © 2001-2013 Michael Sorens - Revised 2013.06.30 |