another CUFP or better WICDWMBP (what i can do with my baby Perl)..
Reading
this post i'm started wondering if there was a way to wrap an existing script and grab modules it uses without exucuting it.
Obviously the answer or part of it was in the monastery:
here
I very liked the
perl -d:Modlist=options script.pl
perl -MDevel::Modlist=options script.pl # equivalent
part but, unfortunately it executes the script.pl
Also liked the
tachyon-II hack, but you have to edit the script.pl and i'm too lazy.
No hope to use
$^C = 1 as pointed wisely by
shmem
The
UNITCHECK do the trick! Never known it seems quite usefull for this task:
read about it
#!perl
#use strict; #commented to not pollute %INC
#use warnings;#commented to not pollute %INC
my $file = $ARGV[0];
my $content = do { open my $fh, '<', $file or die $!; local $/; <$fh>
+};
my $begin =<<'THEEND';
UNITCHECK {
no strict; # access $VERSION by symbolic reference
no warnings qw (uninitialized);
print map {
s!/!::!g;
s!.pm$!!;
sprintf "%-20s %s\n", $_, ${"${_}::VERSION"}
} sort keys %INC;
exit;
};
THEEND
eval $begin.$content;
print $@ if $@;
Enjoy the results!
HtH
L*
UPDATE 9 april 2014: BE CAREFULL, as stated by
davido and also by
LanX in other post,
BEGIN blocks are executed anyway. In fact
BEGIN blocks come first, in order of definition, then come
UNITCHECK blocks and, being that block prepended to the original code in the above program, it will be executed just after the last
BEGIN block and just before any
UNITCHECK defined in the original program passed in via
@ARGV. In the case of
perl -c -d:TraceUse script.pl all the
BEGIN UNITCHECK CHECK blocks are executed.
Here two examples to demonstrate where the
-c ends his operations (a simplified version of
16 pillars of wisdom):
perl -c -e "BEGIN{print qq(1-begin\n)};
UNITCHECK {print qq(2-unitcheck\n)};
CHECK {print qq(3-check\n)};
INIT {print qq(4-init\n)};
print qq(5-main\n);
END{print qq(6-end\n)}"
__OUTPUT__
1-begin
2-unitcheck
3-check
-e syntax OK
# the same code without -c
__OUTPUT__
1-begin
2-unitcheck
3-check
4-init
5-main
6-end
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.