10 my $stash = Package::Stash->new('Hash');
11 my $val = $stash->get_package_symbol('%foo');
12 is($val, undef, "got nothing yet");
15 no warnings 'void', 'once';
19 my $stash = Package::Stash->new('Hash');
20 my $val = $stash->get_package_symbol('%foo');
21 is(ref($val), 'HASH', "got something");
23 is_deeply($stash->get_package_symbol('%foo'), {bar => 1},
24 "got the right variable");
25 is_deeply(\%Hash::foo, {bar => 1},
26 "stash has the right variable");
32 my $stash = Package::Stash->new('Array');
33 my $val = $stash->get_package_symbol('@foo');
34 is($val, undef, "got nothing yet");
37 no warnings 'void', 'once';
41 my $stash = Package::Stash->new('Array');
42 my $val = $stash->get_package_symbol('@foo');
43 is(ref($val), 'ARRAY', "got something");
45 is_deeply($stash->get_package_symbol('@foo'), [1],
46 "got the right variable");
47 is_deeply(\@Array::foo, [1],
48 "stash has the right variable");
54 my $stash = Package::Stash->new('Scalar');
55 my $val = $stash->get_package_symbol('$foo');
56 is($val, undef, "got nothing yet");
59 no warnings 'void', 'once';
63 my $stash = Package::Stash->new('Scalar');
64 my $val = $stash->get_package_symbol('$foo');
65 is(ref($val), 'SCALAR', "got something");
67 is_deeply($stash->get_package_symbol('$foo'), \1,
68 "got the right variable");
70 "stash has the right variable");
76 my $stash = Package::Stash->new('Io');
77 my $val = $stash->get_package_symbol('FOO');
78 is($val, undef, "got nothing yet");
81 no warnings 'void', 'once';
86 my $stash = Package::Stash->new('Io');
87 my $val = $stash->get_package_symbol('FOO');
90 open $val, '<', \$str;
91 is(readline($stash->get_package_symbol('FOO')), "foo",
92 "got the right variable");
95 ::isa_ok(*FOO{IO}, 'IO');
101 # making TODO tests at a mixture of BEGIN and runtime is irritating
103 BEGIN { $_TODO = "obviously I don't understand this well enough"; }
104 BEGIN { $TODO = $_TODO; }
107 my $stash = Package::Stash->new('Code');
108 my $val = $stash->get_package_symbol('&foo');
109 is($val, undef, "got nothing yet");
112 no warnings 'void', 'once';
116 my $stash = Package::Stash->new('Code');
117 my $val = $stash->get_package_symbol('&foo');
119 is(ref($val), 'CODE', "got something");
122 eval "require PadWalker"
123 or skip "needs PadWalker", 1;
124 # avoid padwalker segfault
125 if (!defined($val)) {
126 fail("got the right variable");
129 PadWalker::set_closed_over($val, {'$x' => 1});
130 is_deeply({PadWalker::closed_over($stash->get_package_symbol('&foo'))}, {'$x' => 1},
131 "got the right variable");
132 is_deeply({PadWalker::closed_over(\&Code::foo)}, {'$x' => 1},
133 "stash has the right variable");
137 BEGIN { undef $TODO; }
142 my $stash = Package::Stash->new('Hash::Vivify');
143 my $val = $stash->get_or_add_package_symbol('%foo');
144 is(ref($val), 'HASH', "got something");
146 is_deeply($stash->get_or_add_package_symbol('%foo'), {bar => 1},
147 "got the right variable");
149 is_deeply(\%Hash::Vivify::foo, {bar => 1},
150 "stash has the right variable");
154 my $stash = Package::Stash->new('Array::Vivify');
155 my $val = $stash->get_or_add_package_symbol('@foo');
156 is(ref($val), 'ARRAY', "got something");
158 is_deeply($stash->get_or_add_package_symbol('@foo'), [1],
159 "got the right variable");
161 is_deeply(\@Array::Vivify::foo, [1],
162 "stash has the right variable");
166 my $stash = Package::Stash->new('Scalar::Vivify');
167 my $val = $stash->get_or_add_package_symbol('$foo');
168 is(ref($val), 'SCALAR', "got something");
170 is_deeply($stash->get_or_add_package_symbol('$foo'), \1,
171 "got the right variable");
173 is($Scalar::Vivify::foo, 1,
174 "stash has the right variable");
179 my $stash = Package::Stash->new('Io::Vivify');
180 my $val = $stash->get_or_add_package_symbol('FOO');
183 open $val, '<', \$str;
184 is(readline($stash->get_package_symbol('FOO')), "foo",
185 "got the right variable");
190 ::isa_ok(*FOO{IO}, 'IO');