Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: goto &method and skipping call frame

by jcb (Parson)
on Mar 05, 2021 at 04:02 UTC ( [id://11129146] : note . print w/replies, xml ) Need Help??


in reply to goto &method and skipping call frame

Recalling the other thread that seems to have inspired this, I expect that you will encounter a few problems:

  • Each with body will need its own auto-generated package for each class of object you want as "context": ref $OBJ should be sufficient to choose a context package.
  • The Perl prototype functionality that allows a keyword sub to be omitted only works for the first argument, if I remember correctly, so this may force you to change the syntax a bit or use a source filter.
  • The closure you get for the with body has already been compiled in its surrounding package, so you will need XS magic to crack it open and relocate it into the auto-generated package for the context. It may be easiest to simply move the closure into ref $OBJ and let Perl handle the rest, but watch for with being used in the scope of a use vars — you will need to translate references to globals that came from use vars. Globals declared using our are actually lexical aliases, so they should be carried with the closure when you move it to another package.

I have only a few readings of perlguts for how any of this is actually implemented, so I could be wrong here, but with appears fairly difficult to "bolt-on" to Perl. I expect a JS-like with to need to be added to the core language to work, or to hook sufficiently far into the interpreter that it may as well have been added to the core language.

Replies are listed 'Best First'.
Re^2: goto &method and skipping call frame
by LanX (Saint) on Mar 05, 2021 at 19:43 UTC
    Hi

    thanks for your thoughts.

    Regarding with - I just mentioned it for motivation and am still looking into the options.

    I'll post a RFC soon. :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery