creamygoodness has asked for the wisdom of the Perl Monks concerning the following question:

Greets,

I'm working on a CPAN distro with dozens of modules, several of which are outfitted with XS code. What's the best directory structure for this kind of thing?

Traditionally, .xs files and their associated Makefile.PL files get put in either the root directory of the distro, or one level above in a folder named for the last part of the package (e.g. Bar.xs from Foo::Bar gets put in MyDist-0.01/Bar/, along with Bar.pm). That doesn't scale well, unfortunately -- the distro's root directory gets real cluttered.

For now, what I'm doing is putting all the .pm files in MyDist-0.01/lib/ and giving each XS module a folder in MyDist-0.01/XS/. The upside of this strategy is that you can grok the distro's structure by looking only at Mydist-0.01/lib/, as if it were a pure Perl distro.

There are two downsides. First, the xs dirs are not organized hierarchically, but collected in a flat dir which doesn't mirror the distro's structure. Second, MakeMaker chdir's into the dir with the Makefile.PL before running it, so building the the path to the associated .pm file at MyDist-0.01/lib/Foo/Bar.pm gets messy. Right now, the code looks like...

my $path_to_pm_file = catfile(updir, updir, 'lib', 'Foo', 'Bar.pm');

... and I'm not even sure that's portable.

Suggestions?

--
Marvin Humphrey
Rectangular Research ― http://www.rectangular.com

Replies are listed 'Best First'.
Re: Distro with multiple XS modules
by randyk (Parson) on Sep 23, 2005 at 21:02 UTC
    You may want to check out how mod_perl and the perl glue of apreq approach this, both of which have multiple XS-based modules.
      Thanks! It seems like my intention to keep the .pm files in lib/ and thus separated from the .xs files is not standard practice. Food for thought.

      --
      Marvin Humphrey
      Rectangular Research ― http://www.rectangular.com