Skip Menu |
 

This queue is for tickets about the Moose CPAN distribution.

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

People
Owner: Nobody in particular
Requestors: perl [...] toby.ink
Cc:
AdminCc:

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



Subject: Please avoid calling ref() on attribute values!
Download (untitled) / with headers
text/plain 758b
I've been noodling on MooseX::Thunk which adds Data::Thunk support to Moose. One small thing that tripped me up is that the initialize_instance_slot method of Moose::Meta::Attribute includes the following code: if (ref $val && $self->is_weak_ref) { $self->_weaken_value($instance); } Calling "ref" on the value causes Data::Thunk to think about the value, and thus avoids the desired property of laziness. Simply swapping the order of the two conditions in the conjunction fixes it: if ($self->is_weak_ref && ref $val) { $self->_weaken_value($instance); } Right now I'm overriding the whole initialize_instance_slot method in my attribute trait, but that seems like overkill. So it would be nice if this could be changed in a future Moose.
Subject: Re: [rt.cpan.org #77587] Please avoid calling ref() on attribute values!
Date: Sun, 10 Jun 2012 08:37:36 -0500 (CDT)
To: Toby Inkster via RT <bug-Moose [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
Download (untitled) / with headers
text/plain 1.2k
On Fri, 1 Jun 2012, Toby Inkster via RT wrote: Show quoted text
> I've been noodling on MooseX::Thunk which adds Data::Thunk support to > Moose. One small thing that tripped me up is that the > initialize_instance_slot method of Moose::Meta::Attribute includes the > following code: > > if (ref $val && $self->is_weak_ref) { > $self->_weaken_value($instance); > } > > Calling "ref" on the value causes Data::Thunk to think about the value, > and thus avoids the desired property of laziness. Simply swapping the > order of the two conditions in the conjunction fixes it: > > if ($self->is_weak_ref && ref $val) { > $self->_weaken_value($instance); > } > > Right now I'm overriding the whole initialize_instance_slot method in > my attribute trait, but that seems like overkill. So it would be nice > if this could be changed in a future Moose.
I just don't think it's reasonable to expect Moose to never call ref on a value. Calling ref is a pretty normal thing to do in something like Moose. We might fix this one instance, but are we really going to ban ref($value) for all time? -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.