NAME

Attribute::RecordCallers - keep a record of who called a subroutine

SYNOPSIS

use Attribute::RecordCallers;
sub call_me_and_i_ll_tell_you : RecordCallers { ... }
...
END {
    use Data::Dumper;
    print Dumper \%Attribute::RecordCallers::callers;
}

DESCRIPTION

This module defines a function attribute that will trigger collection of callers for the designated functions.

Each time a function with the :RecordCallers attribute is run, a global hash %Attribute::RecordCallers::caller is populated with caller information. The keys in the hash are the function names, and the elements are arrayrefs containing lists of quadruplets:

[ $package, $filename, $line, $timestamp ]

The timestamp is obtained via Time::HiRes.

FUNCTIONS

clear()

(not exported) This function will clear the %callers global hash.

walk(sub { ... })

(not exported) Invokes the subroutine passed as argument once for each item in the %callers hash. The arguments passed to it are the recorded subroutine name, and the arrayref of arrayrefs recording all the calls.

LIMITATIONS

You cannot use the :RecordCaller attribute on anonymous or lexical subroutines, or or subroutines with any other attribute (such as :lvalue).

With perls older than version 5.16.0, setting the :RecordCallers attribute will remove the prototype of any subroutine.

LICENSE

(c) Rafael Garcia-Suarez (rgs at consttype dot org) 2014

This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

A git repository for the sources is at https://github.com/rgs/Attribute-RecordCallers.