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