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 if ("$]" >= 5.011_002 && "$]" < 5.021_004) {
98 @store = map { ($_) x 2 } @calls;
104 is $@, "ok\n", 'stash: function calls compiled fine';
108 }, 'stash: function calls';
114 eval q{ Hlagh->shoot() };
116 is $@, '', 'stash: valid method call ran fine';
118 fetch => [ qw<shoot> ],
119 }, 'stash: valid method call';
125 eval q{ Hlagh->shoot() };
127 is $@, '', 'stash: second valid method call ran fine';
129 fetch => [ qw<shoot> ],
130 }, 'stash: second valid method call';
136 eval q{ my $meth = 'shoot'; Hlagh->$meth() };
138 is $@, '', 'stash: valid dynamic method call ran fine';
140 store => [ qw<shoot> ],
141 }, 'stash: valid dynamic method call';
150 BEGIN { @ISA = 'Hlagh' }
154 is $@, '', 'inherited valid method call ran fine';
156 fetch => [ qw<ISA leave> ],
157 }, 'stash: inherited valid method call';
163 eval q{ Hlagher->leave() };
165 is $@, '', 'second inherited valid method call ran fine';
166 is_deeply \%mg, { }, 'stash: second inherited valid method call doesn\'t call magic';
172 eval q{ Hlagher->shoot() };
174 is $@, '', 'inherited previously called valid method call ran fine';
176 fetch => [ qw<shoot> ],
177 }, 'stash: inherited previously called valid method call';
183 eval q{ Hlagher->shoot() };
185 is $@, '', 'second inherited previously called valid method call ran fine';
186 is_deeply \%mg, { }, 'stash: second inherited previously called valid method call doesn\'t call magic';
192 eval q{ Hlagh->unknown() };
194 like $@, qr/^Can't locate object method "unknown" via package "Hlagh"/, 'stash: invalid method call croaked';
196 fetch => [ qw<unknown> ],
197 store => [ qw<unknown AUTOLOAD> ],
198 }, 'stash: invalid method call';
204 eval q{ my $meth = 'unknown_too'; Hlagh->$meth() };
206 like $@, qr/^Can't locate object method "unknown_too" via package "Hlagh"/, 'stash: invalid dynamic method call croaked';
208 store => [ qw<unknown_too AUTOLOAD> ],
209 }, 'stash: invalid dynamic method call';
215 eval q{ Hlagher->also_unknown() };
217 like $@, qr/^Can't locate object method "also_unknown" via package "Hlagher"/, 'stash: invalid inherited method call croaked';
219 fetch => [ qw<also_unknown AUTOLOAD> ],
220 }, 'stash: invalid method call';
226 my @expected_stores = qw<nevermentioned eat shoot>;
227 @expected_stores = map { ($_) x 2 } @expected_stores if "$]" < 5.017_004;
228 push @expected_stores, 'nevermentioned' if "$]" < 5.017_001;
232 undef &nevermentioned;
237 is $@, '', 'stash: delete executed fine';
238 is_deeply \%mg, { store => \@expected_stores }, 'stash: delete';
242 is_deeply \%mg, { }, 'stash: magic that remains at END time' if $run;
245 dispell %Hlagh::, $wiz;
250 use vars qw<$AUTOLOAD>;
252 sub AUTOLOAD { return $AUTOLOAD }
255 cast %AutoHlagh::, $wiz;
260 my $res = eval q{ AutoHlagh->autoloaded() };
262 is $@, '', 'stash: autoloaded method call ran fine';
263 is $res, 'AutoHlagh::autoloaded',
264 'stash: autoloaded method call returned the right thing';
266 fetch => [ qw<autoloaded> ],
267 store => [ qw<autoloaded AUTOLOAD AUTOLOAD> ],
268 }, 'stash: autoloaded method call';
275 BEGIN { @ISA = ('AutoHlagh') }
281 my $res = eval q{ AutoHlagher->also_autoloaded() };
283 is $@, '', 'stash: inherited autoloaded method call ran fine';
284 is $res, 'AutoHlagher::also_autoloaded',
285 'stash: inherited autoloaded method returned the right thing';
287 fetch => [ qw<also_autoloaded AUTOLOAD> ],
288 store => [ qw<AUTOLOAD> ],
289 }, 'stash: inherited autoloaded method call';
292 dispell %AutoHlagh::, $wiz;
296 . join (', ', map { <<CB;
299 return 0 if \$d->{guard};
300 local \$d->{guard} = 1;
305 } qw<fetch store exists delete>);
307 my $uo_exp = "$]" >= 5.011_002 && "$]" < 5.021_004 ? 3 : 2;
309 $code .= ', data => sub { +{ guard => 0 } }';
311 $wiz = eval $code . ', op_info => ' . VMG_OP_INFO_NAME;
316 is $uo, 0, 'stash: no undef op before function call with op name';
322 is $@, "ok\n", 'stash: function call with op name compiled fine';
323 is $uo, $uo_exp, 'stash: undef op after function call with op name';
325 dispell %Hlagh::, $wiz;
326 is $uo, $uo_exp, 'stash: undef op after dispell for function call with op name';
330 $wiz = eval $code . ', op_info => ' . VMG_OP_INFO_OBJECT;
335 is $uo, 0, 'stash: no undef op before function call with op object';
341 is $@, "ok\n", 'stash: function call with op object compiled fine';
343 'stash: undef op after dispell for function call with op object';
345 dispell %Hlagh::, $wiz;
347 'stash: undef op after dispell for function call with op object';