8 use Variable::Magic qw<
10 VMG_UVAR VMG_OP_INFO_NAME VMG_OP_INFO_OBJECT
18 plan skip_all => 'uvar magic is required to test symbol table hooks';
24 . join (', ', map { <<CB;
27 return 0 if \$d->{guard};
28 local \$d->{guard} = 1;
29 push \@{\$mg{$_}}, \$_[2];
33 } qw<fetch store exists delete>);
35 $code .= ', data => sub { +{ guard => 0 } }';
51 our $what = @Hlagh::stuff;
55 is $@, "ok\n", 'stash: variables compiled fine';
57 fetch => [ qw<thing stuff> ],
58 store => [ qw<thing stuff> ],
59 }, 'stash: variables';
74 is $@, "ok\n", 'stash: function definitions compiled fine';
76 store => [ qw<eat shoot leave shoot> ],
77 }, 'stash: function definitions';
94 my @calls = qw<eat shoot leave roam yawn roam>;
96 is $@, "ok\n", 'stash: function calls compiled fine';
99 store => ("$]" < 5.011002 ? \@calls : [ map { ($_) x 2 } @calls ]),
100 }, 'stash: function calls';
106 eval q{ Hlagh->shoot() };
108 is $@, '', 'stash: valid method call ran fine';
110 fetch => [ qw<shoot> ],
111 }, 'stash: valid method call';
117 eval q{ Hlagh->shoot() };
119 is $@, '', 'stash: second valid method call ran fine';
121 fetch => [ qw<shoot> ],
122 }, 'stash: second valid method call';
128 eval q{ my $meth = 'shoot'; Hlagh->$meth() };
130 is $@, '', 'stash: valid dynamic method call ran fine';
132 store => [ qw<shoot> ],
133 }, 'stash: valid dynamic method call';
142 BEGIN { @ISA = 'Hlagh' }
146 is $@, '', 'inherited valid method call ran fine';
148 fetch => [ qw<ISA leave> ],
149 }, 'stash: inherited valid method call';
155 eval q{ Hlagher->leave() };
157 is $@, '', 'second inherited valid method call ran fine';
158 is_deeply \%mg, { }, 'stash: second inherited valid method call doesn\'t call magic';
164 eval q{ Hlagher->shoot() };
166 is $@, '', 'inherited previously called valid method call ran fine';
168 fetch => [ qw<shoot> ],
169 }, 'stash: inherited previously called valid method call';
175 eval q{ Hlagher->shoot() };
177 is $@, '', 'second inherited previously called valid method call ran fine';
178 is_deeply \%mg, { }, 'stash: second inherited previously called valid method call doesn\'t call magic';
184 eval q{ Hlagh->unknown() };
186 like $@, qr/^Can't locate object method "unknown" via package "Hlagh"/, 'stash: invalid method call croaked';
188 fetch => [ qw<unknown> ],
189 store => [ qw<unknown AUTOLOAD> ],
190 }, 'stash: invalid method call';
196 eval q{ my $meth = 'unknown_too'; Hlagh->$meth() };
198 like $@, qr/^Can't locate object method "unknown_too" via package "Hlagh"/, 'stash: invalid dynamic method call croaked';
200 store => [ qw<unknown_too AUTOLOAD> ],
201 }, 'stash: invalid dynamic method call';
207 eval q{ Hlagher->also_unknown() };
209 like $@, qr/^Can't locate object method "also_unknown" via package "Hlagher"/, 'stash: invalid inherited method call croaked';
211 fetch => [ qw<also_unknown AUTOLOAD> ],
212 }, 'stash: invalid method call';
218 my @expected_stores = map { ($_) x 2 } qw<nevermentioned eat shoot>;
219 push @expected_stores, 'nevermentioned' if "$]" < 5.017_001;
223 undef &nevermentioned;
228 is $@, '', 'stash: delete executed fine';
229 is_deeply \%mg, { store => \@expected_stores }, 'stash: delete';
233 is_deeply \%mg, { }, 'stash: magic that remains at END time' if $run;
236 dispell %Hlagh::, $wiz;
241 use vars qw<$AUTOLOAD>;
243 sub AUTOLOAD { return $AUTOLOAD }
246 cast %AutoHlagh::, $wiz;
251 my $res = eval q{ AutoHlagh->autoloaded() };
253 is $@, '', 'stash: autoloaded method call ran fine';
254 is $res, 'AutoHlagh::autoloaded',
255 'stash: autoloaded method call returned the right thing';
257 fetch => [ qw<autoloaded> ],
258 store => [ qw<autoloaded AUTOLOAD AUTOLOAD> ],
259 }, 'stash: autoloaded method call';
266 BEGIN { @ISA = ('AutoHlagh') }
272 my $res = eval q{ AutoHlagher->also_autoloaded() };
274 is $@, '', 'stash: inherited autoloaded method call ran fine';
275 is $res, 'AutoHlagher::also_autoloaded',
276 'stash: inherited autoloaded method returned the right thing';
278 fetch => [ qw<also_autoloaded AUTOLOAD> ],
279 store => [ qw<AUTOLOAD> ],
280 }, 'stash: inherited autoloaded method call';
283 dispell %AutoHlagh::, $wiz;
287 . join (', ', map { <<CB;
290 return 0 if \$d->{guard};
291 local \$d->{guard} = 1;
296 } qw<fetch store exists delete>);
298 my $uo_exp = "$]" < 5.011002 ? 2 : 3;
300 $code .= ', data => sub { +{ guard => 0 } }';
302 $wiz = eval $code . ', op_info => ' . VMG_OP_INFO_NAME;
307 is $uo, 0, 'stash: no undef op before function call with op name';
313 is $@, "ok\n", 'stash: function call with op name compiled fine';
314 is $uo, $uo_exp, 'stash: undef op after function call with op name';
316 dispell %Hlagh::, $wiz;
317 is $uo, $uo_exp, 'stash: undef op after dispell for function call with op name';
321 $wiz = eval $code . ', op_info => ' . VMG_OP_INFO_OBJECT;
326 is $uo, 0, 'stash: no undef op before function call with op object';
332 is $@, "ok\n", 'stash: function call with op object compiled fine';
334 'stash: undef op after dispell for function call with op object';
336 dispell %Hlagh::, $wiz;
338 'stash: undef op after dispell for function call with op object';