summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Package/Stash.pm17
-rw-r--r--t/004-get.t46
2 files changed, 35 insertions, 28 deletions
diff --git a/lib/Package/Stash.pm b/lib/Package/Stash.pm
index 6f0910c..6b95340 100644
--- a/lib/Package/Stash.pm
+++ b/lib/Package/Stash.pm
@@ -235,22 +235,7 @@ 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 ($type eq 'ARRAY' && $name ne 'ISA') {
- $self->add_package_symbol($variable, []);
- }
- elsif ($type eq 'HASH') {
- $self->add_package_symbol($variable, {});
- }
- else {
- # FIXME
- $self->add_package_symbol($variable)
- }
+ $self->add_package_symbol($variable)
}
my $entry_ref = \$namespace->{$name};
diff --git a/t/004-get.t b/t/004-get.t
index 15e252f..89d7567 100644
--- a/t/004-get.t
+++ b/t/004-get.t
@@ -6,21 +6,43 @@ use Test::More;
use Package::Stash;
{
- my $stash = Package::Stash->new('Foo');
- my $val = $stash->get_package_symbol('%foo');
- is(ref($val), 'HASH', "got something");
- $val->{bar} = 1;
- is_deeply($stash->get_package_symbol('%foo'), {bar => 1},
- "got the right variable");
+ BEGIN {
+ my $stash = Package::Stash->new('Foo');
+ my $val = $stash->get_package_symbol('%foo');
+ is($val, undef, "got nothing yet");
+ }
+ {
+ no warnings 'void', 'once';
+ %Foo::foo;
+ }
+ BEGIN {
+ my $stash = Package::Stash->new('Foo');
+ my $val = $stash->get_package_symbol('%foo');
+ is(ref($val), 'HASH', "got something");
+ $val->{bar} = 1;
+ is_deeply($stash->get_package_symbol('%foo'), {bar => 1},
+ "got the right variable");
+ }
}
{
- my $stash = Package::Stash->new('Bar');
- my $val = $stash->get_package_symbol('@foo');
- is(ref($val), 'ARRAY', "got something");
- push @$val, 1;
- is_deeply($stash->get_package_symbol('@foo'), [1],
- "got the right variable");
+ BEGIN {
+ my $stash = Package::Stash->new('Bar');
+ my $val = $stash->get_package_symbol('@foo');
+ is($val, undef, "got something");
+ }
+ {
+ no warnings 'void', 'once';
+ @Bar::foo;
+ }
+ BEGIN {
+ my $stash = Package::Stash->new('Bar');
+ my $val = $stash->get_package_symbol('@foo');
+ is(ref($val), 'ARRAY', "got something");
+ push @$val, 1;
+ is_deeply($stash->get_package_symbol('@foo'), [1],
+ "got the right variable");
+ }
}
done_testing;