Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Micro Mocking: using local to help test subs

by Zaxo (Archbishop)
on Jan 13, 2003 at 01:47 UTC ( #226374=note: print w/replies, xml ) Need Help??


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:

use Errno qw( ENOSPC ); { local *CORE::GLOBAL::print = sub { $! = ENOSPC; return}; # make test call # see what happens when a device is full }
A finer grained and more accurate test can be obtained by localizing an open file handle:
{ open local(LOG), '>>', '/dev/full' or die $!; # /dev/full is a Linux thing # call the test }
++adrianh for bringing this up, there is a wealth of devious fun in this idiom.

After Compline,
Zaxo

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://226374]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2017-07-21 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (319 votes). Check out past polls.