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.011_002 ? \@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 = qw<nevermentioned eat shoot>;
219 @expected_stores = map { ($_) x 2 } @expected_stores if "$]" < 5.017_004;
220 push @expected_stores, 'nevermentioned' if "$]" < 5.017_001;
224 undef &nevermentioned;
229 is $@, '', 'stash: delete executed fine';
230 is_deeply \%mg, { store => \@expected_stores }, 'stash: delete';
234 is_deeply \%mg, { }, 'stash: magic that remains at END time' if $run;
237 dispell %Hlagh::, $wiz;
242 use vars qw<$AUTOLOAD>;
244 sub AUTOLOAD { return $AUTOLOAD }
247 cast %AutoHlagh::, $wiz;
252 my $res = eval q{ AutoHlagh->autoloaded() };
254 is $@, '', 'stash: autoloaded method call ran fine';
255 is $res, 'AutoHlagh::autoloaded',
256 'stash: autoloaded method call returned the right thing';
258 fetch => [ qw<autoloaded> ],
259 store => [ qw<autoloaded AUTOLOAD AUTOLOAD> ],
260 }, 'stash: autoloaded method call';
267 BEGIN { @ISA = ('AutoHlagh') }
273 my $res = eval q{ AutoHlagher->also_autoloaded() };
275 is $@, '', 'stash: inherited autoloaded method call ran fine';
276 is $res, 'AutoHlagher::also_autoloaded',
277 'stash: inherited autoloaded method returned the right thing';
279 fetch => [ qw<also_autoloaded AUTOLOAD> ],
280 store => [ qw<AUTOLOAD> ],
281 }, 'stash: inherited autoloaded method call';
284 dispell %AutoHlagh::, $wiz;
288 . join (', ', map { <<CB;
291 return 0 if \$d->{guard};
292 local \$d->{guard} = 1;
297 } qw<fetch store exists delete>);
299 my $uo_exp = "$]" < 5.011_002 ? 2 : 3;
301 $code .= ', data => sub { +{ guard => 0 } }';
303 $wiz = eval $code . ', op_info => ' . VMG_OP_INFO_NAME;
308 is $uo, 0, 'stash: no undef op before function call with op name';
314 is $@, "ok\n", 'stash: function call with op name compiled fine';
315 is $uo, $uo_exp, 'stash: undef op after function call with op name';
317 dispell %Hlagh::, $wiz;
318 is $uo, $uo_exp, 'stash: undef op after dispell for function call with op name';
322 $wiz = eval $code . ', op_info => ' . VMG_OP_INFO_OBJECT;
327 is $uo, 0, 'stash: no undef op before function call with op object';
333 is $@, "ok\n", 'stash: function call with op object compiled fine';
335 'stash: undef op after dispell for function call with op object';
337 dispell %Hlagh::, $wiz;
339 'stash: undef op after dispell for function call with op object';