|Subject:||weak_ref => 1 attrs might get undef although the type constraint shouldn't allow it|
short discussion in #moose: (16:01:25) abraxxa: i experienced a strange attribute behavior I can't explain (16:01:49) abraxxa:(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.