testcover and tap_harness_args

Elliot Shank <[email protected]> Thu, 27 May 2010 07:46:11 -0500
Newsgroups gmane.comp.lang.perl.modules.module-build
Message-ID <[email protected]>
If you turn on TAP::Harness, the testcover action won't work because TAP::Harness doesn't use HARNESS_PERL_SWITCHES.  The patch below fixes that, but it uses Storable, which wasn't in core until 5.7.3.  Alternative implementation ideas?



--- Module-Build-0.36_10/lib/Module/Build/Base.pm	2010-05-19 17:39:41.000000000 -0500
+++ Module-Build-0.36_10-patch/lib/Module/Build/Base.pm	2010-05-27 07:31:26.000000000 -0500
@@ -18,6 +18,7 @@
  use File::Compare ();
  use Module::Build::Dumper ();
  use IO::File ();
+use Storable qw< dclone >;
  use Text::ParseWords ();
  
  use Module::Build::ModuleInfo;
@@ -2697,7 +2698,26 @@
    local $Test::Harness::Switches    =
    local $ENV{HARNESS_PERL_SWITCHES} = "-MDevel::Cover";
  
-  $self->depends_on('test');
+  my $orig_tap_harness_args;
+  if ( my $tap_harness_args = $self->tap_harness_args() ) {
+    $tap_harness_args = dclone($tap_harness_args);
+    $orig_tap_harness_args = dclone($tap_harness_args);
+    my $switches = $tap_harness_args->{switches} || [];
+    push @{$switches}, '-MDevel::Cover';
+    $tap_harness_args->{switches} = $switches;
+    $self->tap_harness_args($tap_harness_args);
+  }
+
+  my $worked = eval {
+    $self->depends_on('test');
+    1;
+  };
+  my $error = $@;
+  if ($orig_tap_harness_args) {
+    $self->tap_harness_args($orig_tap_harness_args);
+  }
+  die $error if not $worked;
+
    $self->do_system('cover');
  }