Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I distribute data files with Perl modules?

Tags:

perl

cpan

I've started a module-starter (with --builder=Module::Build). I want to use SQL::Library to collect my SQL into an .ini file... but in order to find the file during run time, I need to know its exact path. How do I get the path of the "data directory" of a module at run time?

Until now, I've been using FindBin (like "$FindBin::Bin/../../path/to/module/datafiles/foo.ini", but I found this is not very robust (For example, it seems to break when there are two programs with the same name in two different dirs in PATH).

like image 541
user1481 Avatar asked Feb 14 '12 23:02

user1481


People also ask

What is a Perl distribution?

In Perl a true value is any value that is not: null, zero or a zero-length string. A distribution is a collection of files that usually includes a Perl module and several other files.

What is the difference between package and module in Perl?

A Perl package is a collection of code which resides in its own namespace. Perl module is a package defined in a file having the same name as that of the package and having extension . pm. Two different modules may contain a variable or a function of the same name.

How many Perl modules are there?

Perl modules are a set of related functions in a library file. They are specifically designed to be reusable by other modules or programs. There are 108,000 modules ready for you to use on the Comprehensive Perl Archive Network.


1 Answers

This is what File::ShareDir is for. Since you're using Module::Build, you'll need to set the share_dir parameter (and require Module::Build 0.36) in order to have your data files installed along with your module. Then, in your code, you'll use File::ShareDir to calculate the path of foo.ini (e.g. dist_file('My-Dist', 'foo.ini'))

like image 91
cjm Avatar answered Sep 20 '22 06:09

cjm