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#

  • $level works exactly as in peek_my0 for the current scope, 1 for the caller, and so on.

  • our declarations are resolved through the package stash in effect at the declaration site, not the calling site.

  • A package with an our name but no value yet appears in the hash with a reference to undef.

Differences from upstream#

Fully compatible with upstream PadWalker 2.5.

See also#

  • peek_my — the sibling for my variables.

  • var_name — resolve a reference back to its declared name.