http://qs321.pair.com?node_id=11107929

You may try a perl app and see Can't locate Foo/Bar.pm in @INC (you may need to install the Foo::Bar module) (@INC contains: ...

So you install the Foo::Bar module and try again and see Can't locate Bar/Baz.pm in @INC (you may need to install the Bar::Baz module) (@INC contains: ...

So you install the Bar::Baz module and the application runs.

Module::Load::Conditional (core) can reduce the pain to:

Install required modules Foo::Bar Bar::Baz from CPAN? (y)/n y
Use 1. cpan or 2. cpanm 1/(2) 2
Successfully installed Foo::Bar
Successfully installed Bar::Baz
Or select 'n' for something more than @INC:
Install required perl modules:
cpan Foo::Bar Bar::Baz 
cpanm -v Foo::Bar Bar::Baz 

Can't locate Foo::Bar Bar::Baz in @INC (@INC contains: ...
Should perl be doing something like this on the core level?

Should monks adopt this mess or fold it into a module so it becomes a best practice?

How could this idea be improved?

Thank you!

#!/usr/bin/perl use strict; use warnings; #use Foo::Bar; #use Bar::Baz; use Module::Load::Conditional 'can_load'; BEGIN { my $modules = [ map {$_} qw[ IPC::Cmd Foo::Bar Bar::Baz ]]; my @install = do { local @_; for my $m (@$modules) { push @_, $m unless can_load(modules => {$m,undef}, autoload => 1)} @_ }; @install and do { print 'Install required modules ', join(' ', @install), ' from CPAN? (y)/n '; my $in = <STDIN>; chomp $in; $in ||= 'y'; my $cpanm = IPC::Cmd::can_run('cpanm'); if (lc $in eq 'y') { if ($cpanm) { print 'Use 1. cpan or 2. cpanm 1/(2) '; my $cpan = do { local $_ = <STDIN>; chomp $_; $_ ||= 2; $_ = 2 unless /^1|2$/; $_ }; if ($cpan == 2) { unless (system $cpanm, '-v', @install) { system 'perl', $0, @ARGV; exit } } } unless (system 'cpan', @install) { system 'perl', $0, @ARGV; exit } } else{ die "Install required perl modules:\n". join ' ', 'cpan', @install, "\n". ($cpanm ? join(' ', 'cpanm', @install) : '')."\n\n". "Can't locate ".join(' ',@install).' in @INC '. '(@INC contains: '.join(' ', @INC).") \n" } }; Bar::Baz->import('Something')}