stop autovivifying on get
[gitmo/Package-Stash-PP.git] / t / 004-get.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More;
5
6 use Package::Stash;
7
8 {
9     BEGIN {
10         my $stash = Package::Stash->new('Foo');
11         my $val = $stash->get_package_symbol('%foo');
12         is($val, undef, "got nothing yet");
13     }
14     {
15         no warnings 'void', 'once';
16         %Foo::foo;
17     }
18     BEGIN {
19         my $stash = Package::Stash->new('Foo');
20         my $val = $stash->get_package_symbol('%foo');
21         is(ref($val), 'HASH', "got something");
22         $val->{bar} = 1;
23         is_deeply($stash->get_package_symbol('%foo'), {bar => 1},
24                 "got the right variable");
25     }
26 }
27
28 {
29     BEGIN {
30         my $stash = Package::Stash->new('Bar');
31         my $val = $stash->get_package_symbol('@foo');
32         is($val, undef, "got something");
33     }
34     {
35         no warnings 'void', 'once';
36         @Bar::foo;
37     }
38     BEGIN {
39         my $stash = Package::Stash->new('Bar');
40         my $val = $stash->get_package_symbol('@foo');
41         is(ref($val), 'ARRAY', "got something");
42         push @$val, 1;
43         is_deeply($stash->get_package_symbol('@foo'), [1],
44                 "got the right variable");
45     }
46 }
47
48 done_testing;