Many times in test suites I don't want to mock up an entire class or package.  
Instead, there are
only one or two target subroutines that I want to change.  I get awfully tired of 
doing the
following, though:

  {
    no warnings 'redefine';
    my $message;
    local *Foo::bar = sub { $message = shift };
    ...
  }

That sucks because I constantly mistype things, or I find that I need to cache the 
original sub
with my $sub = *Foo::bar{CODE} and I often forget the syntax the first time.

So I wrote a little module, Sub::Override, to do that for me.  I can replace subs, 
explicitly
restore them to their original value or just let the object fall out of scope and have 
the subs
automatically restored.  However, this seems like such an obvious little module that 
*someone*
must have written it.  Alas, I cannot find it on the CPAN.  Is it out there and I 
missed it, or is
this something I should upload?

Cheers,
Ovid

=====
Silence is Evil            http://users.easystreet.com/ovid/philosophy/indexdecency.htm
Ovid                       http://www.perlmonks.org/index.pl?node_id=17000
Web Programming with Perl  http://users.easystreet.com/ovid/cgi_course/

Reply via email to