My daughter and other stuff

On February 5th, my wife and I celebrated the birth of our lovely daughter, Lilly-Rose.

Needless to say, this has impacted my posting here :)

At one point before the birth when we were both rather bored, I was trying to get some work done, but I had some code which I could not load because I lacked an Internet connection. Not all modules were present on my system, config files were missing, etc. However, I desperately needed to unit test my code and I quickly got fed up with my standard bag of tricks for forcing modules to load. Thus, I wrote a module to handle that bag of tricks for me. Later, after releasing it to github, I thought about dedicating it to my wife and newborn daughter, but I didn't think they'd like the Package Butcher dedicated to them.

Still, it's handy code and it works like this:

my $butcher = Package::Butcher->new(
    {
        package     => 'Dummy',
        do_not_load => [qw/Cannot::Load Cannot::Load2 NoSuch::List::MoreUtils/],
        predeclare  => 'uniq',
        subs => {
            this     => sub { 7 },
            that     => sub { 3 },
            existing => sub { 'replaced existing' },
        },
        method_chains => [
            [
                'Cannot::Load' => qw/foo bar baz this that/ => sub {
                    my $args = join ', ' => @_;
                    return "end chain: $args";
                },
            ],
        ],
    }
);
$butcher->use(@optional_import_list);

In other words, many of the common issues which would prevent a package from loading are dealt with here. You can predeclare subs (with prototypes), prevent naughty packages from loading, handle awful method chains embedded in the code and inject your own code.

It needs a fair bit of TLC (kind of like my daughter), but it helped me to test some code which was otherwise not testable (and yes, the code was broken. Yay for testing!)

3 Comments

Your selection of code is creepy but congratulations to your daughter and wife!

Awesome! I have 4 of those little buggers. They are my world and I wouldn't have it any other way.

How time flies fast, seems just yesterday you posted about your wedding. Congratulations to both of you!

Leave a comment

About Ovid

user-pic Have Perl; Will Travel. Freelance Perl/Testing/Agile consultant. Photo by http://www.circle23.com/. Warning: that site is not safe for work. The photographer is a good friend of mine, though, and it's appropriate to credit his work.