1use strict; 2use warnings; 3 4package Perl::OSType; 5# ABSTRACT: Map Perl operating system names to generic types 6 7our $VERSION = '1.010'; 8 9require Exporter; 10our @ISA = qw(Exporter); 11 12our %EXPORT_TAGS = ( all => [qw( os_type is_os_type )] ); 13 14our @EXPORT_OK = @{ $EXPORT_TAGS{all} }; 15 16# originally taken from Module::Build by Ken Williams et al. 17my %OSTYPES = qw( 18 aix Unix 19 bsdos Unix 20 beos Unix 21 bitrig Unix 22 dgux Unix 23 dragonfly Unix 24 dynixptx Unix 25 freebsd Unix 26 linux Unix 27 haiku Unix 28 hpux Unix 29 iphoneos Unix 30 irix Unix 31 darwin Unix 32 machten Unix 33 midnightbsd Unix 34 minix Unix 35 mirbsd Unix 36 next Unix 37 openbsd Unix 38 netbsd Unix 39 dec_osf Unix 40 nto Unix 41 svr4 Unix 42 svr5 Unix 43 sco Unix 44 sco_sv Unix 45 unicos Unix 46 unicosmk Unix 47 solaris Unix 48 sunos Unix 49 cygwin Unix 50 msys Unix 51 os2 Unix 52 interix Unix 53 gnu Unix 54 gnukfreebsd Unix 55 nto Unix 56 qnx Unix 57 android Unix 58 59 dos Windows 60 MSWin32 Windows 61 62 os390 EBCDIC 63 os400 EBCDIC 64 posix-bc EBCDIC 65 vmesa EBCDIC 66 67 MacOS MacOS 68 VMS VMS 69 vos VOS 70 riscos RiscOS 71 amigaos Amiga 72 mpeix MPEiX 73); 74 75sub os_type { 76 my ($os) = @_; 77 $os = $^O unless defined $os; 78 return $OSTYPES{$os} || q{}; 79} 80 81sub is_os_type { 82 my ( $type, $os ) = @_; 83 return unless $type; 84 $os = $^O unless defined $os; 85 return os_type($os) eq $type; 86} 87 881; 89 90=pod 91 92=encoding UTF-8 93 94=head1 NAME 95 96Perl::OSType - Map Perl operating system names to generic types 97 98=head1 VERSION 99 100version 1.010 101 102=head1 SYNOPSIS 103 104 use Perl::OSType ':all'; 105 106 $current_type = os_type(); 107 $other_type = os_type('dragonfly'); # gives 'Unix' 108 109=head1 DESCRIPTION 110 111Modules that provide OS-specific behaviors often need to know if 112the current operating system matches a more generic type of 113operating systems. For example, 'linux' is a type of 'Unix' operating system 114and so is 'freebsd'. 115 116This module provides a mapping between an operating system name as given by 117C<$^O> and a more generic type. The initial version is based on the OS type 118mappings provided in L<Module::Build> and L<ExtUtils::CBuilder>. (Thus, 119Microsoft operating systems are given the type 'Windows' rather than 'Win32'.) 120 121=head1 USAGE 122 123No functions are exported by default. The export tag ":all" will export 124all functions listed below. 125 126=head2 os_type() 127 128 $os_type = os_type(); 129 $os_type = os_type('MSWin32'); 130 131Returns a single, generic OS type for a given operating system name. With no 132arguments, returns the OS type for the current value of C<$^O>. If the 133operating system is not recognized, the function will return the empty string. 134 135=head2 is_os_type() 136 137 $is_windows = is_os_type('Windows'); 138 $is_unix = is_os_type('Unix', 'dragonfly'); 139 140Given an OS type and OS name, returns true or false if the OS name is of the 141given type. As with C<os_type>, it will use the current operating system as a 142default if no OS name is provided. 143 144=head1 SEE ALSO 145 146=over 4 147 148=item * 149 150L<Devel::CheckOS> 151 152=back 153 154=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan 155 156=head1 SUPPORT 157 158=head2 Bugs / Feature Requests 159 160Please report any bugs or feature requests through the issue tracker 161at L<https://github.com/Perl-Toolchain-Gang/Perl-OSType/issues>. 162You will be notified automatically of any progress on your issue. 163 164=head2 Source Code 165 166This is open source software. The code repository is available for 167public review and contribution under the terms of the license. 168 169L<https://github.com/Perl-Toolchain-Gang/Perl-OSType> 170 171 git clone https://github.com/Perl-Toolchain-Gang/Perl-OSType.git 172 173=head1 AUTHOR 174 175David Golden <dagolden@cpan.org> 176 177=head1 CONTRIBUTORS 178 179=for stopwords Chris 'BinGOs' Williams David Golden Graham Ollis Jonas B. Nielsen Owain G. Ainsworth Paul Green Piotr Roszatycki 180 181=over 4 182 183=item * 184 185Chris 'BinGOs' Williams <chris@bingosnet.co.uk> 186 187=item * 188 189David Golden <xdg@xdg.me> 190 191=item * 192 193Graham Ollis <plicease@cpan.org> 194 195=item * 196 197Jonas B. Nielsen <jonasbn@hoarfrost.local> 198 199=item * 200 201Owain G. Ainsworth <oga@nicotinebsd.org> 202 203=item * 204 205Paul Green <Paul.Green@stratus.com> 206 207=item * 208 209Piotr Roszatycki <piotr.roszatycki@gmail.com> 210 211=back 212 213=head1 COPYRIGHT AND LICENSE 214 215This software is copyright (c) 2016 by David Golden. 216 217This is free software; you can redistribute it and/or modify it under 218the same terms as the Perl 5 programming language system itself. 219 220=cut 221 222__END__ 223 224 225# vim: ts=4 sts=4 sw=4 et: 226