Carl,
On Nov 23, 2006, at 11:29 AM, Carl Franks wrote:
I'm working on a project using Moose, with an object which uses
overloading.
I came across a situation where the subroutine for 'bool' overloading
was being unexpectedly called.
I tracked it down to Class::MOP::Attribute, line 125. If I change
this:
if ($instance && $self->is_default_a_coderef) {
to this:
if (defined $instance && $self->is_default_a_coderef) {
it fixes my problem, and the bool overload subroutine is no longer
called.
Is this a suitable fix, or does it suggest I'm using Moose attributes
in a wrong way?
No, you are likely using them just fine, the defined test should be
fine, so I have applied your change in svn HEAD. I will have to test
this against Moose as well too, but I don't expect any test failures.
The reason it was causing me a problem, was because the overload
subroutine was calling methods on $self, when construction hadn't
completed yet, and I was relying on attributes that were supposed to
be set by BUILD subs.
Moose has not been well tested with overloads (I don't use them much
anymore myself), so you may very well find some issues. If you would
be so inclined, I would love some tests which combine Moose +
overload :)
Thanks,
- Steve