develooper Front page | perl.moose | Postings from March 2009

RFC: How to overcome potential problems with before?

Thread Next
From:
MORGUN Alexander
Date:
March 4, 2009 09:12
Subject:
RFC: How to overcome potential problems with before?
Message ID:
E1Leudc-000MfS-6m@ffe14.ukr.net
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;  
  
  
  

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About