I've been asked recently how to tell which perl module overrides a function. Here's an exapmle I managed to write. It's incomplete and most certainly buggy, but I don't think the task in question is worth a full-blown CPAN module anyway.
#!/usr/bin/perl -w use strict; BEGIN { use Guard; use Carp; { my $guard = guard { Carp::cluck "Function replaced!" }; my $code = \&time; *time = sub { return $code->(@_); undef $guard; }; }; }; BEGIN { print time(), "\n"; }; use Time::HiRes qw(time); print time, "\n";I welcome critique on this one.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Find out who redefined a subroutine
by tobyink (Canon) on Jan 25, 2013 at 15:33 UTC | |
by Dallaylaen (Chaplain) on Jan 25, 2013 at 15:45 UTC | |
by mwray (Initiate) on Feb 13, 2013 at 00:11 UTC |
Back to
Meditations