CGI-Application-Plugin-ValidateRM-2.5/0000700000175000001440000000000011766631576016331 5ustar fanyusersCGI-Application-Plugin-ValidateRM-2.5/t/0000700000175000001440000000000011766631576016574 5ustar fanyusersCGI-Application-Plugin-ValidateRM-2.5/t/TestApp1.pm0000755000175000001440000000344711577754100020605 0ustar fanyuserspackage TestApp1; use strict; use CGI::Application; @TestApp1::ISA = qw(CGI::Application); sub setup { my $self = shift; $self->run_modes([qw/ form_display form_process form_display_with_ref form_process_with_ref form_process_with_fif_opts /]); } # This is the run mode that will be validated. Notice that it accepts # some errors to be passed in, and on to the template system. sub form_display { my $self = shift; my $errs = shift; my $t = $self->load_tmpl('t/01_display.html', die_on_bad_params=>0); $t->param($errs) if $errs; return $t->output; } # This is another run mode that will be validated. Similar, but this one # returns a reference to the output rather than returning the output itself. sub form_display_with_ref { my $self = shift; my $errs = shift; my $t = $self->load_tmpl('t/01_display.html', die_on_bad_params=>0, ); $t->param($errs) if $errs; return \$t->output; } sub form_process { my $self = shift; use CGI::Application::Plugin::ValidateRM; my ($results, $err_page) = $self->validate_rm('form_display', '_form_profile' ); return $err_page if $err_page; return 'success'; } sub form_process_with_ref { my $self = shift; my ($results, $err_page) = $self->validate_rm('form_display_with_ref', '_form_profile' ); return $err_page if $err_page; return 'success'; } sub form_process_with_fif_opts { my $self = shift; my $results = $self->check_rm('form_display', '_form_profile', { fill_password => 0 } ) || return $self->dfv_error_page; return 'success'; } sub _form_profile { return { required => [qw/email phone/], optional => [qw/passwd/], constraints => { email => 'email', }, msgs => { any_errors => 'err__', prefix => 'err_', }, }; } CGI-Application-Plugin-ValidateRM-2.5/t/99_pod.t0000755000175000001440000000020111577754100020057 0ustar fanyusersuse Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); CGI-Application-Plugin-ValidateRM-2.5/t/01_basic.t0000755000175000001440000000277611577754100020360 0ustar fanyusersuse Test::More tests => 14; BEGIN { use_ok('CGI::Application::Plugin::ValidateRM') }; use lib './t'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestApp1; my $t1_obj = TestApp1->new(QUERY=>CGI->new("email=broken;rm=form_process")); my $t1_output = $t1_obj->run(); like($t1_output, qr/Some fields below/, 'err__'); like($t1_output, qr/name="email".*Invalid/, 'basic invalid'); like($t1_output,qr/name="phone".*Missing/, 'basic missing'); my $t2_obj = TestApp1->new(QUERY=>CGI->new("email=broken;rm=form_process_with_ref")); my $t2_output = $t2_obj->run(); like($t2_output, qr/Some fields below/, 'err__'); like($t2_output, qr/name="email".*Invalid/, 'basic invalid'); like($t2_output,qr/name="phone".*Missing/, 'basic missing'); my $t3_obj = TestApp1->new(QUERY=>CGI->new("email=broken;passwd=anything;rm=form_process_with_fif_opts")); my $t3_output = $t3_obj->run(); like($t3_output,qr/name="phone".*Missing/, 't3 basic missing'); unlike($t3_output, qr/anything/, 'passing options to HTML::FillInForm works'); { ok( $t3_obj->can('dfv_results'), "has dfv_results method" ); ok( $t3_obj->can('dfv_error_page'), "has dfv_error_page method" ); ok( $t3_obj->can('check_rm_error_page'), "has check_rm_error_page method" ); ok( defined $t3_obj->dfv_results->invalid('email'), "content of DFV method is as expected" ); } { my $valid = $t3_obj->check_rm('form_display', '_form_profile', ); ok($valid->can('invalid'), "calling check_rm in scalar context returns just the DFV obj."); } CGI-Application-Plugin-ValidateRM-2.5/t/fif_class.t0000644000175000001440000000101211765154550020705 0ustar fanyusersuse Test::More tests => 3; BEGIN { use_ok('CGI::Application::Plugin::ValidateRM') }; use lib './t'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestApp1; my $app = TestApp1->new(QUERY=>CGI->new("email=broken;rm=form_process")); my $output = $app->run(); unlike($output, qr/Filler Up/); $app->param(dfv_fif_class => 'TestFormFiller'); $output = $app->run(); like($output, qr/Filler Up/); exit(0); package TestFormFiller; use strict; use warnings; sub new { bless {}, $_[0] } sub fill { "Filler Up!" } 1; CGI-Application-Plugin-ValidateRM-2.5/t/forward.t0000644000175000001440000000416511577754100020432 0ustar fanyusersuse Test::More 'no_plan'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; { package MyForward::Test; use base 'CGI::Application'; use CGI::Application::Plugin::ValidateRM; use Test::More; sub setup { my $self = shift; $self->start_mode('legacy_process'); $self->run_modes([qw/legacy_process legacy_form/]); } sub legacy_form { my $self = shift; ok( (not exists $INC{'CGI/Application/Plugin/Forward.pm'}) , "reality check: Forward plugin is not loaded yet."); is($self->get_current_runmode , 'legacy_process' , "if ::Forward is not loaded, current_rm is not updated"); $self->header_type('none'); return "legacy form output"; } sub legacy_process { my $self = shift; my ($results, $err_page) = $self->check_rm('legacy_form', { required => 'fail' }); return $err_page if $err_page; return 'legacy process completed'; } my $app = MyForward::Test->new(); my $out = $app->run(); is($out, 'legacy form output', "form is returned"); } SKIP: { package MyForward::TestForward; use base 'CGI::Application'; use CGI::Application::Plugin::ValidateRM; use Test::More; eval { require CGI::Application::Plugin::Forward; }; if ($@) { skip "CGI::Application::Plugin::Forward required", 2; } sub setup { my $self = shift; $self->start_mode('forward_process'); $self->run_modes([qw/forward_process forward_form/]); } sub forward_form { my $self = shift; is($self->get_current_runmode, 'forward_form', "if ::Forward is loaded, current_rm is updated"); $self->header_type('none'); return "forward form output"; } sub forward_process { my $self = shift; my ($results, $err_page) = $self->check_rm('forward_form', { required => 'fail' }); return $err_page if $err_page; } my $app = MyForward::TestForward->new; my $out = $app->run; is($out, 'forward form output', "form is returned"); } CGI-Application-Plugin-ValidateRM-2.5/t/01_display.html0000755000175000001440000000047011577754100021432 0ustar fanyusers

