in reply to Asking a question in Makefile.PL

If you want to control the process yourself remember that Makefile.PL is just perl so before the call to WriteMakefile do whatever you want:

use ExtUtils::MakeMaker; eval{require Some::Module}; if ($@) { my $reply = prompt("Some::Module not installed. Install (Y/n)", "Y +"); install("Some::Module") unless $reply =~ m/n/i; } sub install { my $module = shift; eval{require CPAN}; die "Aaaaagh! $@\n" if $@; CPAN::Shell->install($module); } WriteMakefile( ... );

Update: In line with grinders post changed to EUMM prompt routine.

Replies are listed 'Best First'.
Re^2: Asking a question in Makefile.PL
by grinder (Bishop) on Apr 20, 2008 at 09:41 UTC

    And to back up what bingos says. NO, don't write your own prompt routine. You already have one in the EUMM distribution, and as a bonus it will play nicely with unattended installations.

    • another intruder with the mooring in the heart of the Perl

Re^2: Asking a question in Makefile.PL
by bingos (Vicar) on Apr 20, 2008 at 08:30 UTC

    NO, please don't invoke CPAN in Makefile.PL

    It is extremely bad practice. It plays havoc with CPANPLUS based CPAN tester rigs ( like mine ), and for people who don't use CPAN but use CPANPLUS for installing modules.

    Update

    The best way is to just let CPAN/CPANPLUS deal with installing the module for you as a prereq.

    use ExtUtils::MakeMaker; my %prereqs = ( "Blah::Blah" => 0, "Foo::Bar" => 1.0, ); eval{require Some::Module}; if ($@) { my $reply = prompt("Some::Module not installed. Install (Y/n)", "Y +"); $prereqs{"Some::Module"} = 0 unless $reply =~ m/n/i; } WriteMakefile( PREREQ_PM => \%prereqs, );

      While I'll accept it might not be best practice or suit testing rigs I would be interested to know what the preferred alternatives are.

      Okay, but what would be the alternative in this case? Could I check if CPANPLUS is what's being used and use that or use CPAN instead?