share perl module state between tests -


i using test::more , have helper function takes while run. need use in several test scripts. save result of running function, state can accessed scripts. result of calling function not change each test.

i have created module this: package helper;

our $_global_state = under;  sub helper {     if ( !defined( $_global_state)) {         #insert magic here set _global_state         print stderr "inside magic\n";     }     return $_global_state; }  return 1; 

however, if call function several test scripts, redoes 'magic' each time. trying avoid if @ possible.

can solved using following:

  • save calculated state file.
  • if file isn't last modified in 10 minutes, recalculate value.

using storable:

use strict; use warnings;  use storable;  our $state_file = 'global.state';  sub helper {     # check see if file last modified in 10 minutes.     if (-e $state_file && -m $state_file < 1/24/6) {         return retrieve($state_file);     }      #insert magic here set _global_state     $global_state = {'a'..'d'};      store $global_state, $state_file;      return $global_state; }  use data::dump; dd helper();  1; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -