Package::Localize - localize package variables in other packages
Say you've got this pesky package someone wrote that decided to use globals:
package Foo; our $var = 42; sub inc { $var++ }
Whenever you call Foo::inc(), it'll always be increasing that $var, even if you call it from different places. Package::Localize to the rescue:
Foo::inc()
$var
Package::Localize
my $p1 = Package::Localize->new('Foo'); my $p2 = Package::Localize->new('Foo'); say $p1->inc; # prints 42 say $p1->inc; # prints 43 say $p2->inc; # prints 42
This module allows you to use multple instances of packages that have package variables operated by the functions the module offers.
Currently there is no support for OO modules; functions only.
new
my $p1 = Package::Localize->new('Foo');
Takes one mandatory argument which is the name of the package you want to localize.
Returns an object. Call functions from your original package as methods on this object to operate on localizes package variables only.
name
my $name = $p1->name; no strict 'refs'; my $p1_var = ${"$name::var"};
Returns the name of the localized package.
Currently there is no support for OO modules; functions only. Patches are definitely welcome though.
Package::Stash
Fork this module on GitHub: https://github.com/zoffixznet/Package-Localize
To report bugs or request features, please use https://github.com/zoffixznet/Package-Localize/issues
If you can't access GitHub, you can email your request to bug-Package-Localize at rt.cpan.org
bug-Package-Localize at rt.cpan.org
You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.
LICENSE
To install Package::Localize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Package::Localize
CPAN shell
perl -MCPAN -e shell install Package::Localize
For more information on module installation, please visit the detailed CPAN module installation guide.