Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Well, you can iterate over @INC, or directly evaluate $INC{'App/Package.pm'}, or use __FILE__ as already suggested. But I'm aware that you are looking for a more secure method, and here it can get murky.

If you have relative paths in @INC you must assert that your code did not do a chdir between loading the library and reading the config file, or you might either not find your config file, or read some other file which per accident (or per malicious action) has the relative path you are using after changing the directory.

I would also consider whether putting a configuration file in the library path is a good idea. If the contents of the config file never change, then you have the option of putting them in a __DATA__ section of a config module, and have get_config() reading from the DATA file handle in that module. If, however, the contents may change over time, then you need to grant write permission to a file within the library path, which doesn't play well with the module installers and may create issues when upgrading the application.

I recommend to check out CPAN's File::HomeDir module, which has functions like my_dist_data and my_dist_config to obtain paths to directories for data and configuration files. They are outside the library path, though, so your installation / initialisation steps need to be adjusted accordingly.


In reply to Re: Path relative to package by haj
in thread Path relative to package by DreamT

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-19 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found