revert the vivication changes for now, i didn't mean to release them
[gitmo/Package-Stash-XS.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 {
44726d1a 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';
44726d1a 16 %Foo::foo;
a1c10d3a 17 }
18 BEGIN {
44726d1a 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},
44726d1a 24 "got the right variable");
a1c10d3a 25 }
d2d3faf4 26}
27
28{
a1c10d3a 29 BEGIN {
44726d1a 30 my $stash = Package::Stash->new('Bar');
a1c10d3a 31 my $val = $stash->get_package_symbol('@foo');
44726d1a 32 is($val, undef, "got something");
a1c10d3a 33 }
34 {
35 no warnings 'void', 'once';
44726d1a 36 @Bar::foo;
a1c10d3a 37 }
38 BEGIN {
44726d1a 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],
44726d1a 44 "got the right variable");
a1c10d3a 45 }
d2d3faf4 46}
47
e55803fc 48{
44726d1a 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},
44726d1a 54 "got the right variable");
e55803fc 55}
56
57{
44726d1a 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],
44726d1a 63 "got the right variable");
e55803fc 64}
65
d2d3faf4 66done_testing;