From e55970bce6430bcc6cd014bc46983c100f660e79 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 26 Aug 2010 22:13:30 -0500 Subject: cache the ref to the stash --- lib/Package/Stash.pm | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'lib') 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}; } { -- cgit v1.2.3-54-g00ecf