| 1 | package Devel::Callsite; | ||||||||||
| 2 | 2 | ▶ | use 5.005; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use XSLoader; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | $VERSION = '1.0.1'; | |||||||||
| 7 | 2 | ▶ | if ($] >= 5.026) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 8 | 2 | @EXPORT = qw/callsite context addr_to_op caller_nextop/; | |||||||||
| 9 | } else { | ||||||||||
| 10 | 0 | @EXPORT = qw/callsite context/; | |||||||||
| 11 | } | ||||||||||
| 12 | |||||||||||
| 13 | 2 | XSLoader::load __PACKAGE__; | |||||||||
| 14 | |||||||||||
| 15 | 2 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||
| 16 | 2 | ▶ | if ($] >= 5.026) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 1 | ▶ | sub caller_nextop { | ||||||||
|
Subroutine
caller_nextop: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 18 | 1 | ▶ | my $level = ($#_ ? shift : 0) + 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 1 | return addr_to_op(callsite($level)); | |||||||||
| 20 | } | ||||||||||
| 21 | } | ||||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | # Demo code | ||||||||||
| 25 | 2 | ▶ | unless (caller) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | ▶ | my $site = sub { return callsite() }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 27 | 0 | printf "OP location: 0x%x\n", $site->(); # prints caller OP location | |||||||||
| 28 | 0 | printf "OP location: 0x%x\n", $site->(); # prints a different OP location | |||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | if ($] >= 5.026) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | ▶ | my $get_op = sub { return caller_nextop() }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 32 | 0 | printf "OP is: %s\n", $get_op->(); | |||||||||
| 33 | |||||||||||
| 34 | # prints the interpreter context, an unsigned number | ||||||||||
| 35 | 0 | print "Expression context is: ", context(), "\n"; | |||||||||
| 36 | } | ||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 2 | 1; | |||||||||
| 40 | __END__ | ||||||||||