Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Making a distribution for my website

by gone2015 (Deacon)
on Feb 06, 2009 at 18:23 UTC ( [id://741976]=note: print w/replies, xml ) Need Help??


in reply to Making a distribution for my website

If you're trying to find out what modules your program is using, then the following piece of magic may suffice:

END { foreach my $file (sort keys %INC) { my $module = $file ; my $located = $INC{$file} ; $module =~ s|\.pm$|| ; $module =~ s|[/\\]|::|g ; my $version ; { no strict 'refs' ; $version = ${$module.'::VERSION'} || '??' ; } + ; print STDERR "$module v$version $located\n" ; } ; } ;
if inserted at the start of your program, just before it ends it will print to STDERR all the module file names it has seen require and/or use for. Which may give you a fighting chance of constructing a suitable install package.

Mind you, this will miss any require operations which your test run does not actually execute... I cannot imagine that this will be a problem, but it's tricky to guarantee. If that worries you, you can try:

END { my %myINC = () ; foreach my $file (keys %INC) { my $module = $file ; $module =~ s|\.pm$|| ; $module =~ s|[/\\]|::|g ; $myINC{$module} = $INC{$file} ; } ; foreach my $module (sort keys %myINC) { my $located = $myINC{$module} ; my $version ; { no strict 'refs' ; $version = ${$module.'::VERSION'} || '??' ; } + ; print STDERR "$module v$version $located\n" ; open my $FH, "<", $located or die "failed to open $located: $!" +; while (<$FH>) { if ((m/^(?:\s+|[^#;];\s*)*?require\s+([A-Za-z]\w+(?:::\w+)*)\b/) && !exists($myINC{$1 +})) { printf STDERR " %5d: %s", $., $_ ; } ; } ; } ; } ;
which has a stab at scanning all the required files, looking for require statements for modules (ignores version numbers) that refer to modules that are not already known.

NB: this comes without warranty of any kind, in particular no warranty of fitness for any purpose whatsoever; and if you use this you acknowledge that such exclusion of warranty is entirely reasonable, given the level of the fee :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://741976]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-25 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found