You can only override some builtins, and those you can override must be overridden by importing the replacement functions from another module.
>type TestHarness.pm
use strict; use warnings; package TestHarness; BEGIN { our @EXPORT_OK = qw( unlink ); require Exporter; *import = \&Exporter::import; } sub unlink { print("PRE unlink\n"); # Don't forget to properly handle context. my $rv = unlink(@_); print("POST unlink\n"); return $rv; } 1;
>type test.pl
use strict; use warnings; BEGIN { # Parse options or something. $::TESTING = 1; } use if $::TESTING, TestHarness => qw( unlink ); unlink();
>perl test.pl
PRE unlink POST unlink
You could control TestHarness::unlink's behaviour using globals.
In reply to Re: Unit testing built-in functions
by ikegami
in thread Unit testing built-in functions
by aijin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |