Skip to content

Commit 52427ad

Browse files
JRaspasskhwilliamson
authored andcommitted
Fix B::Concise BEGIN skip count
B::Concise tries hard to hide its own BEGIN blocks when asked to report BEGIN blocks in end-user's code. It does this by maintaining a count of each BEGIN/use/no (and those of the dependencies) and then splicing these BEGIN blocks off before printing. However this count has drifted over time, which this commit fixes. Before: $ perl -MO=Concise,BEGIN,-exec -e 'BEGIN {1} BEGIN {2}' ... BEGIN 1-8 ... BEGIN 9: 26 <;> nextstate(main 2 -e:1) v 27 <$> const[IV 1] s 28 <1> leavesub[1 ref] K/REFC,1 BEGIN 10: 29 <;> nextstate(main 4 -e:1) v 2a <$> const[IV 2] s 2b <1> leavesub[1 ref] K/REFC,1 -e syntax OK After: $ perl -MO=Concise,BEGIN,-exec -e 'BEGIN {1} BEGIN {2}' BEGIN 1: 1 <;> nextstate(main 2 -e:1) v 2 <$> const[IV 1] s 3 <1> leavesub[1 ref] K/REFC,1 BEGIN 2: 4 <;> nextstate(main 4 -e:1) v 5 <$> const[IV 2] s 6 <1> leavesub[1 ref] K/REFC,1 -e syntax OK The tests in ext/B/t/optree_specials.t now correctly only show the things being tested, but that also meant removing the bogus final test, as with this fix the code under test outputs nothing as it has no phase blocks in it.
1 parent 2a91fc1 commit 52427ad

File tree

3 files changed

+71
-640
lines changed

3 files changed

+71
-640
lines changed

ext/B/B/Concise.pm

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ package B::Concise;
1010
# -MO=Concise counts as use #1.
1111

1212
use strict; # use #2
13-
use warnings; # uses #3 and #4, since warnings uses Carp
13+
use warnings; # use #3
1414

15-
use Exporter 'import'; # use #5
15+
use Exporter 'import'; # uses #4-6, since Exporter does use strict, no strict
1616

17-
our $VERSION = "1.007";
17+
our $VERSION = "1.008";
1818
our @EXPORT_OK = qw( set_style set_style_standard add_callback
1919
concise_subref concise_cv concise_main
2020
add_style walk_output compile reset_sequence );
@@ -24,7 +24,8 @@ our %EXPORT_TAGS =
2424
cb => [qw( add_callback )],
2525
mech => [qw( concise_subref concise_cv concise_main )], );
2626

27-
# use #6
27+
# uses #7-10, since B->import loads Exporter::Heavy which does use strict,
28+
# no strict, no warnings.
2829
use B qw(class ppname main_start main_root main_cv cstring svref_2object
2930
SVf_IOK SVf_NOK SVf_POK SVf_IVisUV SVf_FAKE OPf_KIDS OPf_SPECIAL
3031
OPf_STACKED
@@ -113,7 +114,7 @@ sub add_callback {
113114

114115
# output handle, used with all Concise-output printing
115116
our $walkHandle; # public for your convenience
116-
BEGIN { $walkHandle = \*STDOUT }
117+
BEGIN { $walkHandle = \*STDOUT } # use #11
117118

118119
sub walk_output { # updates $walkHandle
119120
my $handle = shift;
@@ -179,7 +180,7 @@ sub concise_cv_obj {
179180
return;
180181
}
181182
if (class($cv->START) eq "NULL") {
182-
no strict 'refs';
183+
no strict 'refs'; # use #12
183184
if (ref $name eq 'CODE') {
184185
print $walkHandle "coderef $name has no START\n";
185186
}
@@ -229,7 +230,7 @@ sub concise_specials {
229230
my($name, $order, @cv_s) = @_;
230231
my $i = 1;
231232
if ($name eq "BEGIN") {
232-
splice(@cv_s, 0, 8); # skip 7 BEGIN blocks in this file. NOW 8 ??
233+
splice(@cv_s, 0, 16); # skip 16 BEGIN blocks from this file
233234
} elsif ($name eq "CHECK") {
234235
pop @cv_s; # skip the CHECK block that calls us
235236
}
@@ -301,7 +302,7 @@ sub compileOpts {
301302
}
302303
elsif ($o =~ /^-stash=(.*)/) {
303304
my $pkg = $1;
304-
no strict 'refs';
305+
no strict 'refs'; # use #13
305306
if (! %{$pkg.'::'}) {
306307
eval "require $pkg";
307308
} else {
@@ -366,7 +367,7 @@ sub compile {
366367
next;
367368
} else {
368369
$objname = "main::" . $objname unless $objname =~ /::/;
369-
no strict 'refs';
370+
no strict 'refs'; # use #14
370371
my $glob = \*$objname;
371372
unless (*$glob{CODE} || *$glob{FORMAT}) {
372373
print $walkHandle "$objname:\n" if $banner;
@@ -386,7 +387,7 @@ sub compile {
386387
}
387388
}
388389
for my $pkg (@render_packs) {
389-
no strict 'refs';
390+
no strict 'refs'; # use #15
390391
concise_stashref($order, \%{$pkg.'::'});
391392
}
392393

@@ -406,7 +407,7 @@ my %opclass = ('OP' => "0", 'UNOP' => "1", 'BINOP' => "2", 'LOGOP' => "|",
406407
'PVOP' => '"', 'LOOP' => "{", 'COP' => ";", 'PADOP' => "#",
407408
'METHOP' => '.', UNOP_AUX => '+');
408409

409-
no warnings 'qw'; # "Possible attempt to put comments..."; use #7
410+
no warnings 'qw'; # "Possible attempt to put comments..."; use #16
410411
my @linenoise =
411412
qw'# () sc ( @? 1 $* gv *{ m$ m@ m% m? p/ *$ $ $# & a& pt \\ s\\ rf bl
412413
` *? <> ?? ?/ r/ c/ // qr s/ /c y/ = @= C sC Cp sp df un BM po +1 +I

0 commit comments

Comments
 (0)