Subject: | Only works for Windows not Unix. |
Date: | Wed, 28 Nov 2012 21:43:53 -0500 |
To: | bug-Dist-Zilla-Plugin-OSPrereqs [...] rt.cpan.org |
From: | David Yingling <deeelwy [...] gmail.com> |
Dist::Zilla::Plugin::OSPrereqs uses $^O to determine if the listed prereqs should be prereqs or not. This works OK for Windows, except if you run a perl compiled under Cygwin, because under Cygwin $^O is Cygwin instead of Win32 according to perlport. So that is perhaps a bug as well, because it means adding a prereq of Win32 will fail if you try to install it with a perl compiled under Cygwin, because the perl on Cygwin will have a $^O variable set to Cygwin instead of Win32.
Interestingly Perl::OSType has Cygwin mapped to Unix, which is both right and wrong at the same time, and probably not worth changing. Perlport, by the way, lists Cygwin under Dos and derivatives.
Similarly, just like Windows most of Unix-like OSes are similar enough that you can treat them the same. However, because Perl::OSType relies on $^O, you can only easily specify prereqs that should only be prereqs on Windows, because nobody is going to do something crazy like I've pasted below to use only a prereq on Unix.
[OSPrereqs / Darwin]
Privileges::Drop = 0
[OSPrereqs / aix]
Privileges::Drop = 0
[OSPrereqs / bsdos]
Privileges::Drop = 0
[OSPrereqs / dgux]
Privileges::Drop = 0
...( I got sick of copying and pasting, but you get the idea :) )...
...I have not even gotten to Linux, or any Unix that's still popular.
...And so on for everything listed at http://perldoc.perl.org/perlport.html#PLATFORMS in the Unix section.
This seems like a design flaw. Dist::Zilla::Plugin::OSPrereqs was probably mostly written to only make something a requirement on Windows without testing or considering trying to use it to do the same thing on Unix.
The easiest fix I can think of is to add Perl::OSType as a dependency. Then instead of relying on $^O. Just make "Windows" magical, and support all $^O values that could be Windows via Perl::OSType or a custom hash table based on perlport if you don't want to add a dependency. And also make "Unix" magical too, and these two strings will be run through Perl::OSType to see if the perl in use is "Windows" or "Unix." Doing it this way would also not change the current behavior regarding using "Win32".
Instead of something too simple like:
$^O eq $user_input
You could do something like:
if (grep $user_input eq $_, qw(Windows Unix)) {
if (is_os_type($user_input)) {
# Add the dependency.
}
# Add code that handles $^O too.
}
You could also add a magical one for Cygwin too. Perhaps call it "WindowsORCygwin" that will install the prereq on Windows, and would also install it if running in the fake Unix environment of Cygwin.
Thanks,
Dave.