During my research of how to find out which operating system is running for the Devel::Platform::Info::Win32 module I found I could pull information from the following sources,
- Win32::GetOSName (this seems to be wrong in a lot of cases, a problem I’m conscious this module could suffer from in the future)
- OSVERSIONINFOEX returned by GetVersionEx
- Environment variables
In practice with my initial implementation I haven’t pulled it from everywhere. Largely this is due to a lack of courage on my part. That and these concerns,
- We need to make sure the module runs on as many machines as possible
- Getting native win32 calls wrong seems to be a quick way to exit perl
- 64 bit perl doesn’t seem to have all the same stuff loaded by default (at least the ActiveState version).
Should I fix this? It occurs to me that I’m probably being too cautious and if I add careful calls to check that modules exist before trying to use them and ensure I am checking everything (like the presence of Win32 API calls) then it ought to be able to continue to work on all platforms.
The thing that’s bugging me is that I know I need to use LoadLibrary and GetProcAddress. When I look those up in the Win32 help though they say that I should use Win32::API instead. Only that’s not present on my Perl 64 ActiveState distro making it not terribly useful. Given the simple nature of most of what I need to do I’d really like to call the original methods since they seem to be consistently there in most distributions. When I’ve googled the method though I’m coming up with very little by way of code that appears to use the calls so I’m really struggling to figure out what I should do. I’d normally expect some degree of prior art to be able to use as a guide with what to do.
I suppose I could create an XS module but I don’t think that’s an ideal option since we’d rather keep this module as lightweight as possible. I want it to run on any win32 perl with as little fuss as possible and an XS module isn’t likely to do that. This is a module for use across a lot of machines, not just for my own personal use where I could make compromises like that.
Of course you’re probably wondering what I’m complaining about. The net effect of what I haven’t done is that the module isn’t as exact at determining the OS version as it could be. It won’t get Windows Home Server. It doesn’t know the difference between Windows Server 2003 and Windows Server 2003 R2 or whether it’s a Small Business Server etc. It largely does get the major operating systems right though, at least as far as I’ve been able to test, from Windows 2000 onwards anyway.
(Incidentally I’m not trying to ding the ActiveState version of Perl. It’s my default Perl on Windows so I just have more of a clue of the out of the box behaviour).