Fri Jan 06 10:28:54 2012: Request 73785 was acted upon.
Transaction: Correspondence added by RSCHUPP
       Queue: Module-ScanDeps
     Subject: scandeps -c  fails on modules that depend on Getopt::Euclid
   Broken in: 1.07
    Severity: (no value)
       Owner: RSCHUPP
  Requestors: florent.an...@gmail.com
      Status: open
 Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=73785 >


On 2012-01-06 03:02:15, FANGLY wrote:
> In short, if scandeps could call "perl -c simple.pl" or "perl simple.pl"
> but somehow have $^C set to 1, then it would be fine.

OK, in order to use "perl -c" instead of "perl" we have
to instrument the script under examination with a CHECK block 
(which is executed even with "-c") instead of an INIT block 
(which is not).

Please try the attached patch.

Cheers, Roderich
Index: lib/Module/ScanDeps.pm
===================================================================
--- lib/Module/ScanDeps.pm	(revision 1312)
+++ lib/Module/ScanDeps.pm	(working copy)
@@ -719,7 +719,7 @@
             next unless $file =~ $ScanFileRE;
 
             ($inchash, $dl_shared_objects, $incarray) = ({}, [], []);
-            _compile($perl, $file, $inchash, $dl_shared_objects, $incarray);
+            _compile_or_execute($compile, $perl, $file, $inchash, $dl_shared_objects, $incarray);
 
             my $rv_sub = _make_rv($inchash, $dl_shared_objects, $incarray);
             _merge_rv($rv_sub, $rv);
@@ -730,7 +730,7 @@
         my $exc;
         foreach $exc (@$excarray) {
             ($inchash, $dl_shared_objects, $incarray) = ({}, [], []);
-            _execute($perl, $exc, $inchash, $dl_shared_objects, $incarray);
+            _compile_or_execute($compile, $perl, $exc, $inchash, $dl_shared_objects, $incarray);
         }
 
         # XXX only retains data from last execute ...  Why? I suspect
@@ -1232,11 +1234,8 @@
 
 # scan_deps_runtime utility functions
 
-sub _compile    { _compile_or_execute(1, @_) }
-sub _execute    { _compile_or_execute(0, @_) }
-
 sub _compile_or_execute {
-    my ($do_compile, $perl, $file, $inchash, $dl_shared_objects, $incarray) = @_;
+    my ($compile, $perl, $file, $inchash, $dl_shared_objects, $incarray) = @_;
 
     require Module::ScanDeps::DataFeed; 
     # ... so we can find it's full pathname in %INC
@@ -1250,14 +1249,14 @@
     # NOTE: We don't directly assign to $0 as it has magic (i.e.
     # assigning has side effects and may actually fail, cf. perlvar(1)).
     # Instead we alias *0 to a package variable holding the correct value.
-    print $feed_fh "BEGIN { ", 
+    print $feed_fh "BEGIN {\n", 
                    Data::Dumper->Dump([ $file ], [ "Module::ScanDeps::DataFeed::_0" ]),
-                   "*0 = \\\$Module::ScanDeps::DataFeed::_0; }\n";
+                   "*0 = \\\$Module::ScanDeps::DataFeed::_0;\n",
+                   "}\n";
 
-    print $feed_fh $do_compile ? "INIT {\n" : "END {\n";
-    # NOTE: When compiling the block will run _after_ all CHECK blocks
-    # (but _before_ the first INIT block) and will terminate the program.
-    # When executing the block will run as the first END block and 
+    print $feed_fh $compile ? "CHECK {\n" : "END {\n";
+    # NOTE: When compiling the block will run as the last CHECK block;
+    # when executing the block will run as the first END block and 
     # the programs continues.
 
     # correctly escape strings containing filenames
@@ -1265,20 +1264,19 @@
                        [ $INC{"Module/ScanDeps/DataFeed.pm"}, $dump_file ],
                        [ qw( datafeedpm dump_file ) ]);
 
+    # save %INC etc so that further requires dont't pollute them
     print $feed_fh <<'...';
-    # save %INC etc so that further requires dont't pollute them
     %Module::ScanDeps::DataFeed::_INC = %INC;
     @Module::ScanDeps::DataFeed::_INC = @INC;
     @Module::ScanDeps::DataFeed::_dl_shared_objects = @DynaLoader::dl_shared_objects;
     @Module::ScanDeps::DataFeed::_dl_modules = @DynaLoader::dl_modules;
 
-        require $datafeedpm;
+    require $datafeedpm;
 
     Module::ScanDeps::DataFeed::_dump_info($dump_file);
+}
 ...
 
-    print $feed_fh $do_compile ? "exit(0);\n}\n" : "}\n";
-
     # append the file to compile
     {
         open my $fhin, "<", $file or die "Couldn't open $file: $!";
@@ -1288,14 +1286,19 @@
     close $feed_fh;
 
     File::Path::rmtree( ['_Inline'], 0, 1); # XXX hack
-    my $rc = system($perl, (map { "-I$_" } @IncludeLibs), $feed_file);
+    
+    my @cmd = ($perl);
+    push @cmd, "-c" if $compile;
+    push @cmd, map { "-I$_" } @IncludeLibs;
+    my $rc = system(@cmd, $feed_file);
 
-    _extract_info($dump_file, $inchash, $dl_shared_objects, $incarray) if $rc == 0;
+    _extract_info($dump_file, $inchash, $dl_shared_objects, $incarray) 
+        if $rc == 0;
     unlink($feed_file, $dump_file);
-    die $do_compile
-            ? "SYSTEM ERROR in compiling $file: $rc" 
-            : "SYSTEM ERROR in executing $file: $rc" 
-            unless $rc == 0;
+    die $compile
+        ? "SYSTEM ERROR in compiling $file: $rc" 
+        : "SYSTEM ERROR in executing $file: $rc" 
+        unless $rc == 0;
 }
 
 # create a new hashref, applying fixups

Reply via email to