Sunday, July 5, 2009

Bootstrapping KiokuDB::Cmd

I just closed a ticket in KiokuDB's RT queue that asked for simpler dependencies. The fix was splitting the KiokuDB::Cmd modules into their own distribution, making the core more easily installable on Windows.

The problem is that I depended on Proc::InvokeEditor for the kioku edit command. Unfortunately that module does not install cleanly on Windows, preventing KiokuDB itself from installing, even though it's not required for normal use.

The problem is that KiokuDB's command line tool requires KiokuDB::Cmd to run. What I ended up doing is having the kioku script (which still ships with KiokuDB) allow bootstraping KiokuDB::Cmd by using Module::AutoInstall (if it's available and the user grants permission to do so).

If kioku can't require KiokuDB::Cmd cleanly, then it calls try_auto_install function:

sub try_auto_install {
    if (eval {
        require Module::AutoInstall;
        require ExtUtils::MakeMaker;
    }) {
        print "\n";
        if (
                "Module::AutoInstall is available. " .
                "Should I use it to install KiokuDB::Cmd?",
            ) =~ /^y/i
        ) {
            my @installed = Module::AutoInstall->install(
                "KiokuDB::Cmd" => $KiokuDB::REQUIRED_CMD_VERSION,
            return @installed > 0;


If installation seems to have succeeded then we delete $INC{"KiokuDB/"} and try to load it again.

Otherwise the script exits with an error asking the user to install KiokuDB::Cmd manually.

I think this is a fair tradeoff, especially if you don't need the command line tools in production deployments (you can still make backups by programmatically scanning the database yourself).

No comments: