Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Moose: I want builder method to run every time I call an attribute

by chromatic (Archbishop)
on Sep 26, 2013 at 22:52 UTC ( #1055919=note: print w/ replies, xml ) Need Help??


in reply to Moose: I want builder method to run every time I call an attribute

Don't make it an attribute:

sub cmd_logfile { my $self = shift; my $inner = $self->dl_inner_dir; defined $inner or die "Error: DL_ +INNER_DIR not set."; my $b4_ext = "$inner/transfer"; my $ext = "log"; my $filename = "$b4_ext.$ext"; my $i = 2; while (-s $filename) { $filename = "$b4_ext-$i.$ext"; $i++; } return $filename; }


Comment on Re: Moose: I want builder method to run every time I call an attribute
Download Code
Re^2: Moose: I want builder method to run every time I call an attribute
by boftx (Deacon) on Sep 26, 2013 at 23:08 UTC

    I concur with chromatic. That said, if there are some other factors in play that preclude doing this, you might consider using an around statement in conjunction with the attribute reader to handle any pre-processing needed. You might not even need to have an explicit builder in that case.

    On time, cheap, compliant with final specs. Pick two.

      Two perfect examples of how Moose encourages bad OO design.

      - tye        

        tye, in all seriousness, would you expand on that (rather broad) statement? I realize this could touch off a "tastes better/less filling" discussion with regard as to what proper OO design is, but I would like to know the basis for your statement. especially since chromatic has a much better claim to knowing what he is talking about than I do in this community. :)

        On time, cheap, compliant with final specs. Pick two.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055919]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2014-12-18 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (51 votes), past polls