in reply to Micro Mocking: using local to help test subs
I have used a similar technique to subvert Perl builtins and mimic system errors:
A finer grained and more accurate test can be obtained by localizing an open file handle:use Errno qw( ENOSPC ); { local *CORE::GLOBAL::print = sub { $! = ENOSPC; return}; # make test call # see what happens when a device is full }
++adrianh for bringing this up, there is a wealth of devious fun in this idiom.{ open local(LOG), '>>', '/dev/full' or die $!; # /dev/full is a Linux thing # call the test }
After Compline,
Zaxo
In Section
Meditations