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");
93 seek($stash->get_package_symbol('FOO'), 0, 0);
96 ::isa_ok(*FOO{IO}, 'IO');
98 "stash has the right variable");
104 # making TODO tests at a mixture of BEGIN and runtime is irritating
106 BEGIN { $_TODO = "obviously I don't understand this well enough"; }
107 BEGIN { $TODO = $_TODO; }
110 my $stash = Package::Stash->new('Code');
111 my $val = $stash->get_package_symbol('&foo');
112 is($val, undef, "got nothing yet");
115 no warnings 'void', 'once';
119 my $stash = Package::Stash->new('Code');
120 my $val = $stash->get_package_symbol('&foo');
122 is(ref($val), 'CODE', "got something");
125 eval "require PadWalker"
126 or skip "needs PadWalker", 1;
127 # avoid padwalker segfault
128 if (!defined($val)) {
129 fail("got the right variable");
132 PadWalker::set_closed_over($val, {'$x' => 1});
133 is_deeply({PadWalker::closed_over($stash->get_package_symbol('&foo'))}, {'$x' => 1},
134 "got the right variable");
135 is_deeply({PadWalker::closed_over(\&Code::foo)}, {'$x' => 1},
136 "stash has the right variable");
140 BEGIN { undef $TODO; }
145 my $stash = Package::Stash->new('Hash::Vivify');
146 my $val = $stash->get_or_add_package_symbol('%foo');
147 is(ref($val), 'HASH', "got something");
149 is_deeply($stash->get_or_add_package_symbol('%foo'), {bar => 1},
150 "got the right variable");
152 is_deeply(\%Hash::Vivify::foo, {bar => 1},
153 "stash has the right variable");
157 my $stash = Package::Stash->new('Array::Vivify');
158 my $val = $stash->get_or_add_package_symbol('@foo');
159 is(ref($val), 'ARRAY', "got something");
161 is_deeply($stash->get_or_add_package_symbol('@foo'), [1],
162 "got the right variable");
164 is_deeply(\@Array::Vivify::foo, [1],
165 "stash has the right variable");
169 my $stash = Package::Stash->new('Scalar::Vivify');
170 my $val = $stash->get_or_add_package_symbol('$foo');
171 is(ref($val), 'SCALAR', "got something");
173 is_deeply($stash->get_or_add_package_symbol('$foo'), \1,
174 "got the right variable");
176 is($Scalar::Vivify::foo, 1,
177 "stash has the right variable");
182 my $stash = Package::Stash->new('Io::Vivify');
183 my $val = $stash->get_or_add_package_symbol('FOO');
186 open $val, '<', \$str;
187 is(readline($stash->get_package_symbol('FOO')), "foo",
188 "got the right variable");
189 seek($stash->get_package_symbol('FOO'), 0, 0);
194 ::isa_ok(*FOO{IO}, 'IO');
196 "stash has the right variable");