Wanted to get some feedback on an idea that I'm toying with here on a project 
I'm working on....

With MB, having to subclass in order to add-in new features to the build works 
great, except that it doesn't let me split out those features into something 
that I can easily re-use from one project to the next.  Yes, I could just 
spin out a package that gathers up -everything- I'm doing, but there are 
times that I'd really just like to cherry-pick through the features I need 
for the project and include only those that are necessary.

So... I've been toying with the idea of "Module::Build::Pluggable" (MBP), 
which would be a hook/callback framework built on top of Module::Build.  
You'd subclass from MBP and then just include in the plug-ins that you wanted 
to have mix-in to your build environment.

Plug-ins wouldn't replace the existing MB behaviour/actions, but would 
supplement it.  When loaded, plug-ins would be able to register themselves 
with MBP and tell it which action they want to run in (and whether 
that's "pre:" or "post:" the core MB action).

A chunk of code is probably worth a thousand words...

    # First, create your custom build class
        package MY::Build;

        # derive from MBP
        use base qw( Module::Build::Pluggable );

        # then, load up MBP plug-ins
        use Module::Build::Plugin::example;
        use Module::Build::Plugin::...
        use Module::Build::Plugin::...

    # Then, use that class in your Build.PL
        use MY::Build;
        MY::Build->new(
            # regular Module::Build parameters
            )->create_build_script();

    # Plug-ins would register themselves with MBP when loaded
        package Module::Build::Plugin::example;
        sub import {
            my $caller = scalar(caller);
            $caller->add_callback( 'ACTION_test', \&test );
        }
        sub test {
            my $self = shift;
            # your extra "test" stuff goes here
        }

Having this type of pluggable interface would make it easier to extend MB with 
new actions as you could mix them as needed, without having to try to deal 
with wonderful things like multiple inheritance.  OR, have I completely 
missed the boat and overlooked some feature of MB that'd let me easily split 
build features out into separate modules and mix them in as needed?

-- 
Graham TerMarsch
Howling Frog Internet Development, Inc.

Reply via email to