From: Jesse Luehrs Date: Fri, 27 Aug 2010 16:15:51 +0000 (-0500) Subject: make the ISA special-casing more sane X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f8e7797c12671e47664c32b6c00b5ee4c8993504;p=gitmo%2FPackage-Stash-PP.git make the ISA special-casing more sane --- diff --git a/lib/Package/Stash.pm b/lib/Package/Stash.pm index 32e5d30..b990f55 100644 --- a/lib/Package/Stash.pm +++ b/lib/Package/Stash.pm @@ -229,17 +229,16 @@ 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, []); + 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 ($opts{vivify} && $type eq 'HASH') { + elsif ($type eq 'HASH') { $self->add_package_symbol($variable, {}); } else { diff --git a/t/05-isa.t b/t/05-isa.t index 3198fb1..0b41b72 100644 --- a/t/05-isa.t +++ b/t/05-isa.t @@ -15,7 +15,7 @@ use Package::Stash; my $stash = Package::Stash->new('Foo'); my @ISA = ('Bar'); -@{$stash->get_package_symbol('@ISA')} = @ISA; +@{$stash->get_or_add_package_symbol('@ISA')} = @ISA; isa_ok('Foo', 'Bar'); done_testing;