Commit | Line | Data |
25c87f5c |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
2905fb35 |
4 | use lib 't/lib'; |
25c87f5c |
5 | use Test::More; |
6 | |
7 | use Package::Stash; |
8 | |
9 | { |
10 | package Foo; |
11 | use constant FOO => 1; |
12 | use constant BAR => \1; |
13 | use constant BAZ => []; |
14 | use constant QUUX => {}; |
15 | use constant QUUUX => sub { }; |
16 | sub normal { } |
17 | sub stub; |
18 | sub normal_with_proto () { } |
19 | sub stub_with_proto (); |
20 | |
21 | our $SCALAR; |
f7543739 |
22 | our $SCALAR_WITH_VALUE = 1; |
25c87f5c |
23 | our @ARRAY; |
24 | our %HASH; |
25 | } |
26 | |
27 | my $stash = Package::Stash->new('Foo'); |
2905fb35 |
28 | { local $TODO = ($] < 5.010 || $Package::Stash::IMPLEMENTATION eq 'PP') |
29 | ? "undef scalars aren't visible on 5.8, or from pure perl at all" |
30 | : undef; |
31 | ok($stash->has_symbol('$SCALAR'), '$SCALAR'); |
f7543739 |
32 | } |
2905fb35 |
33 | ok($stash->has_symbol('$SCALAR_WITH_VALUE'), '$SCALAR_WITH_VALUE'); |
34 | ok($stash->has_symbol('@ARRAY'), '@ARRAY'); |
35 | ok($stash->has_symbol('%HASH'), '%HASH'); |
25c87f5c |
36 | is_deeply( |
2905fb35 |
37 | [sort $stash->list_all_symbols('CODE')], |
25c87f5c |
38 | [qw(BAR BAZ FOO QUUUX QUUX normal normal_with_proto stub stub_with_proto)], |
39 | "can see all code symbols" |
40 | ); |
41 | |
2905fb35 |
42 | $stash->add_symbol('%added', {}); |
43 | ok(!$stash->has_symbol('$added'), '$added'); |
44 | ok(!$stash->has_symbol('@added'), '@added'); |
45 | ok($stash->has_symbol('%added'), '%added'); |
46 | |
47 | my $constant = $stash->get_symbol('&FOO'); |
48 | is(ref($constant), 'CODE', "expanded a constant into a coderef"); |
f7543739 |
49 | |
4723417a |
50 | # ensure get doesn't prevent subsequent vivification (not sure what the deal |
51 | # was here) |
52 | is(ref($stash->get_symbol('$glob')), '', "nothing yet"); |
53 | is(ref($stash->get_or_add_symbol('$glob')), 'SCALAR', "got an empty scalar"); |
54 | |
25c87f5c |
55 | done_testing; |