diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-09-10 22:29:15 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-09-15 22:45:10 -0700 |
commit | a70c2d5688349e997aaf662f41f2dfe6a9b1fe27 (patch) | |
tree | e6fb394290cc691fba4a93645dee89cec40916bc /t/cmd | |
parent | 81df9f6f95225e40ead5e853dadb0bb98be2531b (diff) | |
download | perl-a70c2d5688349e997aaf662f41f2dfe6a9b1fe27.tar.gz |
Allow lexical sub redefinition inside eval
For non-clonable state subs, this already happened to work.
For any clonable subs, we need to clone the sub as soon as it
is defined.
For redefined state subs, we need to apply the new sub to all recur-
sion levels, as state subs are shared.
Diffstat (limited to 't/cmd')
-rw-r--r-- | t/cmd/lexsub.t | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/t/cmd/lexsub.t b/t/cmd/lexsub.t index 24dc5b04ca..d7601b3695 100644 --- a/t/cmd/lexsub.t +++ b/t/cmd/lexsub.t @@ -8,7 +8,7 @@ BEGIN { *bar::like = *like; } no warnings 'deprecated'; -plan 122; +plan 124; # -------------------- our -------------------- # @@ -290,6 +290,19 @@ sub make_anon_with_state_sub{ state sub x; eval 'sub x {3}'; is x, 3, 'state sub defined inside eval'; + + sub r { + state sub foo { 3 }; + if (@_) { # outer call + r(); + is foo(), 42, + 'state sub run-time redefinition applies to all recursion levels'; + } + else { # inner call + eval 'sub foo { 42 }'; + } + } + r(1); } # -------------------- my -------------------- # @@ -568,6 +581,11 @@ not_lexical11(); x(); is $count, 11, 'my recursive subs'; } +{ + my sub x; + eval 'sub x {3}'; + is x, 3, 'my sub defined inside eval'; +} # -------------------- Interactions (and misc tests) -------------------- # |