in reply to SOLVED: Trying to DESTROY() a (closure-wrapped) object
For the demo case, the simplest way of getting your desired output would be localizing, e.g.,
You could also use mock to bless into a subclass One::Debug that looks like:print One::foo(); { my $count = Count->new; no warnings 'redefine'; local *One::foo = sub { $count->{x} = 'x'; return "baz\n"; }; print One::foo(); } print One::foo();
Really, what's going on here is a bit of an XY Problem. You need to think on how to best encapsulate your patching to cover only your particular problem.package One::Debug; our @ISA = 'One'; sub foo { return "baz\n"; } 1;
Incidentally, what you are trying use is traditionally called a guard. At least, I think that's what you are trying to do...
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Trying to DESTROY() an object
by Eily (Monsignor) on Dec 08, 2015 at 16:40 UTC | |
by kennethk (Abbot) on Dec 08, 2015 at 17:59 UTC | |
by Eily (Monsignor) on Dec 09, 2015 at 09:08 UTC | |
by kennethk (Abbot) on Dec 09, 2015 at 15:58 UTC | |
by Eily (Monsignor) on Dec 09, 2015 at 19:18 UTC | |
by stevieb (Canon) on Dec 08, 2015 at 19:01 UTC | |
by kennethk (Abbot) on Dec 08, 2015 at 20:31 UTC | |
by stevieb (Canon) on Dec 08, 2015 at 20:57 UTC | |
|
Re^2: Trying to DESTROY() an object (!gc)
by tye (Sage) on Dec 09, 2015 at 05:24 UTC | |
by kennethk (Abbot) on Dec 09, 2015 at 16:04 UTC |