On 22 Jan 2018 18:00:43 -0000 Father Chrysostomos <sprout@cpan.org> wrote: > 3. When the file-CV reaches run time, the 'my' declaration has its > run-time effect, which is to schedule the lexical (via SAVEFREESV) > to be cleared on scope exit. > 4. When the file-CV finishes running, the code in scope.c that clears > the entry sees that it is referenced elsewhere (its refcnt is > high), so it swaps it out and places another one in its place. Thank you for that bit. The first two steps (1 and 2) I knew, but these are new to me. I haven't spent a lot of time looking into scope exits before, so that hadn't occurred to me. > When you have named subs closing over lexical variables, since the > named subs only get one chance to capture the variable, you are likely > to get the 'will not stay shared' and 'is not available' messages. > However, knowing that the outer CV in this case is only run once, > Perl makes an exception and suppresses the warnings. By cloning a > named sub, you have created a situation the code was not written ot > account for. Yes. I think I'm coming to the conclusion that really, `cv_clone()` is doing lots of things quite specific to its job of cloning the protosub into a real runnable CV as part of the runtime part of an anoymous `sub { ... }` expression, whereas what I need to do is far more literally (and dumbly) duplicate a running (anon or named) CV to exactly capture all its state. I suspect that rather than my ongoing efforts to work around the ways `cv_clone()` doesn't do what I want I might be better off just writing myself a static CV *cv_dup(pTHX_ CV *cv); instead. -- Paul "LeoNerd" Evans leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/Thread Previous | Thread Next