Skip Menu |

This queue is for tickets about the Params-Validate CPAN distribution.

Report information
The Basics
Id: 103301
Status: resolved
Priority: 0/
Queue: Params-Validate

People
Owner: Nobody in particular
Requestors: Isshwarya.M [...] netapp.com
Cc:
AdminCc:

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



Subject: HASHREF type validation allows objects wrongly!
Date: Sat, 4 Apr 2015 07:13:10 +0000
To: "bug-Params-Validate [...] rt.cpan.org" <bug-Params-Validate [...] rt.cpan.org>
From: "Makudeswaran, Isshwarya" <Isshwarya.M [...] netapp.com>
Params::Validate type validation doesn't complain on object being passed for an argument whose type is declared to be hashref. I hope objects are treated differently from hashes for the very reason we have two different datatypes - HASHREF and OBJECT. Show quoted text
------ code snippet--------------- use Params::Validate qw(validate HASHREF); use Data::Dumper; sub invoke_me { my %opts = validate(@_, {arg => {type => HASHREF}}); # This doesn't complain for objects print Dumper \%opts; } my $obj = Data::Dumper->new([]); invoke_me(arg => $obj); ------------------------------------------ Perl version: This is perl 5, version 20, subversion 0 (v5.20.0) built for x86_64-linux-thread-multi Operating system: Linux <some_host> 2.6.32-504.3.3.el6.x86_64 #1 SMP Fri Dec 12 16:05:43 EST 2014 x86_64 x86_64 x86_64 GNU/Linux Module version: 1.07 The test used XS backend. But I see the same problem with PP variation too (by setting PV_TEST_PERL=1 in ENV) Thanks, Isshwarya
In an ideal world I'd fix this, but unfortunately in our world I think maintaining backwards compatibility is more important. I'm sure someone's code out there would break if the various *REF type checks started rejecting objects. There are a lot of ways to enforce this yourself, though the easiest might be to use MooseX::Params::Validate and use Moose types, which do exactly that sort of enforcement. You don't actually need to use Moose classes to use that module.
Subject: RE: [rt.cpan.org #103301] HASHREF type validation allows objects wrongly!
Date: Tue, 7 Apr 2015 12:22:28 +0000
To: "bug-Params-Validate [...] rt.cpan.org" <bug-Params-Validate [...] rt.cpan.org>
From: "Makudeswaran, Isshwarya" <Isshwarya.M [...] netapp.com>
Yes, I agree with your reasoning too. Thanks for pointing the alternative. I took a look and that seems to suffice. Feel free to close this bug. Thanks, Isshwarya Show quoted text
-----Original Message----- From: Dave Rolsky via RT [mailto:bug-Params-Validate@rt.cpan.org] Sent: Monday, April 06, 2015 10:33 PM To: Makudeswaran, Isshwarya Subject: [rt.cpan.org #103301] HASHREF type validation allows objects wrongly! <URL: https://rt.cpan.org/Ticket/Display.html?id=103301 > In an ideal world I'd fix this, but unfortunately in our world I think maintaining backwards compatibility is more important. I'm sure someone's code out there would break if the various *REF type checks started rejecting objects. There are a lot of ways to enforce this yourself, though the easiest might be to use MooseX::Params::Validate and use Moose types, which do exactly that sort of enforcement. You don't actually need to use Moose classes to use that module.