Make the removal of references to AvFLAGS in the B modules conditional
[p5sagit/p5-mst-13.2.git] / ext / B / B / Showlex.pm
index 31708e0..3b261a3 100644 (file)
@@ -1,6 +1,6 @@
 package B::Showlex;
 
-our $VERSION = '1.01';
+our $VERSION = '1.02';
 
 use strict;
 use B qw(svref_2object comppadlist class);
@@ -62,20 +62,21 @@ sub showlex {
     showvaluearray("Pad of lexical values for $objname", $valsav);
 }
 
+my ($newlex, $nosp1); # rendering state vars
+
 sub newlex { # drop-in for showlex
     my ($objname, $names, $vals) = @_;
     my @names = $names->ARRAY;
     my @vals  = $vals->ARRAY;
     my $count = @names;
     print $walkHandle "$objname Pad has $count entries\n";
-    printf $walkHandle "0: %s\n", $names[0]->terse;
+    printf $walkHandle "0: %s\n", $names[0]->terse unless $nosp1;
     for (my $i = 1; $i < $count; $i++) {
-       printf $walkHandle "$i: %s = %s\n", $names[$i]->terse, $vals[$i]->terse;
+       printf $walkHandle "$i: %s = %s\n", $names[$i]->terse, $vals[$i]->terse
+           unless $nosp1 and $names[$i]->terse =~ /SPECIAL/;
     }
 }
 
-my $newlex; # rendering state var
-
 sub showlex_obj {
     my ($objname, $obj) = @_;
     $objname =~ s/^&main::/&/;
@@ -84,7 +85,8 @@ sub showlex_obj {
 }
 
 sub showlex_main {
-    showlex("comppadlist", comppadlist->ARRAY);
+    showlex("comppadlist", comppadlist->ARRAY) if !$newlex;
+    newlex ("main", comppadlist->ARRAY)                if  $newlex;
 }
 
 sub compile {
@@ -92,12 +94,15 @@ sub compile {
     my @args = grep(!/^-/, @_);
     for my $o (@options) {
        $newlex = 1 if $o eq "-newlex";
+       $nosp1  = 1 if $o eq "-nosp";
     }
 
     return \&showlex_main unless @args;
     return sub {
+       my $objref;
        foreach my $objname (@args) {
-           my $objref;
+           next unless $objname;       # skip nulls w/o carping
+
            if (ref $objname) {
                print $walkHandle "B::Showlex::compile($objname)\n";
                $objref = $objname;
@@ -124,13 +129,74 @@ B::Showlex - Show lexical variables used in functions or files
 
 =head1 SYNOPSIS
 
-       perl -MO=Showlex[,SUBROUTINE] foo.pl
+       perl -MO=Showlex[,-OPTIONS][,SUBROUTINE] foo.pl
 
 =head1 DESCRIPTION
 
-When a subroutine name is provided in OPTIONS, prints the lexical
-variables used in that subroutine.  Otherwise, prints the file-scope
-lexicals in the file.
+When a comma-separated list of subroutine names is given as options, Showlex
+prints the lexical variables used in those subroutines.  Otherwise, it prints
+the file-scope lexicals in the file.
+
+=head1 EXAMPLES
+
+Traditional form:
+
+ $ perl -MO=Showlex -e 'my ($i,$j,$k)=(1,"foo")'
+ Pad of lexical names for comppadlist has 4 entries
+ 0: SPECIAL #1 &PL_sv_undef
+ 1: PVNV (0x9db0fb0) $i
+ 2: PVNV (0x9db0f38) $j
+ 3: PVNV (0x9db0f50) $k
+ Pad of lexical values for comppadlist has 5 entries
+ 0: SPECIAL #1 &PL_sv_undef
+ 1: NULL (0x9da4234)
+ 2: NULL (0x9db0f2c)
+ 3: NULL (0x9db0f44)
+ 4: NULL (0x9da4264)
+ -e syntax OK
+
+New-style form:
+
+ $ perl -MO=Showlex,-newlex -e 'my ($i,$j,$k)=(1,"foo")'
+ main Pad has 4 entries
+ 0: SPECIAL #1 &PL_sv_undef
+ 1: PVNV (0xa0c4fb8) "$i" = NULL (0xa0b8234)
+ 2: PVNV (0xa0c4f40) "$j" = NULL (0xa0c4f34)
+ 3: PVNV (0xa0c4f58) "$k" = NULL (0xa0c4f4c)
+ -e syntax OK
+
+New form, no specials, outside O framework:
+
+ $ perl -MB::Showlex -e \
+    'my ($i,$j,$k)=(1,"foo"); B::Showlex::compile(-newlex,-nosp)->()'
+ main Pad has 4 entries
+ 1: PVNV (0x998ffb0) "$i" = IV (0x9983234) 1
+ 2: PVNV (0x998ff68) "$j" = PV (0x998ff5c) "foo"
+ 3: PVNV (0x998ff80) "$k" = NULL (0x998ff74)
+
+Note that this example shows the values of the lexicals, whereas the other
+examples did not (as they're compile-time only).
+
+=head2 OPTIONS
+
+The C<-newlex> option produces a more readable C<< name => value >> format,
+and is shown in the second example above.
+
+The C<-nosp> option eliminates reporting of SPECIALs, such as C<0: SPECIAL
+#1 &PL_sv_undef> above.  Reporting of SPECIALs can sometimes overwhelm
+your declared lexicals.
+
+=head1 SEE ALSO
+
+C<B::Showlex> can also be used outside of the O framework, as in the third
+example.  See C<B::Concise> for a fuller explanation of reasons.
+
+=head1 TODO
+
+Some of the reported info, such as hex addresses, is not particularly
+valuable.  Other information would be more useful for the typical
+programmer, such as line-numbers, pad-slot reuses, etc..  Given this,
+-newlex isnt a particularly good flag-name.
 
 =head1 AUTHOR