Functions Shouldn't be Methods, Yet Another Reminder

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.

Modern Perl: The Book

cover image for Modern Perl: the book

The best Perl Programmers read Modern Perl: The Book.

sponsored by the How to Make a Smoothie guide

Categories

Pages

About this Entry

This page contains a single entry by chromatic published on September 24, 2013 6:00 AM.

Aliasing Short Names for Constructors was the previous entry in this blog.

Automation Paralysis and False Laziness is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.


Powered by the Perl programming language

what is programming?