Skip Menu |

This queue is for tickets about the Data-FormValidator CPAN distribution.

Maintainer(s)' notes

This is the bug queue for Data::FormValidator.

Report information
The Basics
Id: 25873
Status: resolved
Priority: 0/
Queue: Data-FormValidator

People
Owner: Nobody in particular
Requestors: dmo+pause [...] dmo.ca
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 4.50
Fixed in: (no value)



Subject: Make Data::FormValidator not complain when used with UNIVERSAL::can [PATCH]
If using D::FV with modules that use UNIVERSAL::can(), you end up with warning output liberally sprinkled with: Called UNIVERSAL::can() as a function, not a method at /usr/local/share/perl/5.8.4/Data/FormValidator/Results.pm line 1046 The attached patch fixes these warnings by using Scalar::Util::blessed() to check for object-ness, then calling ->can() on the object, as recommended by the UNIVERSAL::can() docs.
Subject: data-formvalidator-with-universal-can.diff
diff -r -u Data-FormValidator-4.50/Build.PL Data-FormValidator-4.50_01/Build.PL --- Data-FormValidator-4.50/Build.PL 2006-12-04 21:38:14.000000000 -0500 +++ Data-FormValidator-4.50_01/Build.PL 2007-03-27 11:06:37.000000000 -0400 @@ -40,7 +40,8 @@ 'File::MMagic' => 1.17, 'MIME::Types' => 1.005, 'Regexp::Common' => 0, - 'overload' => 0, + 'Scalar::Util' => 0, + 'overload' => 0, }, )->create_build_script; diff -r -u Data-FormValidator-4.50/Makefile.PL Data-FormValidator-4.50_01/Makefile.PL --- Data-FormValidator-4.50/Makefile.PL 2006-12-04 21:38:14.000000000 -0500 +++ Data-FormValidator-4.50_01/Makefile.PL 2007-03-27 11:15:32.000000000 -0400 @@ -11,6 +11,7 @@ 'MIME::Types' => '1.005', 'Regexp::Common' => '0', 'Test::More' => '0', + 'Scalar::Util' => '0', 'overload' => '0' }, 'INSTALLDIRS' => 'site', diff -r -u Data-FormValidator-4.50/lib/Data/FormValidator/Constraints.pm Data-FormValidator-4.50_01/lib/Data/FormValidator/Constraints.pm --- Data-FormValidator-4.50/lib/Data/FormValidator/Constraints.pm 2006-12-04 21:38:14.000000000 -0500 +++ Data-FormValidator-4.50_01/lib/Data/FormValidator/Constraints.pm 2007-03-27 11:11:37.000000000 -0400 @@ -58,9 +58,9 @@ sub $func { return sub { my \$dfv = shift; - use UNIVERSAL qw( can ) ; - can(\$dfv, "name_this") - || die "first arg to $func was not an object. Must be called as a constraint_method."; + use Scalar::Util (); + die "first arg to $func was not an object. Must be called as a constraint_method." + unless ( Scalar::Util::blessed(\$dfv) && \$dfv->can('name_this') ); \$dfv->name_this('$func'); no strict 'refs'; diff -r -u Data-FormValidator-4.50/lib/Data/FormValidator/Results.pm Data-FormValidator-4.50_01/lib/Data/FormValidator/Results.pm --- Data-FormValidator-4.50/lib/Data/FormValidator/Results.pm 2006-12-04 21:38:14.000000000 -0500 +++ Data-FormValidator-4.50_01/lib/Data/FormValidator/Results.pm 2007-03-27 11:16:35.000000000 -0400 @@ -1040,10 +1040,11 @@ sub _get_input_as_hash { my ($self,$data) = @_; $self->{__INPUT_DATA} = $data; - require UNIVERSAL; - # This checks whether we have an object that supports param - if (UNIVERSAL::can($data,'param') ) { + require Scalar::Util; + + # This checks whether we have an object that supports param + if ( Scalar::Util::blessed($data) && $data->can('param') ) { my %return; foreach my $k ($data->param()){ # we expect param to return an array if there are multiple values
Subject: Re: [rt.cpan.org #25873] Make Data::FormValidator not complain when used with UNIVERSAL::can [PATCH]
Date: Tue, 27 Mar 2007 12:15:16 -0400
To: bug-Data-FormValidator [...] rt.cpan.org
From: Mark Stosberg <mark [...] summersault.com>
On Tue, 2007-03-27 at 11:32 -0400, David O'Neill via RT wrote: Show quoted text
> > If using D::FV with modules that use UNIVERSAL::can(), you end up with > warning output liberally sprinkled with: > > Called UNIVERSAL::can() as a function, not a method at > /usr/local/share/perl/5.8.4/Data/FormValidator/Results.pm line 1046
That's because UNIVERSAL::can() puts the warnings there. Removing the "-always_warn" flag from the call to UNIVERSAL::can() also fixes this. If you believe the current style is sub-optimal, I'd rather you say that. This whole business with UNIVERSAL::can() is about style advocacy. DFV works fine as it is. I could still consider changing DFV on the grounds that the proposal is better style, but it's certainly not a bug in DFV that someone else created a module that generates warnings when it doesn't need to! Mark
CC: dmo+pause [...] dmo.ca
Subject: Re: [rt.cpan.org #25873] Make Data::FormValidator not complain when used with UNIVERSAL::can [PATCH]
Date: Tue, 27 Mar 2007 12:56:57 -0400
To: "mark [...] summersault.com via RT" <bug-Data-FormValidator [...] rt.cpan.org>
From: "Dave O'Neill" <dmo [...] dmo.ca>
On Tue, Mar 27, 2007 at 12:16:13PM -0400, mark@summersault.com via RT wrote: Show quoted text
> > That's because UNIVERSAL::can() puts the warnings there. Removing the > "-always_warn" flag from the call to UNIVERSAL::can() also fixes this. >
Unfortunately, removing the flag doesn't fix it -- if warnings are enabled it will always warn, regardless of the presence or absence of the flag. Show quoted text
> I could still consider changing DFV on the grounds that the proposal is > better style, but it's certainly not a bug in DFV that someone else > created a module that generates warnings when it doesn't need to!
No, it's certainly not a bug, and definitely doesn't warrant a release of DFV by itself. However it does seem to be better style to check for blessedness first and call can() as a method. And, it doesn't seem to hurt anything to do it, so if you could slide it into the next release, I would appreciate it. Cheers, Dave
applied. to be released soon.