#!/usr/local/bin/perl -w use strict; no strict 'refs'; package A; use Data::Dumper; use vars qw($AUTOLOAD); my %cache; sub AUTOLOAD { (my $meth = $AUTOLOAD) =~ s/.*:://; return if $meth eq 'DESTROY'; my ($package, $filename, $line, $subroutine) = caller(0); print "$meth called by: $package, $filename, $line, $subroutine\n"; $cache{"$package, $filename, $line, $subroutine"} = $_[0]; $_[0]->{line} = $line; *{'A::'.$meth} = sub { print "invoking $meth from: $package, $filename, $line, $subroutine\n"; print "\twith ", Dumper (\@_); }; goto &{'A::'.$meth}; } package main; foreach (1..2) { # if hashref were CONSTANT, and not rebuilt for each invocation, # it could preserve the A::fancy({arb=>1},1); A::fancy({ok=>2},2); A::auto({}); A::auto({}); } use Data::Dumper; print Dumper (\%A::);