Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: lamoz [...] adriver.ru
Cc:
AdminCc:

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



Subject: Validation of objects with overloads
Validation of objects with overloaded 'bool' ( as well as '0+') leads to side effects. This test http://cpansearch.perl.org/src/DROLSKY/Params-Validate-0.95/t/22-overload-can-bug.t seems to address related bug. But if I change use overload 'bool' => sub {0}; to use overload 'bool' => sub {die}; then boolean conversion will be called and die, which is not what I want when validating with { isa => ...} rule. Specifically, this behavior gives me unwanted database requests when I validate DBIx::Class::ResultSet objects, which has numification defined on them.
Subject: Re: [rt.cpan.org #56049] Validation of objects with overloads
Date: Mon, 29 Mar 2010 09:00:15 -0500 (CDT)
To: "Konstantin A. Pustovalov via RT" <bug-Params-Validate [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Mon, 29 Mar 2010, Konstantin A. Pustovalov via RT wrote: Show quoted text
> Validation of objects with overloaded 'bool' ( as well as '0+') leads to > side effects.
I'm not sure I follow. Are you saying that the boolean overloading is _always_ called, or only in some circumstances? Some tests that demonstrate this more clearly would be very helpful. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
Subject: Re: [rt.cpan.org #56049] Validation of objects with overloads
Date: Mon, 29 Mar 2010 18:10:57 +0400
To: bug-Params-Validate [...] rt.cpan.org
From: "Konstantin A. Pustovalov" <lamoz [...] adriver.ru>
On 03/29/2010 06:00 PM, autarch@urth.org via RT wrote: Show quoted text
>> Validation of objects with overloaded 'bool' ( as well as '0+') leads to >> side effects. >>
> I'm not sure I follow. Are you saying that the boolean overloading is > _always_ called, or only in some circumstances? >
Always. At least when validating 'isa' Show quoted text
> Some tests that demonstrate this more clearly would be very helpful. >
The following demonstrates: <cut> use Params::Validate qw(validate); { package Overloaded; use overload 'bool' => sub {die 'Missile launch done. Earth is dead' }; sub new { bless {} } } my $ovl = Overloaded->new; my @p = ( object => $ovl ); validate( @p, { object => { isa => 'Overloaded' } } ); </cut>
Subject: Re: [rt.cpan.org #56049] Validation of objects with overloads
Date: Mon, 29 Mar 2010 09:23:03 -0500 (CDT)
To: "Konstantin A. Pustovalov via RT" <bug-Params-Validate [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Mon, 29 Mar 2010, Konstantin A. Pustovalov via RT wrote: Show quoted text
> use Params::Validate qw(validate); > > { > package Overloaded; > > use overload 'bool' => sub {die 'Missile launch done. Earth is dead' }; > > sub new { bless {} } > } > > my $ovl = Overloaded->new; > my @p = ( object => $ovl ); > validate( @p, { object => { isa => 'Overloaded' } } );
This is happening because, by default, overload will use the boolean method for stringification if no method is defined. You can control this by setting the fallback parameter, or providing an explicit stringification method. This isn't a bug in Params::Validate, and in fact this problem would occur with _any_ code that attempted to stringify the object in question. I'm going to close this bug. Please don't reply directly to this email, or you will re-open the ticket. Thanks, -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
Subject: Re: [rt.cpan.org #56049] Validation of objects with overloads
Date: Mon, 29 Mar 2010 19:08:45 +0400
To: bug-Params-Validate [...] rt.cpan.org
From: "Konstantin A. Pustovalov" <lamoz [...] adriver.ru>
On 03/29/2010 06:23 PM, autarch@urth.org via RT wrote: Show quoted text
> This isn't a bug in Params::Validate, and in fact this problem would occur > with _any_ code that attempted to stringify the object in question. >
Why is it necessary to stringify object? $obj->isa does not involve stringification. My test could be rewritten as: <cut> use Params::Validate qw(validate); { package Overloaded; use overload '""' => sub {die 'Boom!' }; sub new { bless {} } } my $ovl = Overloaded->new; my @p = ( object , $ovl ); $ovl->isa('Overloaded'); # works as expected! validate( @p, { object => { isa => 'Overloaded' } } ); # dies! </cut> Show quoted text
> I'm going to close this bug. Please don't reply directly to this email, or > you will re-open the ticket. >
Sorry for possible inconvenience.
Subject: Re: [rt.cpan.org #56049] Validation of objects with overloads
Date: Mon, 29 Mar 2010 10:14:45 -0500 (CDT)
To: "Konstantin A. Pustovalov via RT" <bug-Params-Validate [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Mon, 29 Mar 2010, Konstantin A. Pustovalov via RT wrote: Show quoted text
> Why is it necessary to stringify object? $obj->isa does not involve > stringification. My test could be rewritten as:
Stringification happens any time we try to use the object in a string. There are a _lot_ of reasons this could happen. Perl's overloading is broken and hard to use correctly, and this is a great example of that. I guarantee that Params::Validate is not the only module that will try to stringify an object. If the side effects are a problem, define an explicit stringification method without side effects. Show quoted text
> Sorry for possible inconvenience.
Please stop replying to this ticket. If you want to discuss this further, just email me directly. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/