# define SU_SAVE_HELEM_OR_HDELETE_SIZE SU_SAVE_HELEM_SIZE
#endif
-#define SU_SAVE_SPTR_SIZE 3
+#define SU_SAVE_GVCV_SIZE SU_SAVE_DESTRUCTOR_SIZE
#if !SU_HAS_PERL(5, 8, 9)
# define SU_SAVE_GP_SIZE 6
/* ... Saving code slots from a glob ....................................... */
-#if SU_HAS_PERL(5, 13, 10)
-
-/* Since perl 5.13.10, GvCV() is only a rvalue so we no longer can store a
- * pointer to the gvcv member of the gv. */
+#if !SU_HAS_PERL(5, 10, 0) && !defined(mro_method_changed_in)
+# define mro_method_changed_in(G) PL_sub_generation++
+#endif
typedef struct {
GV *gv;
STATIC void su_restore_gvcv(pTHX_ void *ud_) {
su_save_gvcv_ud *ud = ud_;
+ GV *gv = ud->gv;
- GvCV_set(ud->gv, ud->old_cv);
+ GvCV_set(gv, ud->old_cv);
+ GvCVGEN(gv) = 0;
+ mro_method_changed_in(GvSTASH(gv));
Safefree(ud);
}
STATIC void su_save_gvcv(pTHX_ GV *gv) {
-#define su_save_gvcv(gv) su_save_gvcv(aTHX_ (gv))
+#define su_save_gvcv(G) su_save_gvcv(aTHX_ (G))
su_save_gvcv_ud *ud;
Newx(ud, 1, su_save_gvcv_ud);
ud->old_cv = GvCV(gv);
GvCV_set(gv, NULL);
+ GvCVGEN(gv) = 0;
+ mro_method_changed_in(GvSTASH(gv));
SAVEDESTRUCTOR_X(su_restore_gvcv, ud);
}
-#else
-
-#define su_save_gvcv(gv) SAVESPTR(GvCV(gv)), GvCV_set((gv), NULL)
-
-#endif
-
/* --- Actions ------------------------------------------------------------- */
typedef struct {
deref = 0;
break;
case SVt_PVCV:
- size = SU_SAVE_SPTR_SIZE;
+ size = SU_SAVE_GVCV_SIZE;
deref = 0;
break;
default:
use strict;
use warnings;
-use Test::More tests => 61 + 4;
+use Test::More tests => 70 + 4;
use Scope::Upper qw/localize UP HERE/;
is foo(), 'x', 'localize *foo, sub { "y" } => UP [end]';
}
+sub X::foo { 'X::foo' }
+
+{
+ {
+ {
+ localize 'X::foo', sub { 'X::foo 2' } => UP;
+ is(X->foo, 'X::foo', 'localize "X::foo", sub { "X::foo 2" } => UP [not yet]')
+ }
+ is(X->foo, 'X::foo 2', 'localize "X::foo", sub { "X::foo 2" } => UP [ok]');
+ }
+ is(X->foo, 'X::foo', 'localize "X::foo", sub { "X::foo 2" } => UP [end]');
+}
+
+@Y::ISA = 'X';
+
+{
+ {
+ {
+ localize 'X::foo', sub { 'X::foo 3' } => UP;
+ is(Y->foo, 'X::foo', 'localize "X::foo", sub { "X::foo 3" } => UP [not yet]')
+ }
+ is(Y->foo, 'X::foo 3', 'localize "X::foo", sub { "X::foo 3" } => UP [ok]');
+ }
+ is(Y->foo, 'X::foo', 'localize "X::foo", sub { "X::foo 2" } => UP [end]');
+}
+
+{
+ {
+ {
+ localize 'Y::foo', sub { 'Y::foo' } => UP;
+ is(Y->foo, 'X::foo', 'localize "Y::foo", sub { "Y::foo" } => UP [not yet]');
+ }
+ is(Y->foo, 'Y::foo', 'localize "Y::foo", sub { "Y::foo" } => UP [ok]');
+ }
+ is(Y->foo, 'X::foo', 'localize "Y::foo", sub { "Y::foo" } => UP [end]');
+}
+
# Invalid
sub invalid_ref { qr/^Invalid \Q$_[0]\E reference as the localization target/ }
use strict;
use warnings;
-use Test::More tests => 44 + 4;
+use Test::More tests => 53 + 4;
use Scope::Upper qw/localize_delete UP HERE/;
'localize_delete "%nonexistent", anything => HERE [end]';
}
-# Others
+# Scalars
our $x = 1;
{
'localize_delete "$nonexistent", anything => HERE [end]';
}
+# Code
+
sub x { 1 };
{
localize_delete '&x', 2 => HERE;
is x(), 1, 'localize_delete *x, anything => HERE [end 1]';
is $x, 1, 'localize_delete *x, anything => HERE [end 2]';
+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/ }