in reply to how can I access code ref contents, not call it?

The simplest solution is likely to say that the Perl code must be passed as text to Cons. Then Cons will compile it into an anon sub and use that. (This is not totally different from, say, how CGI is written.)

Alternately you can start staring at the various B::* and Devel::* modules to see if any will let you decode the guts of a subroutine into canonical form. I don't know of any, but I don't play much with that.

  • Comment on Re (tilly) 1: how can I access code ref contents, not call it?

Replies are listed 'Best First'.
Re: Re (tilly) 1: how can I access code ref contents, not call it?
by clemburg (Curate) on Jan 04, 2001 at 17:46 UTC

    I strongly second tilly's suggestion. Text is *the* portable medium for Perl code. If you have an eval(), why not use it.

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

      If you have an eval(), why not use it.

      Quoting.

      Creating a complex subroutine in text gets decidedly non-trivial and hard to maintain when you have to remember to not escape $foo because you want it interpolated but to escape \$bar because it's a local variable in your text's code. For many situations, a good old anonymous subroutine reads a lot cleaner.

      Cons actually already supports Perl code snippets in text, so this is an empirical observation. Both approaches do have their advantages and disadvantages. (Besides, providing both mechanisms would give people More Than One Way To Do It... :-)