This just cost me a few minutes of debugging:
use Moose;
use File::Temp 'tempdir';
has 'temp_dir', is => 'ro', lazy => 1, builder => '_build_temp_dir';
sub _build_temp_dir {
tempdir( CLEANUP => 1 );
}
sub do_something {
my $self = shift;
my $dir = $self->tempdir;
...
}
Yes, it's my fault for having two names in a single namespace which are too
close together and for getting too clever with directory handling (I wish there
were a chdir
that were lexically scoped), but this really
shouldn't be a problem in 2013.
Yes, it's my fault for not using something like namespace::autoclean, but this probably shouldn't be a problem in 2013.
I look forward to a world where Perl has a proper MOP and method lookup looks up only methods. In the meantime, I'm going to keep reminding myself that importing functions into classes might end in tears.