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
|
|