Skip Menu |
 

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 93203
Status: open
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: abraxxa [...] cpan.org
Cc:
AdminCc:

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



Subject: weak_ref => 1 attrs might get undef although the type constraint shouldn't allow it
Download (untitled) / with headers
text/plain 1.5k
short discussion in #moose: (16:01:25) abraxxa: i experienced a strange attribute behavior I can't explain (16:01:49) abraxxa: https://metacpan.org/source/GSHANK/HTML-FormHandler-0.40056/lib/HTML/FormHandler/Field.pm#L35 (16:02:47) abraxxa: has_result returns false, a call to result->method immediately afterwards die's with "can't call method on undefined value" (16:03:02) abraxxa: gshank thinks that because it's a weak ref it gets garbage collected (16:04:35) ilmari_: that would cause it to become undef, yes (16:04:44) ilmari_: if nothing else has a reference to the result object (16:06:51) abraxxa: so you can't rely on Moose' type validation as soon as the attr is a weak ref? (16:07:34) ilmari_: you can't rely on any weak reference to stay defined (16:07:51) ilmari_: moose doesn't get told when it disappears (16:07:58) ilmari_: and what would it do if it did? (16:36:53) abraxxa: ilmari_: what do you suggest how to handle it? (16:37:21) abraxxa: i'd not let Moose create the has_result method but write one instead which checks for exists AND defined (16:37:22) ilmari_: abraxxa: not using has, just my $result = $field->result or return; (16:38:42) abraxxa: what about adding a warning when a Moose accessor has a predicate set and week_ref => 1? Can we improve this situation by at least documenting it and/or warn when such attribute definitions are detected? Personally I'd like if Moose didn't allow to define a predicate for weak_ref attributes or a different return value from the predicate method in case the type doesn't allow undef.
Subject: Re: [rt.cpan.org #93203] weak_ref => 1 attrs might get undef although the type constraint shouldn't allow it
Date: Sat, 22 Feb 2014 14:17:52 -0800
To: Alexander Hartmaier via RT <bug-Moose [...] rt.cpan.org>
From: Karen Etheridge <ether [...] cpan.org>
Download (untitled) / with headers
text/plain 495b
On Thu, Feb 20, 2014 at 01:15:01PM -0500, Alexander Hartmaier via RT wrote: Show quoted text
> Personally I'd like if Moose didn't allow to define a predicate for weak_ref attributes or a different return value from the predicate method in case the type doesn't allow undef.
I think it would be reasonable for the predicate to return true if the object was collected. As the predicate is supposed to respond to the question "is the slot initialized", if the slot no longer contains a value, that answer is no.


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.