summaryrefslogtreecommitdiffstats
path: root/t/004-get.t
blob: 89d75675cd40a18421d6438652fcd10aec1adba7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

use Package::Stash;

{
    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");
    }
}

{
    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;