| 1 | =for gpg | ||||||||||
| 2 | -----BEGIN PGP SIGNED MESSAGE----- | ||||||||||
| 3 | Hash: SHA1 | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Function::ID - Variables to let functions know their names. | ||||||||||
| 8 | |||||||||||
| 9 | =head1 VERSION | ||||||||||
| 10 | |||||||||||
| 11 | This documentation describes version 0.02 of Function::ID, March 29, 2003. | ||||||||||
| 12 | |||||||||||
| 13 | =cut | ||||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | package Function::ID; | ||||||||||
| 17 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1 | ▶ | use vars '$VERSION'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | $VERSION = 0.02; | |||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | use vars '$this_fn', '$this_function'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | sub TIESCALAR | ||||||||||
| 24 | 2 | ▶ | { | ||||||||
|
Subroutine
TIESCALAR: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 2 | my $class = shift; | |||||||||
| 26 | 2 | my $name = shift; | |||||||||
| 27 | 2 | return bless \$name, $class; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | sub STORE | ||||||||||
| 31 | 2 | ▶ | { | ||||||||
|
Subroutine
STORE: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 2 | my $self = shift; | |||||||||
| 33 | 2 | croak "Attempt to assign to \$$$self"; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | sub FETCH | ||||||||||
| 37 | 6 | ▶ | { | ||||||||
|
Subroutine
FETCH: called CC=2 SCAR=6.9
| |||||||||||
| 38 | 6 | my $self = shift; | |||||||||
| 39 | 6 | my $callfunc = (caller 1)[3]; | |||||||||
| 40 | 6 | ▶ | $callfunc =~ s/.*::// if $$self eq 'this_fn'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 6 | return $callfunc; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | 1 | tie $this_fn, __PACKAGE__, 'this_fn'; | |||||||||
| 47 | 1 | tie $this_function, __PACKAGE__, 'this_function'; | |||||||||
| 48 | |||||||||||
| 49 | sub import | ||||||||||
| 50 | 2 | ▶ | { | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 51 | 2 | my $caller_pkg = caller; | |||||||||
| 52 | |||||||||||
| 53 | 1 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 54 | 2 | *{$caller_pkg."::this_fn"} = \$this_fn; | |||||||||
| 55 | 2 | *{$caller_pkg."::this_function"} = \$this_function; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 1 | 1; # Modules must return true, for silly historical reasons. | |||||||||
| 59 | __END__ | ||||||||||