Hi all,

This patch starts the ball rolling for adding an 'installdeps' action.  
The basic idea is to prompt about whatever optional modules, then run 
the user's choice of program with the needed modules as arguments.

David Golden mentioned the issue of what if the perl that runs Build.PL 
is not the same as the one that is in the path/shebang wrt the 'cpan' 
client.  The --cpan-client option is probably enough to get around 
that.

There are caveats with @INC.  We could simply assume that every valid 
option for --cpan-client is a perl script and run it through 
run_perl_script() with the -S option?

And of course, it needs documentation and tests.  I've tested it 
with "--cpan-client echo", but probably printing a small perl script 
and running that (to print @ARGV to a temp file) would be the way to 
cover it.

--Eric

----------  Forwarded Message:  ----------

Subject: [svn:Module-Build] r13254 - Module-Build/trunk/lib/Module/Build
Date: Tuesday 01 September 2009 20:33
From: ericwilh...@cvs.perl.org
To: svn-commit-modules-module-bu...@perl.org

Author: ericwilhelm
Date: Tue Sep  1 20:33:09 2009
New Revision: 13254

Modified:
   Module-Build/trunk/lib/Module/Build/Base.pm

Log:
lib/Module/Build/Base.pm - initial code for installdeps


Modified: Module-Build/trunk/lib/Module/Build/Base.pm
=======================================================================
======= --- Module-Build/trunk/lib/Module/Build/Base.pm (original)
+++ Module-Build/trunk/lib/Module/Build/Base.pm Tue Sep  1 20:33:09
 2009 @@ -850,6 +850,7 @@
 __PACKAGE__->add_property(config => undef);
 __PACKAGE__->add_property(test_file_exts => ['.t']);
 __PACKAGE__->add_property(use_tap_harness => 0);
+__PACKAGE__->add_property(cpan_client => 'cpan');
 __PACKAGE__->add_property(tap_harness_args => {});
 __PACKAGE__->add_property(
   'installdirs',
@@ -1752,6 +1753,7 @@
     use_rcfile
     use_tap_harness
     tap_harness_args
+    cpan_client
   ); # normalize only selected option names

   return $opt;
@@ -3154,6 +3156,33 @@
   only::install::install(%onlyargs);
 }

+sub ACTION_installdeps {
+  my ($self) = @_;
+
+  my $info = $self->_enum_prereqs or return;
+
+  my $failures = $self->prereq_failures($info) or return;
+
+  my @install;
+  while (my ($type, $prereqs) = each %$failures) {
+    warn $type;
+    if($type =~ m/_requires$/) {
+      push(@install, keys %$prereqs);
+      next;
+    }
+    while (my ($module, $status) = each %$prereqs) {
+      warn "$type $module $status->{message}\n";
+      push(@install, $module) if($self->y_n("install $module?", 'y'));
+    }
+  }
+
+
+  my ($command, @opts) = $self->split_like_shell($self->cpan_client);
+  # TODO possibly check whether $command is a perl script (search the
+  # PATH) and use run_perl_command().
+  $self->do_system($command, @opts, @install);
+}
+
 sub ACTION_clean {
   my ($self) = @_;
   foreach my $item (map glob($_), $self->cleanup) {

-------------------------------------------------------

-- 
software:  a hypothetical exercise which happens to compile.
---------------------------------------------------
    http://scratchcomputing.com
---------------------------------------------------

Reply via email to