1Devel::CheckOS(3) User Contributed Perl Documentation Devel::CheckOS(3)
2
3
4
6 Devel::CheckOS - check what OS we're running on
7
9 A learned sage once wrote on IRC:
10
11 $^O is stupid and ugly, it wears its pants as a hat
12
13 Devel::CheckOS provides a more friendly interface to $^O, and also lets
14 you check for various OS "families" such as "Unix", which includes
15 things like Linux, Solaris, AIX etc.
16
17 It spares perl the embarrassment of wearing its pants on its head by
18 covering them with a splendid Fedora.
19
21 use Devel::CheckOS qw(os_is);
22 print "Hey, I know this, it's a Unix system\n" if(os_is('Unix'));
23
24 print "You've got Linux 2.6\n" if(os_is('Linux::v2_6'));
25
27 If you want to use this from Makefile.PL or Build.PL, do not simply
28 copy the module into your distribution as this may cause problems when
29 PAUSE and search.cpan.org index the distro. Instead, use the use-
30 devel-assertos script.
31
33 Devel::CheckOS implements the following functions, which load
34 subsidiary OS-specific modules on demand to do the real work. They can
35 all be exported by listing their names after "use Devel::CheckOS". You
36 can also export groups of functions thus:
37
38 use Devel::CheckOS qw(:booleans); # export the boolean functions
39 # and 'die_unsupported'
40
41 use Devel::CheckOS qw(:fatal); # export those that die on no match
42
43 use Devel::CheckOS qw(:all); # export everything exportable
44
45 Boolean functions
46 os_is
47
48 Takes a list of OS names. If the current platform matches any of them,
49 it returns true, otherwise it returns false. The names can be a
50 mixture of OSes and OS families, eg ...
51
52 os_is(qw(Unix VMS)); # Unix is a family, VMS is an OS
53
54 Matching is case-insensitive provided that Taint-mode is not enabled,
55 so the above could also be written:
56
57 os_is(qw(unix vms));
58
59 os_isnt
60
61 If the current platform matches (case-insensitively) any of the
62 parameters it returns false, otherwise it returns true.
63
64 Fatal functions
65 die_if_os_isnt
66
67 As os_is(), except that it dies instead of returning false. The die()
68 message matches what the CPAN-testers look for to determine if a module
69 doesn't support a particular platform.
70
71 die_if_os_is
72
73 As os_isnt(), except that it dies instead of returning false.
74
75 And some utility functions ...
76 die_unsupported
77
78 This function simply dies with the message "OS unsupported", which is
79 what the CPAN testers look for to figure out whether a platform is
80 supported or not.
81
82 list_platforms
83
84 When called in list context, return a list of all the platforms for
85 which the corresponding Devel::AssertOS::* module is available. This
86 includes both OSes and OS families, and both those bundled with this
87 module and any third-party add-ons you have installed.
88
89 In scalar context, returns a hashref keyed by platform with the
90 filename of the most recent version of the supporting module that is
91 available to you. This behaviour is deprecated.
92
93 Unfortunately, on some platforms this list may have file case broken.
94 eg, some platforms might return 'freebsd' instead of 'FreeBSD'. This
95 is because they have case-insensitive filesystems so things should Just
96 Work anyway.
97
98 This function does not work in taint-mode.
99
100 list_family_members
101
102 Takes the name of an OS 'family' and returns a list of all its members.
103 In list context, you get a list, in scalar context you get an arrayref.
104
105 If called on something that isn't a family, you get an empty list (or a
106 ref to an empty array).
107
108 register_alias
109
110 It takes two arguments, the first being an alias name, the second being
111 the name of an OS. After the alias has been registered, any queries
112 about the alias will return the appropriate result for the named OS.
113
114 It returns true unless you invoke it incorrectly or you attempt to
115 change an existing alias.
116
117 Aliases don't work under taint-mode.
118
119 See Devel::AssertOS::Extending.
120
122 To see the list of platforms for which information is available, run
123 this:
124
125 perl -MDevel::CheckOS -e 'print join(", ", Devel::CheckOS::list_platforms())'
126
127 These are the names of the underlying Devel::AssertOS::* modules which
128 do the actual platform detection, so they have to be 'legal' filenames
129 and module names, which unfortunately precludes funny characters, so
130 platforms like OS/2 are mis-spelt deliberately. Sorry.
131
132 Also be aware that not all of them have been properly tested. I don't
133 have access to most of them and have had to work from information
134 gleaned from perlport and a few other places. For a complete list of
135 OS families, see Devel::CheckOS::Families.
136
137 If you want to add your own OSes or families, see
138 Devel::AssertOS::Extending and please feel free to upload the results
139 to the CPAN.
140
142 I welcome feedback about my code, including constructive criticism.
143 Bug reports should be made using
144 <https://github.com/DrHyde/perl-modules-Devel-CheckOS/issues>.
145
146 You will need to include in your bug report the exact value of $^O,
147 what the OS is called (eg Windows Vista 64 bit Ultimate Home Edition),
148 and, if relevant, what "OS family" it should be in and who wrote it.
149
150 If you are feeling particularly generous you can encourage me in my
151 open source endeavours by buying me something from my wishlist:
152 <http://www.cantrell.org.uk/david/wishlist/>
153
155 Version 1.90 made all matches case-insensitive. This is a change in
156 behaviour, but if it breaks your code then your code was already
157 broken, you just didn't know it.
158
160 At some point after April 2024 the "list_family_members" and
161 "list_platforms" functions will stop being sensitive to whether they
162 are called in list context or not, and will always return a list. From
163 now until then calling them in non-list context will emit a warning.
164 You can turn that off by setting
165 $Devel::CheckOS::NoDeprecationWarnings::Context to a true value.
166
168 $^O in perlvar
169
170 perlport
171
172 Devel::AssertOS
173
174 Devel::AssertOS::Extending
175
176 Probe::Perl
177
178 The use-devel-assertos script
179
180 Module::Install::AssertOS
181
183 David Cantrell <david@cantrell.org.uk>
184
185 Thanks to David Golden for the name and ideas about the interface, and
186 to the cpan-testers-discuss mailing list for prompting me to write it
187 in the first place.
188
189 Thanks to Ken Williams, from whose Module::Build I lifted some of the
190 information about what should be in the Unix family.
191
192 Thanks to Billy Abbott for finding some bugs for me on VMS.
193
194 Thanks to Matt Kraai for information about QNX.
195
196 Thanks to Kenichi Ishigaki and Gabor Szabo for reporting a bug on
197 Windows, and to the former for providing a patch.
198
199 Thanks to Paul Green for some information about VOS.
200
201 Thanks to Yanick Champoux for a patch to let Devel::AssertOS support
202 negative assertions.
203
204 Thanks to Brian Fraser for adding Android support.
205
206 Thanks to Dale Evans for Debian detection, a bunch of Mac OS X specific
207 version detection modules, and perl 5.6 support.
208
209 Thanks to Graham Knop for fixing a build bug on perl 5.8.
210
212 <git://github.com/DrHyde/perl-modules-Devel-CheckOS.git>
213
215 Copyright 2023 David Cantrell
216
217 This software is free-as-in-speech software, and may be used,
218 distributed, and modified under the terms of either the GNU General
219 Public Licence version 2 or the Artistic Licence. It's up to you which
220 one you use. The full text of the licences can be found in the files
221 GPL2.txt and ARTISTIC.txt, respectively.
222
224 I recommend buying a Fedora from <http://hatsdirect.com/>.
225
227 This module is also free-as-in-mason software.
228
229
230
231perl v5.36.0 2023-02-05 Devel::CheckOS(3)