8 use Variable::Magic qw/wizard cast dispell VMG_UVAR VMG_OP_INFO_NAME VMG_OP_INFO_OBJECT/;
15 plan skip_all => 'uvar magic is required to test symbol table hooks';
21 . join (', ', map { <<CB;
24 return 0 if \$d->{guard};
25 local \$d->{guard} = 1;
26 push \@{\$mg{$_}}, \$_[2];
30 } qw/fetch store exists delete/);
32 $code .= ', data => sub { +{ guard => 0 } }';
48 our $what = @Hlagh::stuff;
52 is $@, "ok\n", 'stash: variables compiled fine';
54 fetch => [ qw/thing stuff/ ],
55 store => [ qw/thing stuff/ ],
56 }, 'stash: variables';
71 is $@, "ok\n", 'stash: function definitions compiled fine';
73 store => [ qw/eat shoot leave shoot/ ],
74 }, 'stash: function definitions';
91 my @calls = qw/eat shoot leave roam yawn roam/;
93 is $@, "ok\n", 'stash: function calls compiled fine';
96 store => ($] < 5.011002 ? \@calls : [ map { ($_) x 2 } @calls ]),
97 }, 'stash: function calls';
103 eval q{ Hlagh->shoot() };
105 is $@, '', 'stash: valid method call ran fine';
107 fetch => [ qw/shoot/ ],
108 }, 'stash: valid method call';
114 eval q{ Hlagh->shoot() };
116 is $@, '', 'stash: second valid method call ran fine';
118 fetch => [ qw/shoot/ ],
119 }, 'stash: second valid method call';
125 eval q{ my $meth = 'shoot'; Hlagh->$meth() };
127 is $@, '', 'stash: valid dynamic method call ran fine';
129 store => [ qw/shoot/ ],
130 }, 'stash: valid dynamic method call';
139 BEGIN { @ISA = 'Hlagh' }
143 is $@, '', 'inherited valid method call ran fine';
145 fetch => [ qw/ISA leave/ ],
146 }, 'stash: inherited valid method call';
152 eval q{ Hlagher->leave() };
154 is $@, '', 'second inherited valid method call ran fine';
155 is_deeply \%mg, { }, 'stash: second inherited valid method call doesn\'t call magic';
161 eval q{ Hlagher->shoot() };
163 is $@, '', 'inherited previously called valid method call ran fine';
165 fetch => [ qw/shoot/ ],
166 }, 'stash: inherited previously called valid method call';
172 eval q{ Hlagher->shoot() };
174 is $@, '', 'second inherited previously called valid method call ran fine';
175 is_deeply \%mg, { }, 'stash: second inherited previously called valid method call doesn\'t call magic';
181 eval q{ Hlagh->unknown() };
183 like $@, qr/^Can't locate object method "unknown" via package "Hlagh"/, 'stash: invalid method call croaked';
185 fetch => [ qw/unknown/ ],
186 store => [ qw/unknown AUTOLOAD/ ],
187 }, 'stash: invalid method call';
193 eval q{ my $meth = 'unknown_too'; Hlagh->$meth() };
195 like $@, qr/^Can't locate object method "unknown_too" via package "Hlagh"/, 'stash: invalid dynamic method call croaked';
197 store => [ qw/unknown_too AUTOLOAD/ ],
198 }, 'stash: invalid dynamic method call';
204 eval q{ Hlagher->also_unknown() };
206 like $@, qr/^Can't locate object method "also_unknown" via package "Hlagher"/, 'stash: invalid inherited method call croaked';
208 fetch => [ qw/also_unknown AUTOLOAD/ ],
209 }, 'stash: invalid method call';
217 undef &nevermentioned;
222 is $@, '', 'stash: delete executed fine';
225 qw/nevermentioned nevermentioned eat eat shoot shoot nevermentioned/
231 is_deeply \%mg, { }, 'stash: magic that remains at END time' if $run;
234 dispell %Hlagh::, $wiz;
239 use vars qw/$AUTOLOAD/;
241 sub AUTOLOAD { return $AUTOLOAD }
244 cast %AutoHlagh::, $wiz;
249 my $res = eval q{ AutoHlagh->autoloaded() };
251 is $@, '', 'stash: autoloaded method call ran fine';
252 is $res, 'AutoHlagh::autoloaded',
253 'stash: autoloaded method call returned the right thing';
255 fetch => [ qw/autoloaded/ ],
256 store => [ qw/autoloaded AUTOLOAD AUTOLOAD/ ],
257 }, 'stash: autoloaded method call';
264 BEGIN { @ISA = ('AutoHlagh') }
270 my $res = eval q{ AutoHlagher->also_autoloaded() };
272 is $@, '', 'stash: inherited autoloaded method call ran fine';
273 is $res, 'AutoHlagher::also_autoloaded',
274 'stash: inherited autoloaded method returned the right thing';
276 fetch => [ qw/also_autoloaded AUTOLOAD/ ],
277 store => [ qw/AUTOLOAD/ ],
278 }, 'stash: inherited autoloaded method call';
281 dispell %AutoHlagh::, $wiz;
285 . join (', ', map { <<CB;
288 return 0 if \$d->{guard};
289 local \$d->{guard} = 1;
294 } qw/fetch store exists delete/);
296 my $uo_exp = $] < 5.011002 ? 2 : 3;
298 $code .= ', data => sub { +{ guard => 0 } }';
300 $wiz = eval $code . ', op_info => ' . VMG_OP_INFO_NAME;
305 is $uo, 0, 'stash: no undef op before function call with op name';
311 is $@, "ok\n", 'stash: function call with op name compiled fine';
312 is $uo, $uo_exp, 'stash: undef op after function call with op name';
314 dispell %Hlagh::, $wiz;
315 is $uo, $uo_exp, 'stash: undef op after dispell for function call with op name';
319 $wiz = eval $code . ', op_info => ' . VMG_OP_INFO_OBJECT;
324 is $uo, 0, 'stash: no undef op before function call with op object';
330 is $@, "ok\n", 'stash: function call with op object compiled fine';
332 'stash: undef op after dispell for function call with op object';
334 dispell %Hlagh::, $wiz;
336 'stash: undef op after dispell for function call with op object';