Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 58907
Status: rejected
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: felixtubiana [...] gmail.com
Cc:
AdminCc:

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



Subject: Moose predicate with default
Apologies if this has already been addressed. When defining an attribute, it would be useful to emit a warning or an error when trying to use both predicate and default, as the default overrides the usefulness of the predicate function, which is probably not what the user intends. has( 'foo_param' => ( is => 'rw', isa => 'Bool', predicate => 'has_foo_param', default => 0 ) ); Felix
Subject: Re: [rt.cpan.org #58907] Moose predicate with default
Date: Mon, 28 Jun 2010 12:25:41 -0400
To: bug-Moose [...] rt.cpan.org
From: Shawn M Moore <sartak [...] gmail.com>
(6/28/10 12:24 PM), Felix Tubiana via RT wrote: Show quoted text
> Mon Jun 28 12:24:09 2010: Request 58907 was acted upon. > Transaction: Ticket created by FELIX > Queue: Moose > Subject: Moose predicate with default > Broken in: 0.92 > Severity: Wishlist > Owner: Nobody > Requestors: felixtubiana@gmail.com > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=58907 > > > > Apologies if this has already been addressed. > > When defining an attribute, it would be useful to emit a warning or an > error when trying to use both predicate and default, as the default > overrides the usefulness of the predicate function, which is probably > not what the user intends. > > has( 'foo_param' => ( is => 'rw', > isa => 'Bool', > predicate => 'has_foo_param', > default => 0 > ) > ); > > Felix
predicate, default with coderef, and lazy are useful together. It's hard and IMO not worthwhile to enumerate all the possible ways that users can have useless option combinations. Shawn
A default doesn't make this useless, you can still define a clearer for the attribute (possibly even in a subclass). The concept of a predicate is well defined even in the presence of a default.
Subject: Re: [rt.cpan.org #58907] Moose predicate with default
Date: Mon, 28 Jun 2010 11:27:24 -0500 (CDT)
To: Felix Tubiana via RT <bug-Moose [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Mon, 28 Jun 2010, Felix Tubiana via RT wrote: Show quoted text
> Mon Jun 28 12:24:09 2010: Request 58907 was acted upon. > Transaction: Ticket created by FELIX > Queue: Moose > Subject: Moose predicate with default > Broken in: 0.92 > Severity: Wishlist > Owner: Nobody > Requestors: felixtubiana@gmail.com > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=58907 > > > > Apologies if this has already been addressed. > > When defining an attribute, it would be useful to emit a warning or an > error when trying to use both predicate and default, as the default > overrides the usefulness of the predicate function, which is probably > not what the user intends. > > has( 'foo_param' => ( is => 'rw', > isa => 'Bool', > predicate => 'has_foo_param', > default => 0 > ) > );
This is a little more complicated than you might think. If the attribute has a clearer, then the predicate is still useful. Similarly, if the attribute is lazy, then the predicate is useful. Then factor in the possibility that some MooseX module will affect the logic here, and I think it's unrealistic to expect Moose to warn on this sort of thing. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/