Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The following code could be part of your solution - it will show you which symbols are imported for each instance of <code>use</code>:</p> <pre><code>package traceuse; use strict; use warnings; use Devel::Symdump; sub import { my $class = shift; my $module = shift; my $caller = caller(); my $before = Devel::Symdump-&gt;new($caller); my $args = \@_; # more robust way of emulating use? eval "package $caller; require $module; $module\-&gt;import(\@\$args)"; my $after = Devel::Symdump-&gt;new($caller); my @added; my @after_subs = $after-&gt;functions; my %before_subs = map { ($_,1) } $before-&gt;functions; for my $k (@after_subs) { push(@added, $k) unless $before_subs{$k}; } if (@added) { warn "using module $module added: ".join(' ', @added)."\n"; } else { warn "no new symbols from using module $module\n"; } } 1; </code></pre> <p>Then just replace "use module ..." with "use traceuse module ...", and you'll get a list of the functions that were imported.</p> <p>Usage example:</p> <pre><code>package main; sub foo { print "debug: foo called with: ".Dumper(\@_)."\n"; } use traceuse Data::Dumper; </code></pre> <p>This will output:</p> <pre><code>using module Data::Dumper added: main::Dumper </code></pre> <p>i.e. you can tell which functions were imported in robust way. And you can easily extend this to report on imported scalar, array and hash variables - check the docs on <code>Devel::Symdump</code>.</p> <p>Determine which functions are actually used is the other half of the equation. For that you might be able to get away with a simple grep of your source code - i.e. does <code>Dumper</code> appear in the module's source code that's not on a <code>use</code> line. It depends on what you know about your source code.</p> <p>Notes:</p> <ul> <li><p>there may be a module which does what traceuse does - I haven't checked</p></li> <li><p>there might be a better way to emulate "use" from another package</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload