/usr/lib/perl5/B/Walker.pm is in libb-perlreq-perl 0.82-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | package B::Walker;
our $VERSION = 0.11;
use 5.006;
use strict;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(padname padval const_sv walk);
our $CV;
sub padname ($) {
my $targ = shift;
return $CV->PADLIST->ARRAYelt(0)->ARRAYelt($targ);
}
sub padval ($) {
my $targ = shift;
return $CV->PADLIST->ARRAYelt(1)->ARRAYelt($targ);
}
sub const_sv ($) {
my $op = shift;
my $sv = $op->sv;
$sv = padval($op->targ) unless $$sv;
return $sv;
}
our $Level = 0;
our $Line;
our $Sub;
our $Opname;
our %Ops;
our %BlockData;
my %startblock = map { $_ => 1 }
qw(leave leaveloop leavesub leavesublv leavetry
grepwhile mapwhile scope);
sub walk_root ($);
sub walk_root ($) {
my $op = shift;
my $ref = ref($op);
if ($ref eq "B::COP") {
$Line = $op->line;
return;
}
my $name = $op->name;
use B qw(ppname);
$name = ppname($op->targ) if $name eq "null";
local $Level = $Level + 1;
local %BlockData = %BlockData if $startblock{$name};
local $Opname = $name if $Ops{$name};
$Ops{$name}->($op) if $Ops{$name} and $Line;
if ($ref eq "B::PMOP") {
my $root = $op->pmreplroot;
if (ref($root) and $root->isa("B::OP")) {
walk_root($root);
}
}
use B qw(OPf_KIDS);
if ($op->flags & OPf_KIDS) {
for ($op = $op->first; $$op; $op = $op->sibling) {
walk_root($op);
}
}
}
sub walk_cv ($);
sub walk_av ($$) {
my ($name, $av) = @_;
return if ref($av) ne "B::AV";
local $Sub = $name;
walk_cv($_) for $av->ARRAY;
}
sub walk_pad ($) {
my $pad = shift;
return unless $pad->can("ARRAY");
walk_av ANON => $pad->ARRAY;
}
sub walk_cv ($) {
my $cv = shift;
return if ref($cv) ne "B::CV";
return if $cv->FILE and $cv->FILE ne $0;
local $CV = $cv;
walk_root($cv->ROOT) if ${$cv->ROOT};
walk_pad($cv->PADLIST);
}
sub walk_blocks () {
use B qw(begin_av init_av);
walk_av "BEGIN" => begin_av;
walk_av "INIT" => init_av;
}
sub walk_main () {
use B qw(main_cv main_root);
local $Sub = "MAIN";
local $CV = main_cv;
walk_root(main_root) if ${main_root()};
walk_cv(main_cv);
}
sub walk_gv ($) {
my $gv = shift;
my $cv = $gv->CV;
return unless ( $$cv && ref($cv) eq "B::CV" );
return if $cv->XSUB;
local $Sub = $gv->SAFENAME;
$Line = $gv->LINE;
walk_cv($cv);
}
sub walk_stash ($$);
sub walk_stash ($$) { # similar to B::walksymtable
my ($symref, $prefix) = @_;
for my $sym (keys %$symref) {
no strict 'refs';
my $fullname = "*main::". $prefix . $sym;
if ($sym =~ /::\z/) {
$sym = $prefix . $sym;
walk_stash(\%$fullname, $sym)
if $sym ne "main::" && $sym ne "<none>::";
}
else {
use B qw(svref_2object);
walk_gv(svref_2object(\*$fullname))
if *$fullname{CODE};
}
}
}
sub walk_subs () {
walk_stash \%::, '';
}
sub walk () {
walk_blocks();
walk_main();
walk_subs();
}
1;
__END__
=head1 NAME
B::Walker - dumb walker, optree ranger
=head1 COPYING
Copyright (c) 2006, 2007 Alexey Tourbin, ALT Linux Team.
This is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
=head1 SEE ALSO
L<B::Utils>
|