ebeb8647c4626e25320f71a4d0d7312c9ccd3a65
[gitmo/Package-Stash.git] / t / 04-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 {
49     my $stash = Package::Stash->new('Baz');
50     my $val = $stash->get_or_add_package_symbol('%foo');
51     is(ref($val), 'HASH', "got something");
52     $val->{bar} = 1;
53     is_deeply($stash->get_or_add_package_symbol('%foo'), {bar => 1},
54             "got the right variable");
55 }
56
57 {
58     my $stash = Package::Stash->new('Quux');
59     my $val = $stash->get_or_add_package_symbol('@foo');
60     is(ref($val), 'ARRAY', "got something");
61     push @$val, 1;
62     is_deeply($stash->get_or_add_package_symbol('@foo'), [1],
63             "got the right variable");
64 }
65
66 done_testing;