overriding core functions

geoff on 2004-08-31T20:18:05

I spent some time today trying to override perl's time() function for some tests. after a few iterations in solitary that didn't quite cut it, I stumbled upon this list discussion. and so, after far too much independent work, 5 minutes of google yielded

BEGIN {
  *CORE::GLOBAL::time = sub { CORE::time };
}
                                                                                                                             
{
  no warnings qw(redefine);

local *CORE::GLOBAL::time = sub { $time }; }


while I got the BEGIN part on my own, the trick I was missing in my own hacking was to reassign CORE::GLOBAL::time() to itself so that it would continue to function until my local overrides went into effect.



I imagine that most test-driven people already know this, but just in case I wasn't the only person sleeping in class I thought I'd post it here.


ex::override

cwest on 2004-09-01T15:26:26

Odd name, but it does the job with a pretty face. ;-)