peek_our#

Return every our variable in scope at a given call-stack depth as a hash of name-to-reference pairs.

Σύνοψη#

use PadWalker qw(peek_our);
my $h = peek_our($level);

Τι επιστρέφεται#

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.

Παραδείγματα#

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;
}

Οριακές περιπτώσεις#

  • $level works exactly as in peek_my - 0 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.

Διαφορές από το upstream#

Fully compatible with upstream PadWalker 2.5.

Δείτε επίσης#

  • peek_my - the sibling for my variables.

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