Some fields below are missing or invalid




CGI-Application-Plugin-ValidateRM-2.5/t/fif_defaults.t0000644000175000001440000000065711765154550021425 0ustar fanyusersuse Test::More tests => 3; BEGIN { use_ok('CGI::Application::Plugin::ValidateRM') }; use lib './t'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestApp1; my $app = TestApp1->new(QUERY=>CGI->new("email=broken;rm=form_process")); my $output = $app->run(); like($output, qr/value="broken"/); $app->param(dfv_fif_defaults => { ignore_fields => ['email'] }); $output = $app->run(); unlike($output, qr/value="broken"/); CGI-Application-Plugin-ValidateRM-2.5/Changes0000755000175000001440000000660611765154550017640 0ustar fanyusersRevision history for Perl extension CGI::Application::Plugin::ValidateRM. 2.5 June 10th, 2012 New features, thanks to Michael Peters (RT#46258): - Support for using an alternative HTML::FillInForm class via param dfv_fif_class. - Support for supplying defaults for HTML::FillInForm->fill via param dfv_fif_defaults. 2.4 July 20th, 2011 No functional changes. Fixed Perl 5.12 compatibility, thanks to Nicholas Bamber. (RT#67894) Also, some other code-cleanup. 2.3 Wed Oct 22 23:05:29 EDT 2008 - Fix broken test in t/forward.t (#35056) No code changes. 2.2 Tue Apr 29 10:44:57 EDT 2008 - Fix test failure by requiring at least HTML::FillInForm 1.07 (RT#35056) No code changes. 2.1 Sun Jul 31 21:17:23 EST 2005 - Added experimental support for ::Forward; 2.00 Tue Jul 19 22:01:35 EST 2005 - Added new syntax for calling check_rm() in scalar context, returning just the $result object. - Added accessor method for the error page, named check_rm_error_page() and aliased as dfv_error_page(). - Added dfv_results() accessor method, primarily of interest to other plug-in authors. - Switched back to exporting by default, but you can still explicitly import if you want to. 1.22 Sun Nov 28 22:24:03 EST 2004 (No code changes) - Update SIGNATURE to use key that hopefully works. 1.21 Mon Sep 6 09:01:30 EST 2004 - Added example of using dfv_defaults 1.20 ?? - renamed from ::ValidateRM to ::Plugin::ValidateRM - changed export policy to not export by default. 1.12 Sat May 08 2004 - Options can now be passed through to HTML::FillInForm (Gabor Szabo) - tests cleaned up to be more sensible 1.11 Thu Feb 26 2004 - Document appropriate support mailing list 1.10 Mon Dec 01 2003 - CGI::Carp is no longer used. (Steve Hay) - Module::Build is no longer required for installation - support has been added for returning scalar refs from the run mode being validated. (Steve Hay) - use of eval / die has been minimized a bit. (Steve Hay) 1.07 Wed Oct 15 2003 - Documentation improvements (William McKee) 1.06 Fri Aug 01 2003 - Syntax fix to work with Perl 5.005. (Fred Kleindenst) 1.05 Sun Jun 22 2003 - Improved examples in documentation (Mike Fragassi) No functionality changes. 1.04 Tue May 27 2003 - Fixed Build.PL syntax problem (Mike Fragassi) 1.03 Sun May 11 2003 - Added check_rm, which returns the results as a Data::FormValidator::Results object. - New Feature: Support for supplying defaults to the Data::FormValidator new() constructor by using the 'dfv_defaults' parameter. - New Feature: The profile can now be provided as the name of a CGI::Application method which returns the appropriate hash reference. - Also note that non-backwards compatible changes were made to D::FV's msgs interface. Although it doesn't affect the interface of this module, non-backwards compatible changes were made to accomodate it. 1.00 Sun Apr 20 - New Feature: added support for Data::FormValidator's new custom error message facility. This version is /not/ backwards compatible. Some has the functionality of this module is now available in Data::FormValidator. 0.02 Sat Apr 12 - Bug Fix: options passed through vrm param weren't being respected (Neil Mansilla) 0.01 Sat Mar 29 07:46:31 2003 - original version; created by h2xs 1.19 CGI-Application-Plugin-ValidateRM-2.5/MANIFEST.SKIP0000755000175000001440000000056611577754100020240 0ustar fanyusers# This is a list of regular expressions of files to skip when rebuilding # the MANIFEST file. See the documention for the ExtUtils::Manifest module for more detail. -mls \bCVS\b ^MANIFEST\.bak$ ^Makefile$ ~$ \.old$ \.bak$ ^blib/ ^pm_to_blib$ ^MakeMaker-\d .tar.gz$ ^notes ^releases \.tgz$ \.tmp$ \.swp$ \.swm$ \.swn$ \.swo$ \.patch$ \.orig$ \.diff$ _darcs _build ^Build$ CGI-Application-Plugin-ValidateRM-2.5/Makefile.PL0000644000175000001440000000110311577754100020275 0ustar fanyusers# Note: this file was auto-generated by Module::Build::Compat version 0.340201 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'CGI::Application::Plugin::ValidateRM', 'VERSION_FROM' => 'lib/CGI/Application/Plugin/ValidateRM.pm', 'PREREQ_PM' => { 'CGI::Application' => '3', 'Data::FormValidator' => '3.7', 'HTML::FillInForm' => '1.07' }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {} ) ; CGI-Application-Plugin-ValidateRM-2.5/META.yml0000600000175000001440000000101111766631576017575 0ustar fanyusers--- abstract: unknown author: - unknown build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.6302, CPAN::Meta::Converter version 2.120921' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: CGI-Application-Plugin-ValidateRM no_index: directory: - t - inc requires: CGI::Application: 3 Data::FormValidator: 3.7 HTML::FillInForm: 1.07 version: 2.5 CGI-Application-Plugin-ValidateRM-2.5/Build.PL0000755000175000001440000000116411577754100017631 0ustar fanyusersuse Module::Build; my $class = Module::Build->subclass( class => 'My::Builder', code => q{ sub ACTION_dist { my $self = shift; `perldoc -t lib/CGI/Application/Plugin/ValidateRM.pm>README`; $self->SUPER::ACTION_dist; } }, ); $class->new( module_name => 'CGI::Application::Plugin::ValidateRM', license => 'perl', requires => { 'CGI::Application' => 3.0, 'Data::FormValidator' => 3.70, # for boolean overloading. 'HTML::FillInForm' => 1.07, # Fixes test-suite failure }, create_makefile_pl => 'traditional', sign=>0, )->create_build_script; CGI-Application-Plugin-ValidateRM-2.5/META.json0000600000175000001440000000165711766631576017765 0ustar fanyusers{ "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.6302, CPAN::Meta::Converter version 2.120921", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "CGI-Application-Plugin-ValidateRM", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "CGI::Application" : "3", "Data::FormValidator" : "3.7", "HTML::FillInForm" : "1.07" } } }, "release_status" : "stable", "version" : "2.5" } CGI-Application-Plugin-ValidateRM-2.5/README0000644000175000001440000002315011765157114017212 0ustar fanyusersNAME CGI::Application::Plugin::ValidateRM - Help validate CGI::Application run modes using Data::FormValidator SYNOPSIS use CGI::Application::Plugin::ValidateRM; my $results = $self->check_rm('form_display','_form_profile') || return $self->check_rm_error_page; # Optionally, you can pass additional options to HTML::FillInForm->fill() my $results = $self->check_rm('form_display','_form_profile', { fill_password => 0 }) || return $self->check_rm_error_page; DESCRIPTION CGI::Application::Plugin::ValidateRM helps to validate web forms when using the CGI::Application framework and the Data::FormValidator module. check_rm() Validates a form displayed in a run mode with a "Data::FormValidator" profile, returning the results and possibly an a version of the form page with errors marked on the page. In scalar context, it returns simply the Data::FormValidator::Results object which conveniently evaluates to false in a boolean context if there were any missing or invalide fields. This is the recommended calling convention. In list context, it returns the results object followed by the error page, if any. This was the previous recommended syntax, and was used like this: my ($results,$err_page) = $self->check_rm('form_display','_form_profile'); return $err_page if $err_page; The inputs are as follows: Return run mode This run mode will be used to generate an error page, with the form re-filled (using HTML::FillInForm) and error messages in the form. This page will be returned as a second output parameter. The errors will be passed in as a hash reference, which can then be handed to a templating system for display. Following the above example, the form_display() routine might look like: sub form_display { my $self = shift; my $errs = shift; # <-- prepared for form reloading my $t = $self->load_tmpl('form_display.html'); $t->param($errs) if $errs; # <-- Also necessary. # ... } The fields should be prepared using Data::FormValidator's built-in support for returning error messages as a hash reference. See the documentation for "msgs" in the Data::FormValidator::Results documentation. Returning the errors with a prefix, such as "err_" is recommended. Using "any_errors" is also recommended to make it easy to display a general "we have some errors" message. HTML::Template users may want to pass "die_on_bad_params=>0" to the HTML::Template constructor to prevent the presence of the "err_" tokens from triggering an error when the errors are *not* being displayed. Data::FormValidator profile This can either be provided as a hash reference, or as the name of a CGI::Application method that will return such a hash reference. HTML::FillInForm options (optional) If desired, you can pass additional options to the HTML::FillInForm fill() method through a hash reference. See an example above. Additional Options To control things even more, you can set parameters in your CGI::Application object itself. dfv_defaults The value of the 'dfv_defaults' param is optionally used to pass defaults to the Data::FormValidator new() constructor. $self->param(dfv_defaults => { filters => ['trim'] }) By setting this to a hash reference of defaults in your "cgiapp_init" routine in your own super-class, you could make it easy to share some default settings for Data::FormValidator across several forms. Of course, you could also set parameter through an instance script via the PARAMS key. Here's an example that I've used: sub cgiapp_init { my $self = shift; # Set some defaults for DFV unless they already exist. $self->param('dfv_defaults') || $self->param('dfv_defaults', { missing_optional_valid => 1, filters => 'trim', msgs => { any_errors => 'err__', prefix => 'err_', invalid => 'Invalid', missing => 'Missing', format => '%s', }, }); } Now all my applications that inherit from a super class with this "cgiapp_init()" routine and have these defaults, so I don't have to add them to every profile. dfv_fif_class By default this plugin uses HTML::FillInForm to fill in the forms on the error pages with the given values. This option let's you change that so it uses an HTML::FillInForm compatible class (like a subclass) to do the same work. $self->param(dfv_fif_class => 'HTML::FillInForm::SuperDuper'); dfv_fif_defaults The value of the 'dfv_fif_defaults' param is optionally used to pass defaults to the HTML::FillInForm "fill()" method. $self->param(dfv_fif_defaults => {ignore_fields => ['rm']}) By setting this to a hash reference of defaults in your "cgiapp_init" routine in your own super-class, you could make it easy to share some default settings for HTML::FillInForm across several forms. Of course, you could also set parameter through an instance script via the PARAMS key. CGI::Application::Plugin::Forward support Experimental support has been added for CGI::Application::Plugin::Forward, which keeps the current run mode up to date. This would be useful if you were automatically generating a template name based on the run mode name, and you wanted this to work with the form run mode used with ::ValidateRM. If we detect that ::Forward is loaded, we will set the current run mode name to be accurate while the error page is being generated, and then set it back to the previous value afterwards. There is a caveat: This currently only works when the run name name is the same as the subroutine name for the form page. If they differ, the current run mode name inside of the form page will be inaccurate. If this is a problem for you, get in touch to discuss a solution. check_rm_error_page() After check_rm() is called this accessor method can be used to retrieve the error page described in the check_rm() docs above. The method has an alias named "dfv_error_page()" if you find that more intuitive. dfv_results() $self->dfv_results; After "check_rm()" or "validate_rm()" has been called, the DFV results object can also be accessed through this method. I expect this to be most useful to other plugin authors. validate_rm() Works like "check_rm" above, but returns the old style $valid hash reference instead of the results object. It's no longer recommended, but still supported. EXAMPLE In a CGI::Application module: # This is the run mode that will be validated. Notice that it accepts # some errors to be passed in, and on to the template system. sub form_display { my $self = shift; my $errs = shift; my $t = $self->load_tmpl('page.html'); $t->param($errs) if $errs; return $t->output; } sub form_process { my $self = shift; use CGI::Application::Plugin::ValidateRM (qw/check_rm/); my ($results, $err_page) = $self->check_rm('form_display','_form_profile'); return $err_page if $err_page; #.. do something with DFV $results object now my $t = $self->load_tmpl('success.html'); return $t->output; } sub _form_profile { return { required => 'email', msgs => { any_errors => 'some_errors', prefix => 'err_', }, }; } In page.html:

Some fields below are missing or invalid

SEE ALSO CGI::Application, Data::FormValidator, HTML::FillInForm, perl(1) AUTHOR Mark Stosberg MAILING LIST If you have any questions, comments, bug reports or feature suggestions, post them to the support mailing list! This the Data::FormValidator list. To join the mailing list, visit LICENSE Copyright (C) 2003-2005 Mark Stosberg This module is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details. For a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA CGI-Application-Plugin-ValidateRM-2.5/lib/0000700000175000001440000000000011766631576017077 5ustar fanyusersCGI-Application-Plugin-ValidateRM-2.5/lib/CGI/0000700000175000001440000000000011766631576017501 5ustar fanyusersCGI-Application-Plugin-ValidateRM-2.5/lib/CGI/Application/0000700000175000001440000000000011766631576021744 5ustar fanyusersCGI-Application-Plugin-ValidateRM-2.5/lib/CGI/Application/Plugin/0000700000175000001440000000000011766631576023202 5ustar fanyusersCGI-Application-Plugin-ValidateRM-2.5/lib/CGI/Application/Plugin/ValidateRM.pm0000755000175000001440000002752511765154550025547 0ustar fanyuserspackage CGI::Application::Plugin::ValidateRM; use base ('Exporter','AutoLoader'); use HTML::FillInForm; use Data::FormValidator; use strict; our @EXPORT = qw( &dfv_results &dfv_error_page &check_rm_error_page &check_rm &validate_rm ); our $VERSION = '2.5'; sub check_rm { my $self = shift; my $return_rm = shift || die 'missing required return run mode'; my $profile_in = shift || die 'missing required profile'; my $fif_params = shift || {}; # If the profile is not a hash reference, # assume it's a CGI::App method my $profile; if (ref $profile_in eq 'HASH') { $profile = $profile_in; } else { if ($self->can($profile_in)) { $profile = $self->$profile_in(); } else { $profile = eval { $self->$profile_in() }; die "Error running profile method '$profile_in': $@" if $@; } } require Data::FormValidator; my $dfv = Data::FormValidator->new({}, $self->param('dfv_defaults') ); my $r =$dfv->check($self->query,$profile); $self->{'__DFV_RESULT'} = $r; # Pass the params through the object so the user # can just call dfv_error_page() later $self->{'__DFV_RETURN_RM'} = $return_rm; $self->{'__DFV_FIF_PARAMS'} = $fif_params; if (wantarray) { # We have to call the function non-traditionally to achieve mix-in happiness. return $r, dfv_error_page($self); } else { return $r; } } sub dfv_results { my $self = shift; die "must call check_rm() or validate_rm() first." unless defined $self->{'__DFV_RESULT'}; return $self->{'__DFV_RESULT'}; } sub validate_rm { my $self = shift; my ($r,$err_page) = $self->check_rm(@_); return (scalar $r->valid,$err_page); } sub dfv_error_page { my $self = shift; my $r = $self->{'__DFV_RESULT'}; my $return_rm = $self->{'__DFV_RETURN_RM'}; my $fif_params = $self->param('dfv_fif_defaults') || {}; # merge the defaults with the ones given for this fill $fif_params = {%$fif_params, %{$self->{'__DFV_FIF_PARAMS'}}}; my $err_page = undef; if ($r->has_missing or $r->has_invalid) { # If ::Forward has been loaded, act like forward() my $before_rm = $self->{__CURRENT_RUNMODE}; $self->{__CURRENT_RUNMODE} = $return_rm if ($INC{'CGI/Application/Plugin/Forward.pm'}); my $return_page = $self->$return_rm($r->msgs); $self->{__CURRENT_RUNMODE} = $before_rm; my $return_pageref = (ref($return_page) eq 'SCALAR') ? $return_page : \$return_page; my $fif_class = $self->param('dfv_fif_class') || 'HTML::FillInForm'; eval "require $fif_class"; # Deliberately do _not_ check if the eval succeeded, # since $fif_class might be an inlined class not to be found in @INC. my $fif = $fif_class->new(); $err_page = $fif->fill( scalarref => $return_pageref, fobject => $self->query, %$fif_params, ); } return $err_page; } *check_rm_error_page = \&dfv_error_page; my $avoid_warning = \&check_rm_error_page; 1; __END__ =head1 NAME CGI::Application::Plugin::ValidateRM - Help validate CGI::Application run modes using Data::FormValidator =head1 SYNOPSIS use CGI::Application::Plugin::ValidateRM; my $results = $self->check_rm('form_display','_form_profile') || return $self->check_rm_error_page; # Optionally, you can pass additional options to HTML::FillInForm->fill() my $results = $self->check_rm('form_display','_form_profile', { fill_password => 0 }) || return $self->check_rm_error_page; =head1 DESCRIPTION CGI::Application::Plugin::ValidateRM helps to validate web forms when using the CGI::Application framework and the Data::FormValidator module. =head2 check_rm() Validates a form displayed in a run mode with a C profile, returning the results and possibly an a version of the form page with errors marked on the page. In scalar context, it returns simply the Data::FormValidator::Results object which conveniently evaluates to false in a boolean context if there were any missing or invalide fields. This is the recommended calling convention. In list context, it returns the results object followed by the error page, if any. This was the previous recommended syntax, and was used like this: my ($results,$err_page) = $self->check_rm('form_display','_form_profile'); return $err_page if $err_page; The inputs are as follows: =over =item Return run mode This run mode will be used to generate an error page, with the form re-filled (using L) and error messages in the form. This page will be returned as a second output parameter. The errors will be passed in as a hash reference, which can then be handed to a templating system for display. Following the above example, the form_display() routine might look like: sub form_display { my $self = shift; my $errs = shift; # <-- prepared for form reloading my $t = $self->load_tmpl('form_display.html'); $t->param($errs) if $errs; # <-- Also necessary. # ... } The fields should be prepared using Data::FormValidator's built-in support for returning error messages as a hash reference. See the documentation for C in the L documentation. Returning the errors with a prefix, such as "err_" is recommended. Using C is also recommended to make it easy to display a general "we have some errors" message. HTML::Template users may want to pass C0> to the HTML::Template constructor to prevent the presence of the "err_" tokens from triggering an error when the errors are I being displayed. =item Data::FormValidator profile This can either be provided as a hash reference, or as the name of a CGI::Application method that will return such a hash reference. =item HTML::FillInForm options (optional) If desired, you can pass additional options to the L L method through a hash reference. See an example above. =back =head3 Additional Options To control things even more, you can set parameters in your L object itself. =over =item dfv_defaults The value of the 'dfv_defaults' param is optionally used to pass defaults to the L L constructor. $self->param(dfv_defaults => { filters => ['trim'] }) By setting this to a hash reference of defaults in your C routine in your own super-class, you could make it easy to share some default settings for Data::FormValidator across several forms. Of course, you could also set parameter through an instance script via the PARAMS key. Here's an example that I've used: sub cgiapp_init { my $self = shift; # Set some defaults for DFV unless they already exist. $self->param('dfv_defaults') || $self->param('dfv_defaults', { missing_optional_valid => 1, filters => 'trim', msgs => { any_errors => 'err__', prefix => 'err_', invalid => 'Invalid', missing => 'Missing', format => '%s', }, }); } Now all my applications that inherit from a super class with this C routine and have these defaults, so I don't have to add them to every profile. =item dfv_fif_class By default this plugin uses L to fill in the forms on the error pages with the given values. This option let's you change that so it uses an L compatible class (like a subclass) to do the same work. $self->param(dfv_fif_class => 'HTML::FillInForm::SuperDuper'); =item dfv_fif_defaults The value of the 'dfv_fif_defaults' param is optionally used to pass defaults to the L C method. $self->param(dfv_fif_defaults => {ignore_fields => ['rm']}) By setting this to a hash reference of defaults in your C routine in your own super-class, you could make it easy to share some default settings for L across several forms. Of course, you could also set parameter through an instance script via the PARAMS key. =back =head2 CGI::Application::Plugin::Forward support Experimental support has been added for CGI::Application::Plugin::Forward, which keeps the current run mode up to date. This would be useful if you were automatically generating a template name based on the run mode name, and you wanted this to work with the form run mode used with ::ValidateRM. If we detect that ::Forward is loaded, we will set the current run mode name to be accurate while the error page is being generated, and then set it back to the previous value afterwards. There is a caveat: This currently only works when the run name name is the same as the subroutine name for the form page. If they differ, the current run mode name inside of the form page will be inaccurate. If this is a problem for you, get in touch to discuss a solution. =head2 check_rm_error_page() After check_rm() is called this accessor method can be used to retrieve the error page described in the check_rm() docs above. The method has an alias named C if you find that more intuitive. =head2 dfv_results() $self->dfv_results; After C or C has been called, the DFV results object can also be accessed through this method. I expect this to be most useful to other plugin authors. =head2 validate_rm() Works like C above, but returns the old style C<$valid> hash reference instead of the results object. It's no longer recommended, but still supported. =head1 EXAMPLE In a CGI::Application module: # This is the run mode that will be validated. Notice that it accepts # some errors to be passed in, and on to the template system. sub form_display { my $self = shift; my $errs = shift; my $t = $self->load_tmpl('page.html'); $t->param($errs) if $errs; return $t->output; } sub form_process { my $self = shift; use CGI::Application::Plugin::ValidateRM (qw/check_rm/); my ($results, $err_page) = $self->check_rm('form_display','_form_profile'); return $err_page if $err_page; #.. do something with DFV $results object now my $t = $self->load_tmpl('success.html'); return $t->output; } sub _form_profile { return { required => 'email', msgs => { any_errors => 'some_errors', prefix => 'err_', }, }; } In page.html:

Some fields below are missing or invalid

=head1 SEE ALSO L, L, L, perl(1) =head1 AUTHOR Mark Stosberg =head1 MAILING LIST If you have any questions, comments, bug reports or feature suggestions, post them to the support mailing list! This the Data::FormValidator list. To join the mailing list, visit L =head1 LICENSE Copyright (C) 2003-2005 Mark Stosberg This module is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details. For a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA =cut CGI-Application-Plugin-ValidateRM-2.5/MANIFEST0000644000175000001440000000047111766631576017476 0ustar fanyusersBuild.PL Changes MANIFEST This list of files MANIFEST.SKIP META.yml Makefile.PL README lib/CGI/Application/Plugin/ValidateRM.pm t/01_basic.t t/01_display.html t/99_pod.t t/TestApp1.pm t/forward.t t/fif_class.t t/fif_defaults.t META.json Module JSON meta-data (added by MakeMaker)