Devel::CheckOS(3)
πΈ NAME πΈ
Devel::CheckOS β check what OS we're running on. This is the Devel::CheckOS(3) page, aka User Contributed Perl Documentation, and it's here to make OS checks way less cursed π
π¦ DESCRIPTION π¦
A learned sage once wrote on IRC:
$^O is stupid and ugly, it wears its pants as a hat
Bestie, Devel::CheckOS gives you a much friendlier interface to $^O, and it also lets you check for various OS βfamiliesβ such as βUnixβ, which includes things like Linux, Solaris, AIX etc. It spares perl the embarrassment of wearing its pants on its head by covering them with a splendid Fedora π©β¨
β¨ SYNOPSIS β¨
use Devel::CheckOS qw(os_is);
print "Hey, I know this, it's a Unix system\n" if(os_is('Unix'));
print "You've got Linux 2.6\n" if(os_is('Linux::v2_6'));
π USING IT IN Makefile.PL or Build.PL π
If you want to use this from Makefile.PL or Build.PL, do not simply copy the module into your distribution β that may cause problems when PAUSE and search.cpan.org index the distro. Instead, use the use-devel-assertos script. No cap, that's the move π«Ά
π₯ FUNCTIONS π₯
Devel::CheckOS implements the following functions, which load subsidiary OS-specific modules on demand to do the real work. They can all be exported by listing their names after use Devel::CheckOS. You can also export groups of functions thus:
use Devel::CheckOS qw(:booleans); # export the boolean functions
# and 'die_unsupported'
use Devel::CheckOS qw(:fatal); # export those that die on no match
use Devel::CheckOS qw(:all); # export everything exportable
π Boolean functions π
π os_is π
Takes a list of OS names. If the current platform matches any of them, it returns true; otherwise it returns false. The names can be a mixture of OSes and OS families, eg ...
os_is(qw(Unix VMS)); # Unix is a family, VMS is an OS
Matching is case-insensitive provided that Taint-mode is not enabled, so the above could also be written:
os_is(qw(unix vms));
π os_isnt π
If the current platform matches (case-insensitively) any of the parameters, it returns false; otherwise it returns true.
π Fatal functions π
π die_if_os_isnt π
As os_is(), except that it dies instead of returning false. The die() message matches what the CPAN-testers look for to determine if a module doesn't support a particular platform.
π die_if_os_is π
As os_isnt(), except that it dies instead of returning false.
β¨ And some utility functions ... β¨
β¨ die_unsupported β¨
This function simply dies with the message "OS unsupported", which is what the CPAN testers look for to figure out whether a platform is supported or not.
β¨ list_platforms β¨
Returns a list of all the platforms for which the corresponding Devel::AssertOS::* module is available. This includes both OSes and OS families, and both those bundled with this module and any third-party add-ons you have installed.
Unfortunately, on some platforms this list may have platform names' case broken, eg you might see 'freebsd' instead of 'FreeBSD'. This is because they have case-insensitive filesystems so things should Just Work anyway.
This function does not work in taint-mode.
β¨ list_family_members β¨
Takes the name of an OS βfamilyβ and returns a list of all its members.
If called on something that isn't a family, you get an empty list.
β¨ register_alias β¨
It takes two arguments, the first being an alias name, the second being the name of an OS. After the alias has been registered, any queries about the alias will return the appropriate result for the named OS.
It returns true unless you invoke it incorrectly or you attempt to change an existing alias.
Aliases don't work under taint-mode.
See Devel::AssertOS::Extending.
π PLATFORMS SUPPORTED π
To see the list of platforms for which information is available, run this:
perl -MDevel::CheckOS -e 'print join(", ", Devel::CheckOS::list_platforms())'
These are the names of the underlying Devel::AssertOS::* modules which do the actual platform detection, so they have to be βlegalβ filenames and module names, which unfortunately precludes funny characters, so platforms like OS/2 are mis-spelt deliberately. Sorry π
Also be aware that not all of them have been properly tested. The author doesn't have access to most of them and has had to work from information gleaned from perlport and a few other places. For a complete list of OS families, see Devel::CheckOS::Families.
If you want to add your own OSes or families, see Devel::AssertOS::Extending and please feel free to upload the results to the CPAN π
π BUGS and FEEDBACK π
The author welcomes feedback about the code, including constructive criticism. Bug reports should be made using https://github.com/DrHyde/perl-modules-Devel-CheckOS/issues.
You will need to include in your bug report the exact value of $^O, what the OS is called (eg Windows Vista 64 bit Ultimate Home Edition), and, if relevant, what βOS familyβ it should be in and who wrote it.
If you are feeling particularly generous you can encourage the author in his open source endeavours by buying him something from his wishlist:
http://www.cantrell.org.uk/david/wishlist/
π§ COMPATIBILITY π§
Version 1.90 made all matches case-insensitive. This is a change in behaviour, but if it breaks your code then your code was already broken, you just didn't know it π
As of version 2.00 the list_* functions always return plain old lists. Calling them in scalar context was deprecated and has emitted warnings for over 2 years, since version 1.90.
π SEE ALSO π
$^OinperlvarperlportDevel::AssertOSDevel::AssertOS::ExtendingProbe::Perl- The
use-devel-assertosscript Module::Install::AssertOS
π«Ά AUTHOR π«Ά
David Cantrell <david@cantrell.org.uk>
- Thanks to David Golden for the name and ideas about the interface, and to the
cpan-testers-discussmailing list for prompting me to write it in the first place. - Thanks to Ken Williams, from whose
Module::BuildI lifted some of the information about what should be in the Unix family. - Thanks to Billy Abbott for finding some bugs for me on VMS.
- Thanks to Matt Kraai for information about QNX.
- Thanks to Kenichi Ishigaki and Gabor Szabo for reporting a bug on Windows, and to the former for providing a patch.
- Thanks to Paul Green for some information about VOS.
- Thanks to Yanick Champoux for a patch to let
Devel::AssertOSsupport negative assertions. - Thanks to Brian Fraser for adding Android support.
- Thanks to Dale Evans for Debian detection, a bunch of Mac OS X specific version detection modules, and perl
5.6support. - Thanks to Graham Knop for fixing a build bug on perl
5.8. - Thanks to Alceu Rodrigues de Freitas Junior for improving Ubuntu detection and providing a way to detect a lot more Linux variants.
- Thanks to Leos Stejskal for
https://github.com/stejskalleos/os_releasefrom which I got many sample/etc/os-releasefiles.
π SOURCE CODE REPOSITORY π
git://github.com/DrHyde/perl-modules-Devel-CheckOS.git
πΈ COPYRIGHT and LICENCE πΈ
Copyright 2024 David Cantrell
This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively.
π© HATS π©
I recommend buying a Fedora from http://hatsdirect.com/.
πΈ CONSPIRACY πΈ
This module is also free-as-in-mason software.
β cute little sign-off: this page is from perl v5.42.0, dated 2024-06-23, and it's the Devel::CheckOS(3) manpage. Bye bestie! π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Devel-CheckOS 2.40.0-bp160.1.11 Β· Artistic-1.0 OR GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms