in reply to Upgrade B::Deparse?

has support for CODE references
Be sure you understand the limits of that support. It cannot handle closures properly, only pure coderefs (ones that do not access any lexical variables outside their scope). I've posted code here before to demonstrate that, and I understand that the "fix" would be quite difficult, so don't expect it to be solved in the near future.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: •Re: Upgrade B::Deparse?
by diotalevi (Canon) on Oct 03, 2002 at 14:38 UTC

    I'm curious - how is it difficult to re-instate lexicals? I did a snippet of code on here a two weeks ago where lexical (values anyway) were being extracted from a code ref and was justing plain perl. With a dash of XS the lexicals could be fully re-instated. Is there some hidden trapdoor here I'm not seeing?

    __SIG__
    printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE

      One problem I could see is that even if you could pull the lexical values, you might have serialization problems. For instance, if two closures shared a ref and upon re-animating, getting them to both point back to one value instead of two independant copies. I'm sure you could do it but I would think it might be tricky in subtle ways.

      -Lee

      "To be civilized is to deny one's nature."

        Yes I suppose... though that just sounds like a problem for a hash - keep track of the addresses you're snarfing and when you rebuild the code just (and I don't *think* that's a big just) put it back together the right way. I don't know how the code refs are stored I'm just commenting on the feasibility of getting at all the data in a code ref. From my perspective it's possible and isn't weird somehow.

        I've been thinking that it would be interesting to walk the opcode tree and symbol table to enumerate everything and then see where the gaps are. ;-) It sort of addresses the same idea since that idea is implementable using pure perl - no C compiler required.

        __SIG__
        printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE