7
7
# This is based on the module of the same name by Malcolm Beattie,
8
8
# but essentially none of his code remains.
9
9
10
- package B::Deparse 1.80 ;
10
+ package B::Deparse 1.81 ;
11
11
use strict;
12
12
use Carp;
13
13
use B qw( class main_root main_start main_cv svref_2object opnumber perlstring
@@ -28,7 +28,7 @@ use B qw(class main_root main_start main_cv svref_2object opnumber perlstring
28
28
OPpARG_IF_UNDEF OPpARG_IF_FALSE
29
29
SVf_IOK SVf_NOK SVf_ROK SVf_POK SVf_FAKE SVs_RMG SVs_SMG
30
30
SVs_PADTMP
31
- CVf_NOWARN_AMBIGUOUS CVf_LVALUE
31
+ CVf_NOWARN_AMBIGUOUS CVf_LVALUE CVf_IsMETHOD
32
32
PMf_KEEP PMf_GLOBAL PMf_CONTINUE PMf_EVAL PMf_ONCE
33
33
PMf_MULTILINE PMf_SINGLELINE PMf_FOLD PMf_EXTENDED PMf_EXTENDED_MORE
34
34
PADNAMEf_OUTER PADNAMEf_OUR PADNAMEf_TYPED
@@ -480,7 +480,8 @@ sub next_todo {
480
480
# XXX We would do $self->keyword("sub"), but ‘my CORE::sub’
481
481
# doesn’t work and ‘my sub’ ignores a &sub in scope. I.e.,
482
482
# we have a core bug here.
483
- push @text , " sub " . substr $name -> PVX, 1;
483
+ my $kw = $cv ? $self -> kw_sub_or_method($cv ) : " sub" ;
484
+ push @text , " $kw " . substr $name -> PVX, 1;
484
485
if ($cv ) {
485
486
# my sub foo { }
486
487
push @text , " " . $self -> deparse_sub($cv );
@@ -554,7 +555,7 @@ sub next_todo {
554
555
} elsif (defined $stash ) {
555
556
$name =~ s / ^\Q $stash\E ::(?!\z |.*::)// ;
556
557
}
557
- my $ret = " $pragmata${p}${l} " . $self -> keyword(" sub " ) . " $name "
558
+ my $ret = " $pragmata${p}${l} " . $self -> keyword($self -> kw_sub_or_method( $cv ) ) . " $name "
558
559
. $self -> deparse_sub($cv );
559
560
$self -> {' subs_declared' }{$name } = 1;
560
561
return $ret ;
@@ -1304,6 +1305,12 @@ sub deparse_argops {
1304
1305
}
1305
1306
1306
1307
1308
+ sub kw_sub_or_method {
1309
+ my $self = shift ;
1310
+ my $cv = shift ;
1311
+ return ($cv -> CvFLAGS & CVf_IsMETHOD) ? " method" : " sub" ;
1312
+ }
1313
+
1307
1314
# Deparse a sub. Returns everything except the 'sub foo',
1308
1315
# e.g. ($$) : method { ...; }
1309
1316
# or : prototype($$) lvalue ($a, $b) { ...; };
@@ -1329,10 +1336,13 @@ Carp::confess("SPECIAL in deparse_sub") if $cv->isa("B::SPECIAL");
1329
1336
$proto = $myproto ;
1330
1337
}
1331
1338
}
1332
- if ($cv -> CvFLAGS & (CVf_NOWARN_AMBIGUOUS|CVf_LOCKED|CVf_LVALUE|CVf_ANONCONST)) {
1333
- push @attrs , " lvalue" if $cv -> CvFLAGS & CVf_LVALUE;
1334
- push @attrs , " method" if $cv -> CvFLAGS & CVf_NOWARN_AMBIGUOUS;
1335
- push @attrs , " const" if $cv -> CvFLAGS & CVf_ANONCONST;
1339
+ my $cv_flags = $cv -> CvFLAGS;
1340
+ my $is_method = $cv_flags & CVf_IsMETHOD;
1341
+
1342
+ if ($cv_flags & (CVf_NOWARN_AMBIGUOUS|CVf_LOCKED|CVf_LVALUE|CVf_ANONCONST)) {
1343
+ push @attrs , " lvalue" if $cv_flags & CVf_LVALUE;
1344
+ push @attrs , " method" if $cv_flags & CVf_NOWARN_AMBIGUOUS and !$is_method ;
1345
+ push @attrs , " const" if $cv_flags & CVf_ANONCONST;
1336
1346
}
1337
1347
1338
1348
local ($self -> {' curcv' }) = $cv ;
@@ -1351,6 +1361,10 @@ Carp::confess("SPECIAL in deparse_sub") if $cv->isa("B::SPECIAL");
1351
1361
my $is_list = ($lineseq -> name eq " lineseq" );
1352
1362
my $firstop = $is_list ? $lineseq -> first : $lineseq ;
1353
1363
1364
+ if ($is_method and $firstop -> name eq " methstart" ) {
1365
+ $firstop = $firstop -> sibling;
1366
+ }
1367
+
1354
1368
# Try to deparse first subtree as a signature if possible.
1355
1369
# Top of signature subtree has an ex-argcheck as a placeholder
1356
1370
if ( $has_sig
@@ -2812,8 +2826,9 @@ sub pp_refgen {
2812
2826
2813
2827
sub e_anoncode {
2814
2828
my ($self , $info ) = @_ ;
2815
- my $text = $self -> deparse_sub($info -> {code });
2816
- return $self -> keyword(" sub" ) . " $text " ;
2829
+ my $cv = $info -> {code };
2830
+ my $text = $self -> deparse_sub($cv );
2831
+ return $self -> keyword($self -> kw_sub_or_method($cv )) . " $text " ;
2817
2832
}
2818
2833
2819
2834
sub pp_anoncode {
@@ -5645,7 +5660,7 @@ sub const {
5645
5660
$self -> {curcv }-> object_2svref == $ref -> object_2svref) {
5646
5661
return $self -> keyword(" __SUB__" );
5647
5662
}
5648
- return " sub " . $self -> deparse_sub($ref );
5663
+ return $self -> kw_sub_or_method( $ref ) . " " . $self -> deparse_sub($ref );
5649
5664
}
5650
5665
if ($class ne ' SPECIAL' and $ref -> FLAGS & SVs_SMG) {
5651
5666
for (my $mg = $ref -> MAGIC; $mg ; $mg = $mg -> MOREMAGIC) {
0 commit comments