Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^6: 'state' variables and unit testing (intentional)

by tobyink (Abbot)
on Feb 04, 2014 at 13:08 UTC ( #1073394=note: print w/ replies, xml ) Need Help??


in reply to Re^5: 'state' variables and unit testing (intentional)
in thread 'state' variables and unit testing

An an alternative:

{ use Scope::Guard; my $_cache; sub withLongComputation { $_cache //= ...; ...; } sub localClearCache { my $old = $_cache; undef $_cache; return guard { $_cache = $old }; } } ...; withLongComputation(); withLongComputation(); { my $guard = localClearCache(); # here, $_cache has been cleared withLongComputation(); } # Because $guard has fallen out of scope, # $_cache has been restored to its old value withLongComputation();
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name


Comment on Re^6: 'state' variables and unit testing (intentional)
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1073394]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2014-12-28 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls