Can you show the actual error you are seeing? I don't have MX::Declare installed so I cannot run your code.

Just looking at the code below it is obvious to me that *you* have a bug. If you wrap a method with before, then call that method from within the before it will likely go into infinite recursion. This is not a Moose bug though, it is just incorrect usage.

- Stevan

On Mar 4, 2009, at 12:12 PM, MORGUN Alexander wrote:

Hello,

I've seen a lot of bugs with before on attributes. The last one in HTML::FormBuilder :) What is the good practice to do that? Stop using before on attributes? Use direct value access? Personally, i think that lazy + default is good, but i see much people (including me) using before everywhere, because it is handy.

#!/usr/bin/perl -w
use MooseX::Declare;

class Test {
    has 'a' => (isa => 'Int', is => 'rw');

    before a {
        $self->do_calculations;
    }
    method do_calculations {
#after a lot of refactorings in some cases we check the $self->a
        $self->a;
    }
}

my $t = Test->new(a=>2);
print $t->a;




Reply via email to