revert vivication changes for now again
[gitmo/Package-Stash-PP.git] / t / 04-get.t
CommitLineData
d2d3faf4 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5
e94260da 6use Package::Stash;
d2d3faf4 7
8{
a1c10d3a 9 BEGIN {
67b17048 10 my $stash = Package::Stash->new('Foo');
a1c10d3a 11 my $val = $stash->get_package_symbol('%foo');
12 is($val, undef, "got nothing yet");
13 }
14 {
15 no warnings 'void', 'once';
67b17048 16 %Foo::foo;
a1c10d3a 17 }
18 BEGIN {
67b17048 19 my $stash = Package::Stash->new('Foo');
a1c10d3a 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},
67b17048 24 "got the right variable");
a1c10d3a 25 }
d2d3faf4 26}
27
28{
a1c10d3a 29 BEGIN {
67b17048 30 my $stash = Package::Stash->new('Bar');
a1c10d3a 31 my $val = $stash->get_package_symbol('@foo');
67b17048 32 is($val, undef, "got something");
a1c10d3a 33 }
34 {
35 no warnings 'void', 'once';
67b17048 36 @Bar::foo;
a1c10d3a 37 }
38 BEGIN {
67b17048 39 my $stash = Package::Stash->new('Bar');
a1c10d3a 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],
67b17048 44 "got the right variable");
5d3589c8 45 }
46}
47
5d3589c8 48{
67b17048 49 my $stash = Package::Stash->new('Baz');
e55803fc 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},
67b17048 54 "got the right variable");
e55803fc 55}
56
57{
67b17048 58 my $stash = Package::Stash->new('Quux');
e55803fc 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],
67b17048 63 "got the right variable");
e55803fc 64}
65
d2d3faf4 66done_testing;