Manipulating stashes (Perl's symbol tables) is occasionally necessary, but incredibly messy, and easy to get wrong. This module hides all of that behind a simple API.

NOTE: Most methods in this class require a variable specification that includes a sigil. If this sigil is absent, it is assumed to represent the IO slot.

Due to limitations in the typeglob API available to perl code, and to typeglob manipulation in perl being quite slow, this module provides two implementations - one in pure perl, and one using XS. The XS implementation is to be preferred for most usages; the pure perl one is provided for cases where XS modules are not a possibility. The current implementation in use can be set by setting $ENV{PACKAGE_STASH_IMPLEMENTATION} or $Package::Stash::IMPLEMENTATION before loading Package::Stash (with the environment variable taking precedence), otherwise, it will use the XS implementation if possible, falling back to the pure perl one.

$opts{filename}, $opts{first_line_num}, and $opts{last_line_num} can be used to indicate where the symbol should be regarded as having been defined. Currently these values are only used if the symbol is a subroutine ('&' sigil) and only if $^P & 0x10 is true, in which case the special %DB::sub hash is updated to record the values of filename, first_line_num, and last_line_num for the subroutine. If these are not passed, their values are inferred (as much as possible) from caller information.

Returns a list of package variable names in the package, without sigils. If a type_filter is passed, it is used to select package variables of a given type, where valid types are the slots of a typeglob ('SCALAR', 'CODE', 'HASH', etc). Note that if the package contained any BEGIN blocks, perl will leave an empty typeglob in the BEGIN slot, so this will show up if no filter is used (and similarly for INIT, END, etc).

Returns a hashref, keyed by the variable names in the package. If $type_filter is passed, the hash will contain every variable of that type in the package as values, otherwise, it will contain the typeglobs corresponding to the variable names (basically, a clone of the stash).