Hrunting has asked for the wisdom of the Perl Monks concerning the following question:

I noticed that the latest and greatest of Storable now has support for CODE references. This has been a feature I have long been waiting for, so I rushed to install it on a development box (5.6.1) only to find that when it ran the CODE ref tests, it said that it required both B::Deparse >= 0.61 and perl >= 5.6.0. Well, perl 5.6.1 is installed, but that comes with B::Deparse 0.60.

Knowing that B::Deparse is basically a hook into the perl compiler (although the relationship is fuzzy to me), is it feasible to upgrade it? If so, how? The B::* modules aren't really maintained separately on CPAN and I'm wary of taking code out of 5.8.0 and compiling it for 5.6.1.

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

    The B modules hook into the compiler stuff sort of but not really. All the actual low level stuff happens in perl-?.?.?/ext/B/B.xs which you get when you do a use B;. B::Deparse is just plain perl code. It doesn't access any internals (directly) and nothing in B::* will alter your program runtime (some other B:: stuff from CPAN is different but you aren't using those). I do see that perl 5.8.0 comes with B::Deparse rev 0.63 so you if you get rev 0.61 then that isn't jumping up to 5.8.0. Now the remaining obvious thing here is that since B::Deparse isn't C code it's not compiled and in general it shouldn't be able to break things. I say upgrade. Try it out and just keep a copy of your stock B/Deparse.pm file if you want to swap it back in.

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

      Back to the second part of the problem. How do I upgrade B::Deparse? I can't find it in the B hierarchy on CPAN. It looks like it's only part of the perl distribution, and perl 5.6.1 comes with 0.60. So where do I find B::Deparse (I can figure out how to install it myself).

        Oh. I didn't realize you couldn't find that rev. I'm not sure but I'd look in the various source distributions at ftp://ftp.cpan.org/pub/CPAN/src/5.0/ likely in the devel/ directory to see about finding something betweeen. If doesn't do it then I'd just have to ask on perl5-porters for assistance.

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

•Re: Upgrade B::Deparse?
by merlyn (Sage) on Oct 03, 2002 at 14:30 UTC
    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

      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."