{"id":6688,"date":"2022-12-20T19:33:25","date_gmt":"2022-12-20T22:33:25","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/packagestash-man3\/"},"modified":"2022-12-20T19:33:25","modified_gmt":"2022-12-20T22:33:25","slug":"packagestash-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/packagestash-man3\/","title":{"rendered":"Package::Stash (man3)"},"content":{"rendered":"<h1 align=\"center\">Package::Stash<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#VERSION\">VERSION<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#METHODS\">METHODS<\/a><br \/> <a href=\"#WORKING WITH VARIABLES\">WORKING WITH VARIABLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#HISTORY\">HISTORY<\/a><br \/> <a href=\"#BUGS \/ CAVEATS\">BUGS \/ CAVEATS<\/a><br \/> <a href=\"#AUTHORS\">AUTHORS<\/a><br \/> <a href=\"#CONTRIBUTORS\">CONTRIBUTORS<\/a><br \/> <a href=\"#COPYRIGHT AND LICENSE\">COPYRIGHT AND LICENSE<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Package::Stash \u2212 Routines for manipulating stashes<\/p>\n<h2>VERSION <a name=\"VERSION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">version 0.39<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">my $stash = Package::Stash\u2212>new(&#8216;Foo&#8217;); <br \/> $stash\u2212>add_symbol(&#8216;%foo&#8217;, {bar => 1}); <br \/> # $Foo::foo{bar} == 1 <br \/> $stash\u2212>has_symbol(&#8216;$foo&#8217;) # false <br \/> my $namespace = $stash\u2212>namespace; <br \/> *{ $namespace\u2212>{foo} }{HASH} # {bar => 1}<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Manipulating stashes (Perl\u2019s symbol tables) is occasionally necessary, but incredibly messy, and easy to get wrong. This module hides all of that behind a simple <small>API.<\/small><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><small>NOTE:<\/small> Most methods in this class require a variable specification that includes a sigil. If this sigil is absent, it is assumed to represent the <small>IO<\/small> slot.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Due to limitations in the typeglob <small>API<\/small> available to perl code, and to typeglob manipulation in perl being quite slow, this module provides two implementations \u2212 one in pure perl, and one using <small>XS.<\/small> The <small>XS<\/small> implementation is to be preferred for most usages; the pure perl one is provided for cases where <small>XS<\/small> 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 <small>XS<\/small> implementation if possible, falling back to the pure perl one.<\/p>\n<h2>METHODS <a name=\"METHODS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>new $package_name<\/b> <br \/> Creates a new &#8220;Package::Stash&#8221; object, for the package given as the only argument.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>name<\/b> <br \/> Returns the name of the package that this object represents.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>namespace<\/b> <br \/> Returns the raw stash itself.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>add_symbol $variable $value %opts<\/b> <br \/> Adds a new package symbol, for the symbol given as $variable, and optionally gives it an initial value of $value. $variable should be the name of variable including the sigil, so<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Package::Stash\u2212>new(&#8216;Foo&#8217;)\u2212>add_symbol(&#8216;%foo&#8217;)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">will create %Foo::foo.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Valid options (all optional) are &#8220;filename&#8221;, &#8220;first_line_num&#8221;, and &#8220;last_line_num&#8221;.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">$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 (\u2019&#8221;&#038;&#8221;\u2019 sigil) and only if &#8220;$^P &#038; 0x10&#8221; is true, in which case the special %DB::sub hash is updated to record the values of &#8220;filename&#8221;, &#8220;first_line_num&#8221;, and &#8220;last_line_num&#8221; for the subroutine. If these are not passed, their values are inferred (as much as possible) from &#8220;caller&#8221; information.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>remove_glob $name<\/b> <br \/> Removes all package variables with the given name, regardless of sigil.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>has_symbol $variable<\/b> <br \/> Returns whether or not the given package variable (including sigil) exists.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>get_symbol $variable<\/b> <br \/> Returns the value of the given package variable (including sigil).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>get_or_add_symbol $variable<\/b> <br \/> Like &#8220;get_symbol&#8221;, except that it will return an empty hashref or arrayref if the variable doesn\u2019t exist.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>remove_symbol $variable<\/b> <br \/> Removes the package variable described by $variable (which includes the sigil); other variables with the same name but different sigils will be untouched.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>list_all_symbols $type_filter<\/b> <br \/> Returns a list of package variable names in the package, without sigils. If a &#8220;type_filter&#8221; is passed, it is used to select package variables of a given type, where valid types are the slots of a typeglob (\u2019 <small>SCALAR<\/small> \u2019, \u2019 <small>CODE<\/small> \u2019, \u2019 <small>HASH<\/small> \u2019, etc). Note that if the package contained any &#8220;BEGIN&#8221; blocks, perl will leave an empty typeglob in the &#8220;BEGIN&#8221; slot, so this will show up if no filter is used (and similarly for &#8220;INIT&#8221;, &#8220;END&#8221;, etc).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>get_all_symbols $type_filter<\/b> <br \/> 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).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This is especially useful for debuggers and profilers, which use %DB::sub to determine where the source code for a subroutine can be found. See <http:\/\/perldoc.perl.org\/perldebguts.html#Debugger\u2212Internals> for more information about %DB::sub.<\/p>\n<h2>WORKING WITH VARIABLES <a name=\"WORKING WITH VARIABLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">It is important to note, that when working with scalar variables, the default behavior is to <b>copy<\/b> values.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">my $stash = Package::Stash\u2212>new(&#8216;Some::Namespace&#8217;); <br \/> my $variable = 1; <br \/> # $Some::Namespace::name is a copy of $variable <br \/> $stash\u2212>add_symbol(&#8216;$name&#8217;, $variable); <br \/> $variable++ <br \/> # $Some::Namespace::name == 1 , $variable == 2<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This will likely confuse people who expect it to work the same as typeglob assignment, which simply creates new references to existing variables.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">my $variable = 1; <br \/> { <br \/> no strict &#8216;refs&#8217;; <br \/> # assign $Package::Stash::name = $variable <br \/> *{&#8216;Package::Stash::name&#8217;} = $variable; <br \/> } <br \/> $variable++ # affects both names<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If this behaviour is desired when working with Package::Stash, simply pass Package::Stash a scalar ref:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">my $stash = Package::Stash\u2212>new(&#8216;Some::Namespace&#8217;); <br \/> my $variable = 1; <br \/> # $Some::Namespace::name is now $variable <br \/> $stash\u2212>add_symbol(&#8216;$name&#8217;, $variable); <br \/> $variable++ <br \/> # $Some::Namespace::name == 2 , $variable == 2<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This will be what you want as well if you\u2019re ever working with Readonly variables:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">use Readonly; <br \/> Readonly my $value, &#8216;hello&#8217;; <br \/> $stash\u2212>add_symbol(&#8216;$name&#8217;, $value); # reference <br \/> print $Some::Namespace::name; # hello <br \/> # Tries to modify the read\u2212only &#8216;hello&#8217; and dies. <br \/> $Some::Namespace::name .= &#8221; world&#8221;; <br \/> $stash\u2212>add_symbol(&#8216;$name&#8217;, $value); # copy <br \/> print $Some::Namespace::name; # hello <br \/> # No problem, modifying a copy, not the original <br \/> $Some::Namespace::name .= &#8221; world&#8221;;<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"29%\">\n<p style=\"margin-top: 1em\">Class::MOP::Package<\/p>\n<\/td>\n<td width=\"54%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%; margin-top: 1em\">This module is a factoring out of code that used to live here<\/p>\n<h2>HISTORY <a name=\"HISTORY\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Based on code from Class::MOP::Package, by Stevan Little and the Moose Cabal.<\/p>\n<h2>BUGS \/ CAVEATS <a name=\"BUGS \/ CAVEATS\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p style=\"margin-top: 1em\">Prior to perl 5.10, scalar slots are only considered to exist if they are defined<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%; margin-top: 1em\">This is due to a shortcoming within perl itself. See &#8220;Making References&#8221; in perlref point 7 for more information.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p style=\"margin-top: 1em\"><small>GLOB<\/small> and <small>FORMAT<\/small> variables are not (yet) accessible through this module.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p>Also, see the <small>BUGS<\/small> section for the specific backends (Package::Stash::XS and Package::Stash::PP)<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">Bugs may be submitted through the <small>RT<\/small> bug tracker <https:\/\/rt.cpan.org\/Public\/Dist\/Display.html?Name=Package-Stash> (or bug\u2212Package\u2212Stash@rt.cpan.org <mailto:bug-Package-Stash@rt.cpan.org>).<\/p>\n<h2>AUTHORS <a name=\"AUTHORS\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"71%\">\n<p style=\"margin-top: 1em\">Stevan Little <stevan.little@iinteractive.com><\/p>\n<\/td>\n<td width=\"12%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"71%\">\n<p>Jesse Luehrs <doy@tozt.net><\/p>\n<\/td>\n<td width=\"12%\"> <\/td>\n<\/tr>\n<\/table>\n<h2>CONTRIBUTORS <a name=\"CONTRIBUTORS\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"74%\">\n<p style=\"margin-top: 1em\">Karen Etheridge <ether@cpan.org><\/p>\n<\/td>\n<td width=\"9%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"74%\">\n<p>Carlos Lima <carlos@multi><\/p>\n<\/td>\n<td width=\"9%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"74%\">\n<p>Dave Rolsky <autarch@urth.org><\/p>\n<\/td>\n<td width=\"9%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"74%\">\n<p>Justin Hunter <justin.d.hunter@gmail.com><\/p>\n<\/td>\n<td width=\"9%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"74%\">\n<p>Christian Walde <walde.christian@googlemail.com><\/p>\n<\/td>\n<td width=\"9%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"74%\">\n<p>Kent Fredric <kentfredric@gmail.com><\/p>\n<\/td>\n<td width=\"9%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"74%\">\n<p>Niko Tyni <ntyni@debian.org><\/p>\n<\/td>\n<td width=\"9%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"74%\">\n<p>Renee <reb@perl\u2212services.de><\/p>\n<\/td>\n<td width=\"9%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"74%\">\n<p>Tim Bunce <Tim.Bunce@pobox.com><\/p>\n<\/td>\n<td width=\"9%\"> <\/td>\n<\/tr>\n<\/table>\n<h2>COPYRIGHT AND LICENSE <a name=\"COPYRIGHT AND LICENSE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This software is copyright (c) 2020 by Jesse Luehrs.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This is free software; you can redistribute it and\/or modify it under the same terms as the Perl 5 programming language system itself.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  Package::Stash \u2212 Routines for manipulating stashes <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3007,3067],"class_list":["post-6688","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-man3","tag-packagestash"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6688"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6688\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}