CGI::Application::CheckRM - Checks run modes using Data::FormValidator
Included in CGI-Application-Plus 1.21 distribution.
The latest versions changes are reported in the Changes file in this distribution.
The distribution includes:
CGI::Application::Plus
CGI::Application rewriting with several pluses
CGI::Application::Magic
Template based framework for CGI applications
CGI::Application::CheckRM
Checks run modes using Data::FormValidator
Perl version >= 5.6.1 OOTools >= 1.52
perl -MCPAN -e 'install CGI::Application::Plus'
If you want to install also all the prerequisites to use CGI::Application::Magic), all in one easy step:
perl -MCPAN -e 'install Bundle::Application::Magic'
From the directory where this file is located, type:
perl Makefile.PL make make test make install
use base 'CGI::Application::CheckRM'; $s->checkRM('_form_profile') || return $s->switch_to('myOtherRunMode'); my $ERRORS = $s->dfv_resuts->msgs
This module integrates the Data::FormValidator capability with CGI::Application::Plus or with CGI::Application::Magic.
Data::FormValidator
The integration with CGI::Application::Magic is very powerful.
You need just to pass the profile to the checkRM() method and put the labels in the template: no other configuration needed on your side: the error labels in any template will be auto-magically substituted with the error string when needed.
Note: The hash reference returned by the msgs() method will be internally passed as a lookup location to the Template::Magic object.
Template::Magic
In your WebAppMagic.pm
use base 'CGI::Application::Magic'; use base 'CGI::Application::CheckRM'; sub RM_myRunMode { my $s = shift ; $s->checkRM('_form_profile') || return $s->switch_to('myOtherRunMode'); ... } # the RM_myOtherRunMode method is optional sub _form_profile { return { required => 'email', msgs => { any_errors => 'some_errors', prefix => 'err_', }, }; }
Somewhere in the 'myOtherRunMode.html' template (or in any other template) all the label prefixed with 'err_' will be substitute with the relative error if present (with the _form_profile in the example it happens just with 'err_email'):
<!--{err_email}-->
use base 'CGI::Application::Magic'; use base 'CGI::Application::CheckRM'; sub RM_myRunMode { my $s = shift ; $s->checkRM('_form_profile') || return $s->switch_to('myOtherRunMode'); ... } # the RM_myOtherRunMode method is optional sub _form_profile { return { required => 'email', msgs => { any_errors => 'some_errors', prefix => 'err_', }, }; } package WebAppMagic::Lookups; sub MISSING { my $s = shift ; my $missing if ( $s->dfv_resuts->has_missing ) { foreach my $f ( $s->dfv_resuts->missing ) { $missing .= $f, " is missing\n"; } } $missing }
Somewhere in the 'myOtherRunMode.html' template (or in any other template) all the 'MISSING' labels will be substitute with the relative error if present:
<!--{MISSING}-->
You can use this module with CGI::Application::Plus, but you will have to handle the errors in the runmethod:
In your WebAppPlus.pm
use base 'CGI::Application::Plus'; use base 'CGI::Application::CheckRM'; sub RM_myRunMode { my $s = shift ; $s->checkRM('_form_profile') || return $s->switch_to('myOtherRunMode'); ... } sub RM_myOtherRunMode { my $s = shift; my $ERRORS = $s->dfv_resuts->msgs ; # classical way # or do something else with the result object if ( $s->dfv_resuts->has_missing ) { foreach my $f ( $s->dfv_resuts->missing ) { $ERRORS .= $f, " is missing\n"; } } ... do_something_useful ... } sub _form_profile { return { required => 'email', msgs => { any_errors => 'some_errors', prefix => 'err_', }, }; }
Use this method to check the query parameters with the dfv_profile. It returns 1 on success and 0 on failure. If there are some missing or unvalid fields it set also the dfv_results property to the Data::FormValidator::Results object.
dfv_results
This module adds a couple of properties to the standard CGI::Application::Plus properties.
This group accessor handles the Data::FormValidator constructor arguments that are used in the creation of the internal Data::FormValidator object.
This property allows you to access the Data::FormValidator::Results object set by the checkRM() method only if there are some missing or invalid fields.
Data::FormValidator::Results
checkRM()
If you need support or if you want just to send me some feedback or request, please use this link: http://perl.4pro.net/?CGI::Application::CheckRM.
© 2004 by Domizio Demichelis.
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in '©'. Assuming CP1252
To install CGI::Application::Plus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::Application::Plus
CPAN shell
perl -MCPAN -e shell install CGI::Application::Plus
For more information on module installation, please visit the detailed CPAN module installation guide.