configuration - What is good way share reloadable config parameters for perl scripts -
i have lot of little perl daemons mutual configuration.
currently, utilize load settings:
in myconfig.pm:
package myconfig; utilize base of operations 'exporter'; begin { our @export = qw( $db_dsn $db_user $db_pwd ); } our @export; utilize vars @export; $db_dsn = "dbi:mysql:..."; $db_user = 'asdad'; ...
and in daemon.pl:
use myconfig;
this works fine. have new requirement reload configuration when usr1
signal received. know about
$sig{"usr1"} = sub { ... }
but next? use myconfig
again? looks mad.
my scripts have run on many different platforms , different perl versions 5.8 modern, i'm trying avoid cpan modules.
please point me solution task.
when use module (args)
, equivalent to
begin { require module; module->import(args); }
the require
locates , compiles module. happens 1 time each module. import
runs special import
sub loads subs , variables callers namespace (provided exporter module). so
$sig{usr1} = sub { no warnings 'redefine'; myconfig->import };
may work problem.
followup:i wrote little programme demonstrate works (using alrm instead of usr1):
use 5.010; bundle foo; sub import{ # exporter module writes similar. no strict 'refs'; *{caller()."::var"} = \do{ my$x = 1 }; # set $foo callers namespace } bundle main; foo->import(); # utilize foo; if bundle in file $sig{alrm} = sub{ foo->import; alarm 10 }; alarm 10; while(1){ $var++; sleep 1; }
output: counting 0 10, 1 time again , again. aware alter variable within loop, can see changes , reset correctly.
perl configuration import daemon signal-handling
No comments:
Post a Comment