summaryrefslogtreecommitdiffstats
path: root/lib/Package/Stash.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-10-31 11:04:51 -0500
committerJesse Luehrs <doy@tozt.net>2010-10-31 11:04:51 -0500
commitdc378b60e595186cddf0b2ce35da3e6749022770 (patch)
treedd667f647877f1f4518c2caab8550b29022ad75e /lib/Package/Stash.pm
parentc7f0ea46eaf630b6660e32d2cc5e7a9759bb46cf (diff)
downloadpackage-stash-dc378b60e595186cddf0b2ce35da3e6749022770.tar.gz
package-stash-dc378b60e595186cddf0b2ce35da3e6749022770.zip
Revert "revert vivication changes for now again"
This reverts commit 67b1704808e62f27210fe992df9c45b232fe9d5b. Conflicts: Changes
Diffstat (limited to 'lib/Package/Stash.pm')
-rw-r--r--lib/Package/Stash.pm51
1 files changed, 38 insertions, 13 deletions
diff --git a/lib/Package/Stash.pm b/lib/Package/Stash.pm
index 32e5d30..6c361c1 100644
--- a/lib/Package/Stash.pm
+++ b/lib/Package/Stash.pm
@@ -5,6 +5,10 @@ use warnings;
use Carp qw(confess);
use Scalar::Util qw(reftype);
+use Symbol;
+# before 5.12, assigning to the ISA glob would make it lose its magical ->isa
+# powers
+use constant BROKEN_ISA_ASSIGNMENT => ($] < 5.012);
=head1 SYNOPSIS
@@ -230,21 +234,42 @@ sub get_package_symbol {
my $namespace = $self->namespace;
if (!exists $namespace->{$name}) {
- # assigning to the result of this function like
- # @{$stash->get_package_symbol('@ISA')} = @new_ISA
- # makes the result not visible until the variable is explicitly
- # accessed... in the case of @ISA, this might never happen
- # for instance, assigning like that and then calling $obj->isa
- # will fail. see t/005-isa.t
- if ($opts{vivify} && $type eq 'ARRAY' && $name ne 'ISA') {
- $self->add_package_symbol($variable, []);
- }
- elsif ($opts{vivify} && $type eq 'HASH') {
- $self->add_package_symbol($variable, {});
+ if ($opts{vivify}) {
+ if ($type eq 'ARRAY') {
+ if (BROKEN_ISA_ASSIGNMENT) {
+ $self->add_package_symbol(
+ $variable,
+ $name eq 'ISA' ? () : ([])
+ );
+ }
+ else {
+ $self->add_package_symbol($variable, []);
+ }
+ }
+ elsif ($type eq 'HASH') {
+ $self->add_package_symbol($variable, {});
+ }
+ elsif ($type eq 'SCALAR') {
+ $self->add_package_symbol($variable);
+ }
+ elsif ($type eq 'IO') {
+ $self->add_package_symbol($variable, Symbol::geniosym);
+ }
+ elsif ($type eq 'CODE') {
+ confess "Don't know how to vivify CODE variables";
+ }
+ else {
+ confess "Unknown type $type in vivication";
+ }
}
else {
- # FIXME
- $self->add_package_symbol($variable)
+ if ($type eq 'CODE') {
+ # this effectively "de-vivifies" the code slot. if we don't do
+ # this, referencing the coderef at the end of this function
+ # will cause perl to auto-vivify a stub coderef in the slot,
+ # which isn't what we want
+ $self->add_package_symbol($variable);
+ }
}
}