kentnl / File-ShareDir-ProjectDistDir

Simple set-and-forget using of a '/share' directory in your projects root
Other
5 stars 5 forks source link

module_* #5

Open xenoterracide opened 11 years ago

xenoterracide commented 11 years ago

any chance you'll be adding support for things like module_dir? so I could write

my $config  = module_file( __PACKAGE__, 'config.yml' );
kentfredric commented 11 years ago

The problem therein is that while its easy to resolve where the sharedir is for __PACKAGE__ in an install ENV, its not so straight forward during development, because of the property where 1 dist has 1 share dir, but 1 dist has many modules , and each module has its own sharedir, and thus, 1 dist -> many module sharedirs.

ie: When you install those sharedirs with Dist::Zilla, you often have to provide a mapping to tell File::ShareDir::Install where to find a given share dir for a given module, and an equivalent is thus mandatory for this module, which somewhat breaks the notion of "no configuration, just works" that this module mostly relies on.

If you can propose some syntax to make this mapping possible, I'm all for it, but I'm inclined to think it would be grounds for a distinct module to prevent the guts getting too messy.

xenoterracide commented 11 years ago

outside of saying standard File::ShareDir location, or look in share (maybe some defined default substructure of share) , I don't have any good suggestions. It's likely I don't understand the problem well enough. Realistically this is about me not liking hardcoding the current dist in the module.

kentfredric commented 11 years ago

The very best I think you'll be able to achieve automatically, is a layout such as

/
/share/
/share/Some::Module::Name::Here

But that seems problematic as I'd imagine not all filesystem types support :: in filenames.

A transliteration such as

/
/share/
/share/Some-Module-Name-Here

could work, but thats still rather wordy.

I think the best I can muster is having a default of /share/Some-Module-Name-Here, and look for a sub on __PACKAGE__ called _develop_share_subdir that simply returned the name of the development sharedir to use.

So the effective synopsis would be


    package Long::Name::Here;
    use File::ShareDir::ProjectDistDir::Module qw( module_dir module_file );
    sub _develop_share_subdir { 'longnamehere' }
    ...
    sub bar {
      my $dir = module_dir(__PACKAGE__ ); 
      my $file = module_file( __PACKAGE__, 'config.yml' );
    }