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 is $@, "ok\n", 'stash: function calls compiled fine';
93 fetch => [ qw/eat shoot leave roam yawn roam/ ],
94 store => [ qw/eat shoot leave roam yawn roam/ ],
95 }, 'stash: function calls';
101 eval q{ Hlagh->shoot() };
103 is $@, '', 'stash: valid method call ran fine';
105 fetch => [ qw/shoot/ ],
106 }, 'stash: valid method call';
112 eval q{ my $meth = 'shoot'; Hlagh->$meth() };
114 is $@, '', 'stash: valid dynamic method call ran fine';
116 store => [ qw/shoot/ ],
117 }, 'stash: valid dynamic method call';
126 BEGIN { @ISA = 'Hlagh' }
130 is $@, '', 'inherited valid method call ran fine';
132 fetch => [ qw/ISA shoot/ ],
133 }, 'stash: inherited valid method call';
139 eval q{ Hlagh->unknown() };
141 like $@, qr/^Can't locate object method "unknown" via package "Hlagh"/, 'stash: invalid method call croaked';
143 fetch => [ qw/unknown/ ],
144 store => [ qw/unknown AUTOLOAD/ ],
145 }, 'stash: invalid method call';
151 eval q{ my $meth = 'unknown_too'; Hlagh->$meth() };
153 like $@, qr/^Can't locate object method "unknown_too" via package "Hlagh"/, 'stash: invalid dynamic method call croaked';
155 store => [ qw/unknown_too AUTOLOAD/ ],
156 }, 'stash: invalid dynamic method call';
162 eval q{ Hlagher->also_unknown() };
164 like $@, qr/^Can't locate object method "also_unknown" via package "Hlagher"/, 'stash: invalid inherited method call croaked';
166 fetch => [ qw/also_unknown AUTOLOAD/ ],
167 }, 'stash: invalid method call';
175 undef &nevermentioned;
180 is $@, '', 'stash: delete executed fine';
183 qw/nevermentioned nevermentioned eat eat shoot shoot nevermentioned/
189 is_deeply \%mg, { }, 'stash: magic that remains at END time' if $run;
192 dispell %Hlagh::, $wiz;
197 use vars qw/$AUTOLOAD/;
199 sub AUTOLOAD { return $AUTOLOAD }
202 cast %AutoHlagh::, $wiz;
207 my $res = eval q{ AutoHlagh->autoloaded() };
209 is $@, '', 'stash: autoloaded method call ran fine';
210 is $res, 'AutoHlagh::autoloaded',
211 'stash: autoloaded method call returned the right thing';
213 fetch => [ qw/autoloaded/ ],
214 store => [ qw/autoloaded AUTOLOAD AUTOLOAD/ ],
215 }, 'stash: autoloaded method call';
222 BEGIN { @ISA = ('AutoHlagh') }
228 my $res = eval q{ AutoHlagher->also_autoloaded() };
230 is $@, '', 'stash: inherited autoloaded method call ran fine';
231 is $res, 'AutoHlagher::also_autoloaded',
232 'stash: inherited autoloaded method returned the right thing';
234 fetch => [ qw/also_autoloaded AUTOLOAD/ ],
235 store => [ qw/AUTOLOAD/ ],
236 }, 'stash: inherited autoloaded method call';
239 dispell %AutoHlagh::, $wiz;
242 . join (', ', map { <<CB;
245 return 0 if \$d->{guard};
246 local \$d->{guard} = 1;
247 is \$_[3], undef, 'stash: undef op';
251 } qw/fetch store exists delete/);
253 $code .= ', data => sub { +{ guard => 0 } }';
255 $wiz = eval $code . ', op_info => ' . VMG_OP_INFO_NAME;
266 is $@, "ok\n", 'stash: function call with op name compiled fine';
268 dispell %Hlagh::, $wiz;
270 $wiz = eval $code . ', op_info => ' . VMG_OP_INFO_OBJECT;
281 is $@, "ok\n", 'stash: function call with op object compiled fine';
283 dispell %Hlagh::, $wiz;