New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] B::Showlex::newlex enhancement and pod #7512
Comments
From jcromie@divsol.comCreated by jimc@harpo.jimc.earthpatch (to be attached shortly), enhances B::Showlex::newlex [jimc@harpo showlex]$ ./perl -Ilib -MO=Showlex,-newlex -e 'my ($i,$j,$k)=(1,"foo");' Perl Info
|
From jcromie@divsol.comInline Patchdiff -ru -X exclude-diffs ../bleadperl/ext/B/B/Concise.pm showlex/ext/B/B/Concise.pm
--- ../bleadperl/ext/B/B/Concise.pm 2004-09-08 11:15:52.000000000 -0600
+++ showlex/ext/B/B/Concise.pm 2004-09-23 12:34:12.000000000 -0600
@@ -274,7 +274,8 @@
warn "disregarding non-options: @newargs\n" if @newargs;
for my $objname (@args) {
-
+ next unless $objname; # skip null args to avoid noisy responses
+
if ($objname eq "BEGIN") {
concise_specials("BEGIN", $order,
B::begin_av->isa("B::AV") ?
Inline Patchdiff -ru -X exclude-diffs ../bleadperl/ext/B/B/Showlex.pm showlex/ext/B/B/Showlex.pm
--- ../bleadperl/ext/B/B/Showlex.pm 2004-05-14 10:51:58.000000000 -0600
+++ showlex/ext/B/B/Showlex.pm 2004-09-23 14:12:24.000000000 -0600
@@ -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 @@
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_main {
- showlex("comppadlist", comppadlist->ARRAY);
+ showlex("comppadlist", comppadlist->ARRAY) if !$newlex;
+ newlex ("main", comppadlist->ARRAY) if $newlex;
}
sub compile {
@@ -92,12 +94,15 @@
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,76 @@
=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 (comma separated) subroutines are 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 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 initialized values of the lexicals,
+whereas the other examples did not (theyre compile-time only).
+
+=head2 OPTIONS
+
+C<-newlex> option produces a more readable name => value format, and
+is shown in 2nd example above.
+
+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, this allows you to suppress those
+report-lines.
+
+
+=head1 SEE ALSO
+
+C<B::Showlex> can also be used outside of the O framework, as in 3rd
+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
Inline Patchdiff -ru -X exclude-diffs ../bleadperl/ext/B/t/showlex.t showlex/ext/B/t/showlex.t
--- ../bleadperl/ext/B/t/showlex.t 2004-09-10 11:03:10.000000000 -0600
+++ showlex/ext/B/t/showlex.t 2004-09-23 13:55:04.000000000 -0600
@@ -21,7 +21,7 @@
use Config;
use B::Showlex ();
-plan tests => 8;
+plan tests => 15;
my $verbose = @ARGV; # set if ANY ARGS
@@ -44,70 +44,78 @@
# v1.01 tests
-my ($na,$nb,$nc); # holds regex-strs
+my ($na,$nb,$nc); # holds regex-strs
+my ($out, $newlex); # output, option-flag
+
sub padrep {
- my $varname = shift;
- return "PVNV \\\(0x[0-9a-fA-F]+\\\) \\$varname\n";
+ my ($varname,$newlex) = @_;
+ return ($newlex)
+ ? 'PVNV \(0x[0-9a-fA-F]+\) "\\'.$varname.'" = '
+ : "PVNV \\\(0x[0-9a-fA-F]+\\\) \\$varname\n";
}
-my $out = runperl ( switches => ["-MO=Showlex"],
- prog => 'my ($a,$b)', stderr => 1 );
-$na = padrep('$a');
-$nb = padrep('$b');
-like ($out, qr/1: $na/ms, 'found $a in "my ($a,$b)"');
-like ($out, qr/2: $nb/ms, 'found $b in "my ($a,$b)"');
+for $newlex ('', '-newlex') {
-print $out if $verbose;
+ $out = runperl ( switches => ["-MO=Showlex,$newlex"],
+ prog => 'my ($a,$b)', stderr => 1 );
+ $na = padrep('$a',$newlex);
+ $nb = padrep('$b',$newlex);
+ like ($out, qr/1: $na/ms, 'found $a in "my ($a,$b)"');
+ like ($out, qr/2: $nb/ms, 'found $b in "my ($a,$b)"');
+
+ print $out if $verbose;
SKIP: {
skip "no perlio in this build", 5
unless $Config::Config{useperlio};
-our $buf = 'arb startval';
-my $ak = B::Showlex::walk_output (\$buf);
-
-my $walker = B::Showlex::compile(sub { my ($foo,$bar) });
-$walker->();
-$na = padrep('$foo');
-$nb = padrep('$bar');
-like ($buf, qr/1: $na/ms, 'found $foo in "sub { my ($foo,$bar) }"');
-like ($buf, qr/2: $nb/ms, 'found $bar in "sub { my ($foo,$bar) }"');
-
-print $buf if $verbose;
-
-$ak = B::Showlex::walk_output (\$buf);
-
-$walker = B::Showlex::compile(sub { my ($scalar,@arr,%hash) });
-$walker->();
-$na = padrep('$scalar');
-$nb = padrep('@arr');
-$nc = padrep('%hash');
-like ($buf, qr/1: $na/ms, 'found $scalar in "sub { my ($scalar,@arr,%hash) }"');
-like ($buf, qr/2: $nb/ms, 'found @arr in "sub { my ($scalar,@arr,%hash) }"');
-like ($buf, qr/3: $nc/ms, 'found %hash in "sub { my ($scalar,@arr,%hash) }"');
-
-print $buf if $verbose;
-
-my $asub = sub {
- my ($self,%props)=@_;
- my $total;
- { # inner block vars
- my (@fib)=(1,2);
- for (my $i=2; $i<10; $i++) {
- $fib[$i] = $fib[$i-2] + $fib[$i-1];
+ our $buf = 'arb startval';
+ my $ak = B::Showlex::walk_output (\$buf);
+
+ my $walker = B::Showlex::compile( $newlex, sub{my($foo,$bar)} );
+ $walker->();
+ $na = padrep('$foo',$newlex);
+ $nb = padrep('$bar',$newlex);
+ like ($buf, qr/1: $na/ms, 'found $foo in "sub { my ($foo,$bar) }"');
+ like ($buf, qr/2: $nb/ms, 'found $bar in "sub { my ($foo,$bar) }"');
+
+ print $buf if $verbose;
+
+ $ak = B::Showlex::walk_output (\$buf);
+
+ my $src = 'sub { my ($scalar,@arr,%hash) }';
+ my $sub = eval $src;
+ $walker = B::Showlex::compile($sub);
+ $walker->();
+ $na = padrep('$scalar',$newlex);
+ $nb = padrep('@arr',$newlex);
+ $nc = padrep('%hash',$newlex);
+ like ($buf, qr/1: $na/ms, 'found $scalar in "'. $src .'"');
+ like ($buf, qr/2: $nb/ms, 'found @arr in "'. $src .'"');
+ like ($buf, qr/3: $nc/ms, 'found %hash in "'. $src .'"');
+
+ print $buf if $verbose;
+
+ # fibonacci function under test
+ my $asub = sub {
+ my ($self,%props)=@_;
+ my $total;
+ { # inner block vars
+ my (@fib)=(1,2);
+ for (my $i=2; $i<10; $i++) {
+ $fib[$i] = $fib[$i-2] + $fib[$i-1];
+ }
+ for my $i(0..10) {
+ $total += $i;
+ }
}
- for my $i(0..10) {
- $total += $i;
- }
- }
-};
-$walker = B::Showlex::compile($asub, '-newlex');
-$walker->();
-
-$walker = B::Concise::compile($asub, '-exec');
-$walker->();
-
-
-print $buf if $verbose;
-
+ };
+ $walker = B::Showlex::compile($asub, $newlex, -nosp);
+ $walker->();
+ print $buf if $verbose;
+
+ $walker = B::Concise::compile($asub, '-exec');
+ $walker->();
+
+}
}
Inline Patchdiff -ru -X exclude-diffs ../bleadperl/lib/B/Concise.pm showlex/lib/B/Concise.pm
--- ../bleadperl/lib/B/Concise.pm 2004-09-08 11:15:52.000000000 -0600
+++ showlex/lib/B/Concise.pm 2004-09-23 12:34:12.000000000 -0600
@@ -274,7 +274,8 @@
warn "disregarding non-options: @newargs\n" if @newargs;
for my $objname (@args) {
-
+ next unless $objname; # skip null args to avoid noisy responses
+
if ($objname eq "BEGIN") {
concise_specials("BEGIN", $order,
B::begin_av->isa("B::AV") ?
diff -ru -X exclude-diffs ../bleadperl/lib/B/Showlex.pm showlex/lib/B/Showlex.pm
--- ../bleadperl/lib/B/Showlex.pm 2004-05-14 10:51:58.000000000 -0600
+++ showlex/lib/B/Showlex.pm 2004-09-23 14:12:24.000000000 -0600
@@ -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 @@
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_main {
- showlex("comppadlist", comppadlist->ARRAY);
+ showlex("comppadlist", comppadlist->ARRAY) if !$newlex;
+ newlex ("main", comppadlist->ARRAY) if $newlex;
}
sub compile {
@@ -92,12 +94,15 @@
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,76 @@
=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 (comma separated) subroutines are 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 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 initialized values of the lexicals,
+whereas the other examples did not (theyre compile-time only).
+
+=head2 OPTIONS
+
+C<-newlex> option produces a more readable name => value format, and
+is shown in 2nd example above.
+
+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, this allows you to suppress those
+report-lines.
+
+
+=head1 SEE ALSO
+
+C<B::Showlex> can also be used outside of the O framework, as in 3rd
+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
|
From @rgsJim Cromie (via RT) wrote:
Thanks, applied as #23350 to bleadperl (with wording nits to the POD.) |
The RT System itself - Status changed from 'new' to 'open' |
@rgs - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#31697 (status was 'resolved')
Searchable as RT31697$
The text was updated successfully, but these errors were encountered: