Add safety to test scripts for File::HomeDir applications

Alias on 2010-05-23T23:58:26

I always feel a bit depressed when I go on a long geek/coding trip and don't come back having released something.

Since my work is slowly drifting more towards architecture and strategy where I do less coding than I used to, writing something this trip has been tough.

Fortunately, with a few hours to kill at Seattle airport I've managed to knock out File::HomeDir::Test, which is a way to test applications that use File::HomeDir safely and without spewing files into places that the installed application will discover later.

The pattern in your application is just the following...

use File::HomeDir::Test;
use File::HomeDir;


The first line creates a temporary directory that lives for the duration of the test scripts, ads hijacking flags for the base File::HomeDir load, and hijacks $ENV{HOME} to point to the temp directory.

After you have loaded File::HomeDir::Test (in a way that results in ->import being called) File::HomeDir should just work as normal.

It has been released as File::HomeDir 0.91. This release also sees the landing of the FreeDesktop.org driver in a production release for the first time, so please report any problems you may see on Linux.


Pragma? Monkey patching?

jjore on 2010-05-24T03:17:24

Hi, this API is lacking. You're modifying state and expecting it to get used elsewhere and maybe it or maybe it won't or maybe something else now will fall over because things are possibly "strange."

Further, there's little reason for a user to think that loading something that looks like a class isn't going to be the normal sort of idempotent action we normally expect "Yes please, this I require that class X be loaded".

Quite sure this use of use() ought to look unlike a regular class-loading use of use(). Or the class loading could load HomeDir but replace it's environmental db with something custom?

Perhaps something like:

sub import {
    $File::HomeDir::ENV = {
        %main::ENV,
        HOME => ...
    };
}