Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

geoff (2013)

geoff
  reversethis-{gro ... om} {ta} {ffoeg}
http://www.modperlcookbook.org/

see http://www.modperlcookbook.org/~geoff/ [modperlcookbook.org] for personal information, links to presentations, GPG key, and so on.

Journal of geoff (2013)

Tuesday August 31, 2004
03:18 PM

overriding core functions

[ #20660 ]
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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.