develooper Front page | perl.perl5.porters | Postings from December 2001

[PATCH] ext/B/B/Xref.pm adding "our" recognition

From:
Wolfgang Laun
Date:
December 21, 2001 05:02
Subject:
[PATCH] ext/B/B/Xref.pm adding "our" recognition
Message ID:
3C2332C9.7CFED5F2@alcatel.at
The program:
  my( $x, $y );
  my $z = 1;
  our( $x, $y );
  our $z = 1;

perl -MO=Xref try.pl # BEFORE:
  Subroutine (main)
    Package (lexical)
      $x                i1
      $y                i1
      $z                i2
    Package main
      $x                4
      $y                4
      $z                5

# AFTER:
  Subroutine (main)
    Package (lexical)
      $x                i1
      $y                i1
      $z                i2
    Package main
      $x                i3
      $y                i3
      $z                i4

Merry Xmas :-)
-W

--- ext/B/B/Xref.pm.old	Thu Dec 20 15:42:51 2001
+++ ext/B/B/Xref.pm	Fri Dec 21 13:51:17 2001
@@ -89,7 +89,7 @@
 use strict;
 use Config;
 use B qw(peekop class comppadlist main_start svref_2object walksymtable
-         OPpLVAL_INTRO SVf_POK
+         OPpLVAL_INTRO SVf_POK OPpOUR_INTRO
         );
 
 sub UNKNOWN { ["?", "?", "?"] }
@@ -230,16 +230,16 @@
 sub pp_padhv { pp_padsv(@_) }
 
 sub deref {
-    my ($var, $as) = @_;
+    my ($op, $var, $as) = @_;
     $var->[1] = $as . $var->[1];
-    process($var, "used");
+    process($var, $op->private & OPpOUR_INTRO ? "intro" : "used");
 }
 
-sub pp_rv2cv { deref($top, "&"); }
-sub pp_rv2hv { deref($top, "%"); }
-sub pp_rv2sv { deref($top, "\$"); }
-sub pp_rv2av { deref($top, "\@"); }
-sub pp_rv2gv { deref($top, "*"); }
+sub pp_rv2cv { deref(shift, $top, "&"); }
+sub pp_rv2hv { deref(shift, $top, "%"); }
+sub pp_rv2sv { deref(shift, $top, "\$"); }
+sub pp_rv2av { deref(shift, $top, "\@"); }
+sub pp_rv2gv { deref(shift, $top, "*"); }
 
 sub pp_gvsv {
     my $op = shift;
@@ -253,7 +253,8 @@
 	$gv = $op->gv;
 	$top = [$gv->STASH->NAME, '$', $gv->NAME];
     }
-    process($top, $op->private & OPpLVAL_INTRO ? "intro" : "used");
+    process($top, $op->private & OPpLVAL_INTRO ||
+                  $op->private & OPpOUR_INTRO   ? "intro" : "used");
 }
 
 sub pp_gv {



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About