peek_our#
Return every our variable in scope at a given call-stack depth as a hash of name-to-reference pairs.
Synopsis#
use PadWalker qw(peek_our);
my $h = peek_our($level);
What you get back#
A hash reference keyed on sigiled variable names, with values that
are references to the package variables those our declarations
alias. Dereferencing reads from the package slot; assigning through
the reference writes back to it.
Examples#
package Main;
our $config = 'ok';
my $h = peek_our(0);
print ${ $h->{'$config'} }; # ok
Inspect a caller’s our variables:
sub show_our {
my $h = peek_our(1);
print join ",", sort keys %$h;
}
Edge cases#
$levelworks exactly as inpeek_my—0for the current scope,1for the caller, and so on.ourdeclarations are resolved through the package stash in effect at the declaration site, not the calling site.A package with an
ourname but no value yet appears in the hash with a reference toundef.
Differences from upstream#
Fully compatible with upstream PadWalker 2.5.
See also#
peek_my— the sibling formyvariables.var_name— resolve a reference back to its declared name.