Why not adopt me?
NAME
Package::Localize - localize package variables in other packages
SYNOPSIS
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:
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
DESCRIPTION
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.
METHODS
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.
BUGS AND CAVEATS
Currently there is no support for OO modules; functions only. Patches are definitely welcome though.
SEE ALSO
REPOSITORY
Fork this module on GitHub: https://github.com/zoffixznet/Package-Localize
BUGS
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
AUTHOR
LICENSE
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.