summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-01-03 19:40:07 -0600
committerJesse Luehrs <doy@tozt.net>2013-01-03 19:40:07 -0600
commit7ebef6b62f5be89ad75a37d849719a436c821a50 (patch)
tree85218839b2af8b9a7c7ea865f2969dadb01467aa
parent9cf1cab181cf771e28b272186fd0faa9877cc2ad (diff)
downloadpackage-stash-7ebef6b62f5be89ad75a37d849719a436c821a50.tar.gz
package-stash-7ebef6b62f5be89ad75a37d849719a436c821a50.zip
fix add_symbol with no value
-rw-r--r--lib/Package/Stash/PP.pm55
1 files changed, 29 insertions, 26 deletions
diff --git a/lib/Package/Stash/PP.pm b/lib/Package/Stash/PP.pm
index 9c8e924..2508052 100644
--- a/lib/Package/Stash/PP.pm
+++ b/lib/Package/Stash/PP.pm
@@ -198,6 +198,34 @@ sub add_symbol {
*{ $namespace->{$name} } = ref $initial_value
? $initial_value : \$initial_value;
}
+ else {
+ return if BROKEN_ISA_ASSIGNMENT && $name eq 'ISA';
+ *{ $namespace->{$name} } = $self->_undef_ref_for_type($type);
+ }
+ }
+}
+
+sub _undef_ref_for_type {
+ my $self = shift;
+ my ($type) = @_;
+
+ if ($type eq 'ARRAY') {
+ return [];
+ }
+ elsif ($type eq 'HASH') {
+ return {};
+ }
+ elsif ($type eq 'SCALAR') {
+ return \undef;
+ }
+ elsif ($type eq 'IO') {
+ return Symbol::geniosym;
+ }
+ elsif ($type eq 'CODE') {
+ confess "Don't know how to vivify CODE variables";
+ }
+ else {
+ confess "Unknown type $type in vivication";
}
}
@@ -245,32 +273,7 @@ sub get_symbol {
if (!exists $namespace->{$name}) {
if ($opts{vivify}) {
- if ($type eq 'ARRAY') {
- if (BROKEN_ISA_ASSIGNMENT) {
- $self->add_symbol(
- $variable,
- $name eq 'ISA' ? () : ([])
- );
- }
- else {
- $self->add_symbol($variable, []);
- }
- }
- elsif ($type eq 'HASH') {
- $self->add_symbol($variable, {});
- }
- elsif ($type eq 'SCALAR') {
- $self->add_symbol($variable);
- }
- elsif ($type eq 'IO') {
- $self->add_symbol($variable, Symbol::geniosym);
- }
- elsif ($type eq 'CODE') {
- confess "Don't know how to vivify CODE variables";
- }
- else {
- confess "Unknown type $type in vivication";
- }
+ $self->add_symbol($variable);
}
else {
return undef;