Funky stuff! My only suggestion would be to let the developer set his/her own callback,
in case the default output isn't what's wanted (notably tracing to something other than STDERR).
update: oh duh! which is exactly what you
said in the comments.. Something like:
use Carp qw/croak/;
BEGIN {
my $logger;
sub callback {
my $coderef = shift;
croak "$coderef is not a code reference, cannot use as a callb
+ack.\n"
unless ref($coderef) eq 'CODE';
$logger = $coderef;
}
callback( sub { print STDERR "Executing $_[0]!\n" } );
sub logCall {
&$logger( @_ );
}
}
This gives the following output (if the example script is changed as follows):
Test::foo();
Devel::TraceMethods::callback( sub { print STDERR "called $_[0].\n" }
+);
Test::bar();
Test::blah();
__END__
gives:
Executing foo!
called bar.
called AUTOLOAD.
Can works!
You would not believe how much I needed this code a couple of months ago....
-- g r i n d e r
|