in reply to Re^6: Installing a config file during module operation
in thread Installing a config file during module operation

Thanks in large part to the discussion in this thread and Win32 CSIDL_LOCAL_APPDATA, I am making progress toward this goal. Here are three utility subroutines I've written as part of this project. The first identifies a "home" directory suitable for holding a configuration file. The other two are used to locate the config file, suppress its effect during 'make test', then restore it to life afterwards.

sub _get_personal_defaults_directory { my ($realhome, $personal_dir); if ($^O eq 'MSWin32') { require Win32; Win32->import( qw(CSIDL_LOCAL_APPDATA) ); # 0x001c $realhome = Win32::GetFolderPath( CSIDL_LOCAL_APPDATA() ); if (-d "$realhome/.modulemaker") { $personal_dir = "$realhome/.modulemaker"; } else { $realhome =~ s|(.*?)\\Local Settings(.*)|$1$2|; if (-d "$realhome/.modulemaker") { $personal_dir = "$realhome/.modulemaker"; } } } else { # Unix-like systems $realhome = $ENV{HOME}; $personal_dir = "$realhome/.modulemaker"; } return $personal_dir; } sub _process_personal_defaults_file { my ($personal_dir, $pers_file) = @_; my $pers_file_hidden = "$pers_file" . '.hidden'; my %pers; $pers{full} = "$personal_dir/$pers_file"; $pers{hidden} = "$personal_dir/$pers_file_hidden"; if (-f $pers{full}) { $pers{atime} = (stat($pers{full}))[8]; $pers{modtime} = (stat($pers{full}))[9]; rename $pers{full}, $pers{hidden} or croak "Unable to rename $pers{full}: $!"; ok(! -f $pers{full}, "personal defaults file temporarily suppressed"); ok(-f $pers{hidden}, "personal defaults file now hidden"); } else { ok(! -f $pers{full}, "personal defaults file not found"); ok(1, "personal defaults file not found"); } return { %pers }; } sub _reprocess_personal_defaults_file { my $pers_def_ref = shift;; if(-f $pers_def_ref->{hidden} ) { rename $pers_def_ref->{hidden}, $pers_def_ref->{full}, or croak "Unable to rename $pers_def_ref->{hidden}: $!"; ok(-f $pers_def_ref->{full}, "personal defaults file re-established"); ok(! -f $pers_def_ref->{hidden}, "hidden personal defaults now gone"); ok( (utime $pers_def_ref->{atime}, $pers_def_ref->{modtime}, ($pers_def_ref->{full}) ), "atime and modtime of personal defaults file restored") +; } else { ok(1, "test not relevant"); ok(1, "test not relevant"); ok(1, "test not relevant"); } }

Jim Keenan