This queue is for tickets about the CGI-Application-Plugin-ValidateRM CPAN distribution.

Report information
The Basics
Id:
46258
Status:
resolved
Worked:
40 minutes
Users:
WONKO: 40 minutes
Priority:
Low/Low

People
Owner:
MARKSTOS [...] cpan.org
Requestors:
FANY [...] cpan.org
wonko [...] cpan.org
Cc:
AdminCc:



I have a situation where I need to sub-class HTML::FillInForm for some customizations. This means that I can't use CGI::Application::Plugin::ValidateRM because I can't tell it to use an HTML::FillInForm compatible module. Would you accept this feature? The attached patch uses the $self->{__DFV_FIF_CLASS} currently to override this, but if you can think of a cleaner/better place for it, I'd be happy to adjust.
Subject: override-html-fillinform.path

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #46258] alternate fill'ing classes for ValidateRM
Date: Wed, 20 May 2009 17:09:00 -0400
To: bug-CGI-Application-Plugin-ValidateRM@rt.cpan.org
From: Mark Stosberg <mark@summersault.com>
Show quoted text
> I have a situation where I need to sub-class HTML::FillInForm for some > customizations. This means that I can't use > CGI::Application::Plugin::ValidateRM because I can't tell it to use an > HTML::FillInForm compatible module. Would you accept this feature? The > attached patch uses the $self->{__DFV_FIF_CLASS} currently to override > this, but if you can think of a cleaner/better place for it, I'd be > happy to adjust.
I think I'd like this feature. I'm personally working on a Pure-Perl HTML::Parser for use with HTML::FillInForm. I think in that case, HTML::FillInForm may be modified to automatically use it. Anyway, I can appreciate the usefulness of using a compatible class. It seems like there ought to a method to set the alternate class. Would you be willing to formalize that proposal, and include documentation of the new feature? I would also ask for tests, but it seems difficult to test in automated way, but easy enough to review the changes manually. Mark
On Wed May 20 17:09:19 2009, mark@summersault.com wrote:
Show quoted text
> It seems like there ought to a method to set the alternate class.
Looking at it, I instead think it should be a $self->param() option like dfv_defaults. I'm attaching a param that allows dfv_fif_class. In addition, this patch adds dfv_fif_defaults, which is a compliment to dfv_defaults. In almost all my uses I find myself doing this every time I use it check_rm() my $results = $self->check_rm('show', $profile, {ignore_fields => ['rm']}) || return $self->check_rm_error_page(); Now instead I can put $self->param(dfv_fif_defaults => { ignore_fields => ['rm'] }) And then never have to worry about it again.
Show quoted text
> I would also ask for tests, but it seems difficult to test in > automated way, but > easy enough to review the changes manually.
It actually wasn't that hard. Tests attached.
--- lib/CGI/Application/Plugin/ValidateRM.pm.old 2008-10-22 23:06:41.000000000 -0400 +++ lib/CGI/Application/Plugin/ValidateRM.pm 2009-05-21 08:09:45.000000000 -0400 @@ -81,7 +81,10 @@ my $self = shift; my $r = $self->{'__DFV_RESULT'}; my $return_rm = $self->{'__DFV_RETURN_RM'}; - my $fif_params = $self->{'__DFV_FIF_PARAMS'}; + 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) { @@ -95,8 +98,10 @@ my $return_pageref = (ref($return_page) eq 'SCALAR') ? $return_page : \$return_page; - require HTML::FillInForm; - my $fif = new HTML::FillInForm; + + my $fif_class = $self->param('dfv_fif_class') || 'HTML::FillInForm'; + eval "require $fif_class"; + my $fif = $fif_class->new(); $err_page = $fif->fill( scalarref => $return_pageref, fobject => $self->query, @@ -194,10 +199,19 @@ =back -Additionally, the value of the 'dfv_defaults' param from the calling -object is optionally used to pass defaults to the C<new()> constructor. +=head3 Additional Options + +To control things even more, you can set parameters in your L<CGI::Application> +object itself. + +=over + +=item dfv_defaults - $self->param('dfv_defaults') +The value of the 'dfv_defaults' param is optionally used to pass defaults to the +L<Data::FormValidator> C<new()> constructor. + + $self->param(dfv_defaults => { filters => ['trim'] }) By setting this to a hash reference of defaults in your C<cgiapp_init> routine in your own super-class, you could make it easy to share some default settings for @@ -228,6 +242,29 @@ C<cgiapp_init()> 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<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 L<HTML::FillInForm> 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<HTML::FillInForm> C<fill()> method. + + $self->param(dfv_fif_defaults => {ignore_fields => ['rm']}) + +By setting this to a hash reference of defaults in your C<cgiapp_init> routine +in your own super-class, you could make it easy to share some default settings for +L<HTML::FillInForm> 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,
use 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"/);
use 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;
Subject: Re: [rt.cpan.org #46258] Override HTML::FillInForm with subclass
Date: Thu, 21 May 2009 12:16:11 -0400
To: bug-CGI-Application-Plugin-ValidateRM@rt.cpan.org
From: Mark Stosberg <mark@summersault.com>
Michael, I think I like your approach. I'll plan to review the contribution once more in a bit more detail, and then expect to apply and release it next time I have a pocket of time for OSS work. Thanks for the contribution! Mark
BTW: This could especially be useful to be able to use CGI::Application::Plugin::ValidateRM in conjunction with HTML::FillInForm::ForceUTF8. The workaround I currently use is to set „$CGI::PARAM_UTF8 = 1;“ in ->cgiapp_prerun(). Kind regards, fany
Thanks for the nudge on this. Would like to prepare a proposed release, or become a co-maintainer? I'm short on time lately, but don't want hold this up any longer. Mark
CC: wonko@cpan.org
Subject: Re: [rt.cpan.org #46258] Override HTML::FillInForm with subclass
Date: Wed, 18 Apr 2012 09:15:35 +0200
To: MARKSTOS via RT <bug-CGI-Application-Plugin-ValidateRM@rt.cpan.org>
From: "Martin H. Sluka" <fany@cpan.org>
Hi Mark,
Show quoted text
> Thanks for the nudge on this. Would like to prepare a proposed release, > or become a co-maintainer? I'm short on time lately, but don't want hold > this up any longer.
well, I have to finish the project I'm currently working on first and some other urgent things, too, but I'll try to take you up on this afterwards. What would be the correct version to start off from? The latest on CPAN? (Have not found the sources for this at https://github.com/markstos.) fany
On Wed Apr 18 03:15:54 2012, FANY wrote:
Show quoted text
> Hi Mark, >
> > Thanks for the nudge on this. Would like to prepare a proposed
release,
Show quoted text
> > or become a co-maintainer? I'm short on time lately, but don't want
hold
Show quoted text
> > this up any longer.
> > well, I have to finish the project I'm currently working on first and
some
Show quoted text
> other urgent things, too, but I'll try to take you up on this
afterwards.
Show quoted text
> > What would be the correct version to start off from? The latest on
CPAN?
Show quoted text
> (Have not found the sources for this at https://github.com/markstos.)
You can import latest CPAN release into GitHub and start from there. I don't think anything has changed in my private repo since then. (I could also give you the entire history in darcs if you'd like to start from that...) Mark
CC: wonko@cpan.org
Subject: Re: [rt.cpan.org #46258] Override HTML::FillInForm with subclass
Date: Sun, 10 Jun 2012 19:56:43 +0200
To: MARKSTOS via RT <bug-CGI-Application-Plugin-ValidateRM@rt.cpan.org>
From: "Martin H. Sluka" <fany@cpan.org>
Hi Mark, you wrote some time ago:
Show quoted text
> You can import latest CPAN release into GitHub and start from there.
So at last, here is my suggestion for the next release: https://github.com/fany/CGI-Application-Plugin-ValidateRM Disclaimer: I merely integrated Michael's work and hope that is OK. If you would still like to grant me co-maintainership, I will upload the new version to CPAN and try to fix future bugs. Kind regards, fany -- ___________________________________________ _ Martin H. Sluka \ mailto:martin@sluka.de / ASCII ribbon ( ) Breite Straße 3 \ tel +49-700-19751024 / campaign - against X D-90552 Röthenbach \-- http://unf.ug ---/ HTML email & vcards / \

Message body not shown because it is not plain text.

FANY, you have now been made a CO-MAINT. Go forth and release! Thanks for your help. ( I think this also gives you access to bug queue management, after a few hours of time delay. ) Mark
Hi Michael, you wrote May 21st 2009, 08:13:49:
Show quoted text
> It actually wasn't that hard. Tests attached.
Thanks for your patches! They are now part of version 2.5 of CGI::Application::Plugin::ValidateRM, which I just released to CPAN. Kind regards, Martin


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.