Testing your File::ShareDir based dist now possible.

For the last few months, every time I've had a dist that needed File::ShareDir to do its dirty work, I've used various tricks to make it work.
  • Simply not test it:
    Sad as this may seem, this is pretty much the primary approach because it was too confusing
  • Invest a bit of code into overriding sharedir behaviour
    This usually involved having some coderef or lazy-loaded attribute that was normally populated by File::ShareDir, instead provided during test via hard-coding it.

Enter Test::File::ShareDir

I uploaded Test::File::ShareDir this morning to CPAN, which lets you do this:
use Test::More;

use FindBin;

use Test::File::ShareDir
  -root => "$FindBin::Bin/../",
  -share => {
    -module => { 'My::Module' => 'share/MyModule' }
This configuration would be sufficient to use in a test in t/ for a distribution shipping My::Module along with its corresponding shared directory share/MyModule. If you were shipping this dist with Dist::Zilla, you'd have something like this in dist.ini
My::Module = share/MyModule
I plan to add support for 'package' style ShareDir support, but for now, module share dirs are sufficient. Enjoy =).