summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-08-26 22:13:30 -0500
committerJesse Luehrs <doy@tozt.net>2010-08-26 22:31:13 -0500
commite55970bce6430bcc6cd014bc46983c100f660e79 (patch)
treee3b33ec08ad5f9a81b54734d84566c672d707352
parent0992f4ec5d71393517317327dd3164ad6b17a24c (diff)
downloadpackage-stash-e55970bce6430bcc6cd014bc46983c100f660e79.tar.gz
package-stash-e55970bce6430bcc6cd014bc46983c100f660e79.zip
cache the ref to the stash
-rw-r--r--lib/Package/Stash.pm24
-rw-r--r--t/02-extension.t7
2 files changed, 18 insertions, 13 deletions
diff --git a/lib/Package/Stash.pm b/lib/Package/Stash.pm
index d81c96e..32e5d30 100644
--- a/lib/Package/Stash.pm
+++ b/lib/Package/Stash.pm
@@ -33,8 +33,18 @@ argument.
sub new {
my $class = shift;
- my ($namespace) = @_;
- return bless { 'package' => $namespace }, $class;
+ my ($package) = @_;
+ my $namespace;
+ {
+ no strict 'refs';
+ # supposedly this caused a bug in earlier perls, but I can't reproduce
+ # it, so re-enabling the caching
+ $namespace = \%{$package . '::'};
+ }
+ return bless {
+ 'package' => $package,
+ 'namespace' => $namespace,
+ }, $class;
}
=method name
@@ -54,15 +64,7 @@ Returns the raw stash itself.
=cut
sub namespace {
- # NOTE:
- # because of issues with the Perl API
- # to the typeglob in some versions, we
- # need to just always grab a new
- # reference to the hash here. Ideally
- # we could just store a ref and it would
- # Just Work, but oh well :\
- no strict 'refs';
- return \%{$_[0]->name . '::'};
+ return $_[0]->{namespace};
}
{
diff --git a/t/02-extension.t b/t/02-extension.t
index 2f95f15..f639cfa 100644
--- a/t/02-extension.t
+++ b/t/02-extension.t
@@ -13,8 +13,11 @@ use Test::Exception;
use Symbol 'gensym';
- sub namespace {
- $_[0]->{namespace} ||= {}
+ sub new {
+ my $class = shift;
+ my $self = $class->SUPER::new(@_);
+ $self->{namespace} = {};
+ return $self;
}
sub add_package_symbol {