Author: dagolden
Date: Fri Oct 16 04:37:23 2009
New Revision: 13390

Added:
   Module-Build/trunk/t/perl_mb_opt.t   (contents, props changed)
Modified:
   Module-Build/trunk/Changes
   Module-Build/trunk/lib/Module/Build.pm
   Module-Build/trunk/lib/Module/Build/Base.pm
   Module-Build/trunk/t/lib/MBTest.pm

Log:
add support for PERL_MB_OPT

Modified: Module-Build/trunk/Changes
==============================================================================
--- Module-Build/trunk/Changes  (original)
+++ Module-Build/trunk/Changes  Fri Oct 16 04:37:23 2009
@@ -7,6 +7,10 @@
    argument for modification.  The method now takes no arguments and just
    returns a hash reference of metadata. [David Golden]
 
+ Enhancements
+ - Command line options may be set via the PERL_MB_OPT environment
+   variable (similar to PERL_MM_OPT in ExtUtils::MakeMaker)
+
  Bug fixes:
  - Updated PPM generation to PPM v4 (RT#49600) [Olivier Mengue]
  - When c_source is specified, the directory scan will include additional,

Modified: Module-Build/trunk/lib/Module/Build.pm
==============================================================================
--- Module-Build/trunk/lib/Module/Build.pm      (original)
+++ Module-Build/trunk/lib/Module/Build.pm      Fri Oct 16 04:37:23 2009
@@ -759,7 +759,6 @@
 
 =back
 
-
 =head2 Default Options File (F<.modulebuildrc>)
 
 [version 0.28]
@@ -797,6 +796,25 @@
 can set the environment variable C<MODULEBUILDRC> to the complete
 absolute path of the file containing your options.
 
+=head2 Environment variables
+
+=over
+
+=item MODULEBUILDRC
+
+[version 0.28]
+
+Specifies an alternate location for a default options file as described above.
+
+=item PERL_MB_OPT
+
+[version 0.36]
+
+Command line options that are applied to Build.PL or any Build action.  The
+string is split as the shell would (e.g. whitespace) and the result is
+prepended to any actual command-line arguments.
+
+=back
 
 =head1 INSTALL PATHS
 

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 Fri Oct 16 04:37:23 2009
@@ -2094,7 +2094,10 @@
 
 sub cull_args {
   my $self = shift;
-  my ($args, $action) = $self->read_args(@_);
+  my @arg_list = @_;
+  unshift @arg_list, $self->split_like_shell($ENV{PERL_MB_OPT})
+    if $ENV{PERL_MB_OPT};
+  my ($args, $action) = $self->read_args(@arg_list);
   $self->merge_args($action, %$args);
   $self->merge_modulebuildrc( $action, %$args );
 }

Modified: Module-Build/trunk/t/lib/MBTest.pm
==============================================================================
--- Module-Build/trunk/t/lib/MBTest.pm  (original)
+++ Module-Build/trunk/t/lib/MBTest.pm  Fri Oct 16 04:37:23 2009
@@ -13,6 +13,7 @@
     my @delete_env_keys = qw(
         DEVEL_COVER_OPTIONS
         MODULEBUILDRC
+        PERL_MB_OPT
         HARNESS_TIMER
         HARNESS_OPTIONS
         HARNESS_VERBOSE

Added: Module-Build/trunk/t/perl_mb_opt.t
==============================================================================
--- (empty file)
+++ Module-Build/trunk/t/perl_mb_opt.t  Fri Oct 16 04:37:23 2009
@@ -0,0 +1,62 @@
+# sample.t -- a sample test file for Module::Build
+
+use strict;
+use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
+use MBTest;
+use DistGen;
+
+plan tests => 8; # or 'no_plan'
+
+# Ensure any Module::Build modules are loaded from correct directory
+blib_load('Module::Build');
+
+# create dist object in a temp directory
+# enter the directory and generate the skeleton files
+my $dist = DistGen->new->chdir_in->regen;
+
+$dist->add_file('t/subtest/foo.t', <<'END_T');
+use strict;
+use Test::More tests => 1;
+ok(1, "this is a recursive test");
+END_T
+
+$dist->regen;
+
+# get a Module::Build object and test with it
+my $mb = $dist->new_from_context(); # quiet by default
+isa_ok( $mb, "Module::Build" );
+is( $mb->dist_name, "Simple", "dist_name is 'Simple'" );
+ok( ! $mb->recursive_test_files, "set for no recursive testing" );
+
+# set for recursive testing using PERL_MB_OPT
+{
+  local $ENV{PERL_MB_OPT} = "--verbose --recursive_test_files 1";
+
+  my $out = stdout_stderr_of( sub { 
+      $dist->run_build('test');
+  });
+  like( $out, qr/this is a recursive test/, 
+    "recursive tests run via PERL_MB_OPT"
+  );
+}
+
+# set Build.PL opts using PERL_MB_OPT
+{
+  local $ENV{PERL_MB_OPT} = "--verbose --recursive_test_files 1";
+  my $mb = $dist->new_from_context(); # quiet by default
+  ok( $mb->recursive_test_files, "PERL_MB_OPT set recusive tests in Build.PL" 
);
+  ok( $mb->verbose, "PERL_MB_OPT set verbose in Build.PL" );
+}
+
+# verify settings preserved during 'Build test'
+{
+  ok( !$ENV{PERL_MB_OPT}, "PERL_MB_OPT cleared" );
+  my $out = stdout_stderr_of( sub { 
+      $dist->run_build('test');
+  });
+  like( $out, qr/this is a recursive test/, 
+    "recursive tests run via Build object"
+  );
+}
+
+# vim:ts=2:sw=2:et:sta:sts=2

Reply via email to