italdesign has asked for the wisdom of the Perl Monks concerning the following question:
Trouble is, the builder method only gets run the first time I call the attribute. Subsequent calls of the attribute seems to just use the value already stored in it. This defeats checking for existence since the attribute will always just have the default logfile name and will overwrite it freely (later in the application). I want the builder, or at least its behavior, to run whenever the attribute is called. What's the right way to do it?has 'cmd_logfile' => ( is => 'ro', isa => 'Str', required => 0, la +zy => 1, builder => '_build_cmd_logfile' ); sub _build_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; }
|
---|
Replies are listed 'Best First'. | |
---|---|
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 | |
by boftx (Deacon) on Sep 26, 2013 at 23:08 UTC | |
by tye (Sage) on Sep 27, 2013 at 01:14 UTC | |
by boftx (Deacon) on Sep 27, 2013 at 04:47 UTC | |
by tye (Sage) on Sep 27, 2013 at 06:04 UTC | |
| |
by Anonymous Monk on Sep 27, 2013 at 07:42 UTC |