pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on adding some features to CPAN::Mini::Inject, and it's command line tool mcpani. Right now I'm trying to add support for Module::Signature. The thing is, I want it to be optional. If the user doesn't have Module::Signature installed, I want make install to go smoothely, and I don't want mcpani to freak out when the user uses it.

So, my question to you monks is, what's the best way to handle an optional extra functionality like that? Can you point me to any documents/tutorials that talk about that? CPAN::Mini::Inject uses ExtUtils::ModuleMaker, but documentation relating to Module::Builder would also be great.

Thanks!
--Pileofrogs

Update: Downvote if you want, but say why... Can't get better if you don't say what the problem is.

Replies are listed 'Best First'.
Re: Module with optional features
by sgifford (Prior) on Apr 24, 2006 at 22:01 UTC
    The most common way to do this is to use or require the optional module in an eval string, then see whether that succeeded to decide whether to use the feature or not. The advantage to doing it at runtime is that if a user later installs the optional module, your code will just start using it.
Re: Module with optional features
by rinceWind (Monsignor) on Apr 24, 2006 at 22:33 UTC
    Check out Module::Optional, as this is the kind of job it was designed for. If you could write stub routines for Module::Signature, I think these would be popular enough and I will look at including Module::Signature::Dummy in a future release of Module::Optional - suitably attributed of course.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

Re: Module with optional features
by CountZero (Bishop) on Apr 25, 2006 at 03:55 UTC
    Have a look at the has_inst subroutine in the CPAN-module. It basically does a eval { require $file } but has some additional tests for Module::Signature and some tests for other necessary modules.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Module with optional features
by adrianh (Chancellor) on Apr 26, 2006 at 16:11 UTC
    CPAN::Mini::Inject uses ExtUtils::ModuleMaker, but documentation relating to Module::Builder would also be great.

    Module::Build supports this with "auto_features" - see the docs for details. So you might have something in your Build.PL like this (copied from the POD):

    my $b = Module::Build->new( # ... other stuff here... auto_features => { signature_support => { description => "Module::Signature support", requires => q{ Module::Signature >= 0.05 }, }, }, );

    and you can then test to see the feature is enabled with $b->feature('signature_support').