summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-09-22 13:10:28 -0500
committerJesse Luehrs <doy@tozt.net>2010-09-22 13:10:28 -0500
commit7486ccf34361fccfb1599d244961ddbd3d8bc5a7 (patch)
tree6c4ef8b032e8415e9a4caba39208934168a6c0e6 /lib
parent764032903d595e45c8f792bac361c1c97a36a382 (diff)
downloadpackage-stash-xs-7486ccf34361fccfb1599d244961ddbd3d8bc5a7.tar.gz
package-stash-xs-7486ccf34361fccfb1599d244961ddbd3d8bc5a7.zip
fix coderef vivification
Diffstat (limited to 'lib')
-rw-r--r--lib/Package/Stash.pm56
1 files changed, 32 insertions, 24 deletions
diff --git a/lib/Package/Stash.pm b/lib/Package/Stash.pm
index 77236d0..f708bbc 100644
--- a/lib/Package/Stash.pm
+++ b/lib/Package/Stash.pm
@@ -230,32 +230,40 @@ sub get_package_symbol {
my $namespace = $self->namespace;
- if ($opts{vivify} && !exists $namespace->{$name}) {
- if ($type eq 'ARRAY') {
- $self->add_package_symbol(
- $variable,
- # setting our own arrayref manually loses the magicalness or
- # something
- $name eq 'ISA' ? () : ([])
- );
- }
- 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') {
- # ignoring this case for now, since i don't know what would
- # be useful to do here (and subs in the stash autovivify in weird
- # ways too)
- #$self->add_package_symbol($variable, sub {});
+ if (!exists $namespace->{$name}) {
+ if ($opts{vivify}) {
+ if ($type eq 'ARRAY') {
+ $self->add_package_symbol(
+ $variable,
+ # setting our own arrayref manually loses the magicalness
+ # or something
+ $name eq 'ISA' ? () : ([])
+ );
+ }
+ 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 {
- confess "Unknown type $type in vivication";
+ 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);
+ }
}
}