+
+sub X::foo { 'X::foo' }
+
+{
+ {
+ {
+ localize_delete '&X::foo', undef => UP;
+ is(X->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [not yet X]');
+ }
+ ok(!X->can('foo'), 'localize_delete "&X::foo", undef => UP [ok X]');
+ }
+ is(X->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [end X]');
+}
+
+@Y::ISA = 'X';
+
+{
+ {
+ {
+ localize_delete '&X::foo', undef => UP;
+ is(Y->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [not yet Y]');
+ }
+ ok(!Y->can('foo'), 'localize_delete "&X::foo", undef => UP [ok Y]');
+ }
+ is(Y->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [end Y]');
+}
+
+
+{
+ local *Y::foo = sub { 'Y::foo' };
+ {
+ {
+ localize_delete '&Y::foo', undef => UP;
+ is(Y->foo(), 'Y::foo', 'localize_delete "&Y::foo", undef => UP [not yet]');
+ }
+ is(Y->foo(), 'X::foo', 'localize_delete "&Y::foo", undef => UP [ok]');
+ }
+ is(Y->foo(), 'Y::foo', 'localize_delete "&Y::foo", undef => UP [end]');
+}
+
+{
+ # Prevent 'only once' warnings
+ local *Y::foo = *Y::foo;
+}
+
+# Invalid
+
+sub invalid_ref { qr/^Invalid \Q$_[0]\E reference as the localization target/ }
+
+{
+ eval { localize_delete \1, 0 => HERE };
+ like $@, invalid_ref('SCALAR'), 'invalid localize_delete \1, 0 => HERE';
+}
+
+{
+ eval { localize_delete [ ], 0 => HERE };
+ like $@, invalid_ref('ARRAY'), 'invalid localize_delete [ ], 0 => HERE';
+}
+
+{
+ eval { localize_delete { }, 0 => HERE };
+ like $@, invalid_ref('HASH'), 'invalid localize_delete { }, 0 => HERE';
+}
+
+{
+ eval { localize_delete sub { }, 0 => HERE };
+ like $@, invalid_ref('CODE'), 'invalid localize_delete sub { }, 0 => HERE';
+}