I like the idea. Write up a more complete proposal and we'll all review it. A few thoughts:

- The same mechanism could be used to implement Perl 6 sub wrapping, so keep that in mind as you're thinking through the implementation options. Names like "trace_sub" may be too specific to one particular use.

- Runtime addition of traces/wrappers will be more important than adding them at compile-time, considering that they're likely to be mostly used for layering debugging/profiling/etc checks over existing code, and in the debugger. So much more important, that I'd consider skipping the compile-time syntax.

- I like the Perl 6 way of specifying the point in the wrapping sub where the wrapped sub should be called better than setting up conditionals based on an argument for the operation type. So, something like:

.sub joe
  .param pmc wrapped_sub
  .param pmc orig_args

  .local string proc_name
  proc_name = wrapped_sub.name()

  print "entering "
  say proc_name

  invoke_wrapped wrapped_sub, orig_args

  print "leaving "
  say proc_name
.end

.sub bob :wrap joe
  say "whoa."
.end

(That also means you can monkey around with the args before passing them on to the wrapped sub.)


- It should be possible both to put multiple wrappers/traces on a subroutine, and to put wrappers around other wrappers. So these are all possible:

.sub joe
  #...
.end

.sub bob :wrap joe
  #...
.end

.sub phil :wrap joe
  #...
.end

.sub dave :wrap phil
  #...
.end


Allison
FWIW, it might be easier to put the :wrap flag onto the wrapping sub, IMHO. If there is some sub you want to wrap, according to the syntax above you would need to change that sub, which might not be desirable or even possible. The wrapped sub could be only available as a library, for instance.

so, the idea would then be:

.sub joe :wrap('bob')
   .param pmc args
   say "calling bob..."
   invoke_wrapped args
   say "returned from bob"
.end

.sub bob
   say "this is bob"
.end

which outputs:

calling bob....
this is bob
returned from bob

This way, the original sub is not touched, and you just 'add' the wrapper function.
my 2c.

Reply via email to