I would strongly recommend decoupling the data (in this case your login info) from the code. Rather than hardcoding this in, have the module use values specified in a separate configuration file. See Config::Easy or a similar module for some examples.

As for the location of the config file, it is definitely more maintainable to place it outside of the perl hierarchy. Consider what happens if another program wants to use your module for a different data source.

Your greatest code re-use and ease of maintenance options will be to provide methods in the package which can accept either a filename or a hash of configuration options from the calling program. This abstracts the specific application (and application specific info like the database logins) from the module ... which is the whole point of writing a module.

Oh yeah, and the permissions on the config file will depend on how the program is run. If only one user needs to run it, 400 is good. If you can restrict it to a single unix group, then 440.

Updated with clarifying example skeletons of the methods:

sub readConfig { my $configfile = shift or die "No config file supplied"; # Read in the config file and set module-wide options # NB. I don't recommend "do" for this, as config files # shouldn't be able to contain executable code (IMHO) . . . } sub setConfig { my %opts = shift or die "No config options supplied"; # Set module-wide config based upon passed options . . . }

If anyone needs me I'll be in the Angry Dome.

In reply to Re: directory and file access for modules containing sensitive information by idsfa
in thread directory and file access for modules containing sensitive information by silent11

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.