On Oct 18, 2007, at 4:28 PM, Jonathan Rockway wrote:
Eric Wilhelm wrote:
If we're voting, I would prefer to avoid having non-modules in @INC.
I agree. How about using Module::Install to install files to a known
location (auto), and then File::ShareDir to get at those files?
I've had more thoughts on this:
In Build.PL:
# Distro name is My-Distro-Name
my $support_files_install_dir = 'arch/auto/My/Distro/Name';
my $lookup_tables = {
'LookupTables/Colors.txt' => "$support_files_install_dir/
Colors.txt",
'LookupTables/Smells.txt' => "$support_files_install_dir/
Colors.txt",
};
my $build = Module::Build->new(
module_name => 'My::Distro::Name',
license => 'perl',
requires => {
'perl' => '5.8.6',
'File::ShareDir' => '0.05',
},
build_requires => {
'Module::Build' => '0.28',
},
LookupTables_files => $lookup_tables,
);
$build->add_build_element('LookupTables');
$build->create_build_script;
exit;
On my system this will do:
Installing /Library/Perl/5.8.6/darwin-thread-multi-2level/auto/My/
Distro/Name/LookupTables/Colors.txt
Installing /Library/Perl/5.8.6/darwin-thread-multi-2level/auto/My/
Distro/Name/LookupTables/Smells.txt
Then, I can do:
use My::Distro::Name;
use File::ShareDir;
$color_table = File::ShareDir::dist_file('My-Distro-Name',
'LookupTables/Colors.txt')
# finds: /Library/Perl/5.8.6/darwin-thread-multi-2level/auto/My/
Distro/Name/LookupTables/Colors.txt
So far so good.
But, some issues:
1. The calling code needs to compile 'My::Distro::Name' in order
to find
resources associated with that distro.
2. There is not a direct way to obtain the path to the
'LookupTables' directory itself.
That is, you could do:
File::Spec->catdir( File::Share::dist_dir('My-Distro-Name'),
'LookupTables')
But not:
File::Share::find_dir('My-Distro-Name', 'LookupTables'); #
hmm, maybe i should submit a patch
Finally, I am no longer sure it is such a bad thing to have non-
modules directly in @INC. I am currently undecided about this.
Java seems to do just fine with having general support for accessing
any kind of resource "... in a way that is independent of the
location of the code" using the getResource() method.
I wonder (not certain, just thinking out loud) if a similar facility
for Perl would be a good complement to the features already provided
by File::ShareDir?
Here's the API reference on java.lang.ClassLoader.getResource()
getResource
public URL getResource(String name)
Finds the resource with the given name. A resource is some
data (images, audio, text, etc) that can be accessed by class
code in a way that is independent of the location of the code.
The name of a resource is a '/'-separated path name that
identifies the resource.
This method will first search the parent class loader for
the resource; if the parent is null the path of the class
loader built-in to the virtual machine is searched. That failing,
this method will invoke findResource(String) to find the resource.
Parameters:
name - The resource name
Returns:
A URL object for reading the resource, or
null if the resource could not be found or the invoker
doesn't have adequate privileges to get the resource.
-------------------------------------------------------
Matisse Enzer <[EMAIL PROTECTED]>
http://www.matisse.net/ - http://www.eigenstate.net/