class-mop bool test

[email protected] ("Carl Franks")
Newsgroups perl.moose
Message-ID <[email protected]>
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?

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.

Carl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.