Slash Boxes
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 ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Saturday December 04, 2004
12:43 AM

Bricolage Tests

[ #22134 ]

In doing some work for the next version of Bricolage, I quickly discovered a limitation of Sub::Override. If I need to repeatedly override a subroutine to test various aspects of some code's behavior, I had to restore the original subroutine before overriding it subsequent times. Thus, I kept typing this:

    ->replace('Some::sub' => sub { 0 });
# test it

    ->replace('Some::sub' => sub { 1 });
# test it again

    ->replace('Some::sub' => sub { 2 });
# test it yet again

Theory asked me why I didn't just allow the sub to directly overridden more than once. "Well," blathered Ovid, "I'd have to maintain a stack of preceding subroutine behavior so I can ensure that restoring the subroutine always restores the previous behavior."

"No. Just restore the original behavior."

Duh. So I did. The new version (0.06) is on it's way to the CPAN and will let me write this:

$sub->replace('Some::sub' => sub { 0 });
# test it

$sub->replace('Some::sub' => sub { 1 });
# test it again

$sub->replace('Some::sub' => sub { 2 });
# test it yet again

Now, calling restore will always restore the original behavior of the subroutine. Pair programming strikes again.

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