++ed by:

4 PAUSE users
1 non-PAUSE user.

Rocky Bernstein

Devel::Callsite - Get caller return OP address and Perl interpreter context


  use Devel::Callsite;
  my $site = sub { return callsite() };
  printf "OP location: 0x%x\n", $site->(); # prints caller OP location
  printf "OP location: 0x%x\n", $site->(); # prints a different OP location

  print context(), "\n"; # prints the interpreter context, a unsigned number


The callsite() function returns the the OP address of the caller, a number, one level up from where it was called. It's useful for functions that need to uniquely know where they were called, such as Every::every(); see Every. Or it can be used to pinpoint a location with finer granularity than a line number. In conjunction with an OP tree disassembly you can know exactly where the caller is located in the Perl source.

The context() function returns the interpreter context as a number. This is a fairly unique number together with the call site.


Ben Morrow conceived this and posted it to perl5-porters. Ted Zlatanov then turned it into a CPAN module which he maintained for the first 3 revisions.

It is currently maintained (or not) by Rocky Bernstein.


B::Concise to disassemble the OP tree. Devel::Trepan optionally uses Devel::Callsite to show you exactly where you are stopped inside the debugger.


Rocky Bernstein <rocky@cpan.org> (current maintainer) Ted Zlatanov <tzz@lifelogs.com> Ben Morrow