Author image Rafaël Garcia-Suarez


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


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


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.



(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.


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.


(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