int main in C and hard coded directory separators in Perl

When I see a C program which features things like void main() or struct x *p = (struct x *) malloc (sizeof(struct x*)), alarm bells go off in my head, regardless of the stature of the person who wrote it.

I have decided, the Perl equivalent of those alarm bells is unwarranted the assumption that Unix style directory separators must work everywhere.

Looking at TestML::Runtime, I was horrified to find:

$self->{base} ||= $0 =~ m!(.*)/! ? $1 : ".";

This tries to extract the directory portion from the name of the executable by matching all characters up to a Unix style directory separator. If there is no Unix style directory separator in $0, it defaults to using the current directory, "." as the base.

So, what happens when this code is running via a test script invoked as perl t\some-test.t? Ooops! The test script cannot find its input files because it tries to look for them relative to the directory portion extracted above.

This wouldn't be so painful if people, more than two decades ago, had not already figured out how to parse a path into directory and file name components:

use File::Basename qw( dirname );
$self->{base} ||= dirname($0);

ought to work, no?!

Of course, it is probably more correct use File::Spec->splitpath, but I assume the author does want that dot in case $0 does not have directory portion.

I did not even know about the existence of TestML. It was a dependency for another module I did not know about, Pegex. All I did was try to install Inline::C.

My goal is not to fix individual modules.

My goal is to raise enough awareness of the interconnected issues that

  1. The assumption that Unix style directory separators work everywhere is unwarranted; and

  2. Perl has provided the necessary infrastructure to make this a non-issue for the longest time.

This way, if anyone other than me also tried to use Microsoft tools to build their own perl, and modules, the experience will be undermined by unforced errors.

I still can't get a smoke tester going on my Azure VM, and the free trial is about to run out. And, nine out of 10 issues I have encountered have been related to some assumption relating to paths. Each issue is small, trivial even, but they are still problems that ought not to exist.

I prefer to submit pull requests instead of bug reports, but the prospect of figuring out Zilla::Dist was not enticing.