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

In reply to Re^7: Installing a config file during module operation by jkeenan1
in thread Installing a config file during module operation by jkeenan1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.