File Coverage

blib/lib/Perl/osnames.pm
Criterion Covered Total %
statement 15 15 100.0
branch 8 8 100.0
condition 2 6 33.3
subroutine 5 5 100.0
pod 2 2 100.0
total 32 36 88.8


line stmt bran cond sub pod time code
1             package Perl::osnames;
2              
3             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4             our $DATE = '2020-02-10'; # DATE
5             our $DIST = 'Perl-osnames'; # DIST
6             our $VERSION = '0.121'; # VERSION
7              
8 1     1   457 use strict;
  1         7  
  1         29  
9 1     1   4 use warnings;
  1         2  
  1         26  
10              
11 1     1   5 use Exporter qw(import);
  1         2  
  1         569  
12             our @EXPORT_OK = qw($data is_unix is_posix
13             $RE_OS_IS_KNOWN $RE_OS_IS_POSIX $RE_OS_IS_UNIX);
14              
15             our $data = [map {
16             chomp;
17             my @f = split /\s+/, $_, 3;
18             $f[1] = $f[1] eq '-' ? [] : [split /,/, $f[1]];
19             \@f;
20             } split /^/m, <<'_'];
21             aix posix,sysv,unix IBM AIX.
22             amigaos -
23             android sysv,unix
24             bsdos bsd,unix BSD/OS. Originally called BSD/386, also known as BSDi.
25             beos posix See also: haiku.
26             bitrig bsd,unix An OpenBSD fork.
27             dgux sysv,unix DG/UX.
28             dos -
29             dynixptx sysv,unix DYNIX/ptx.
30             cygwin posix,unix Unix-like emulation layer that runs on Windows.
31             darwin bsd,posix,unix Mac OS X. Does not currently (2013) include iOS. See also: iphoneos.
32             dec_osf - DEC Alpha.
33             dragonfly bsd,posix,unix DragonFly BSD.
34             freebsd bsd,posix,unix
35             gnu posix,unix Unix-like operating system which can have one these kernels: Hurd, Linux, FreeBSD.
36             gnukfreebsd bsd,posix,unix Debian GNU/kFreeBSD.
37             haiku posix See also: beos.
38             hpux posix,sysv,unix HP-UX.
39             interix posix,unix Optional, POSIX-compliant Unix subsystem for Windows NT. Also known as Microsoft SFU. No longer included in Windows nor supported.
40             iphoneos posix,unix Darwin-based OS X which is mostly POSIX compatible.
41             irix posix,sysv,unix
42             linux posix,sysv,unix
43             MacOS - Mac OS Classic (predates Mac OS X). See also: darwin, iphoneos.
44             machten bsd,unix MachTen, an operating system that runs virtually under Mac OS.
45             midnightbsd bsd,posix,unix
46             minix bsd,posix
47             mirbsd bsd,posix,unix MirOS BSD.
48             mpeix - MPEiX.
49             msys posix,unix A component of MinGW (minimalist Gnu for Windows) that is POSIX compatible.
50             MSWin32 - All Windows platforms including 95/98/ME/NT/2000/XP/CE/.NET. But does not include Cygwin (see "cygwin") or Interix (see "interix"). To get more details on which Windows you are on, use Win32::GetOSName() or Win32::GetOSVersion(). Ref: perlvar.
51             netbsd bsd,posix,unix
52             next unix NeXTSTEP OS.
53             nto unix ?
54             openbsd bsd,posix,unix
55             os2 - OS/2.
56             os390 ebcdic
57             os400 ebcdic
58             posix-bc ebcdic
59             qnx unix
60             riscos -
61             sco posix,sysv,unix SCO UNIX.
62             sco_sv posix,sysv,unix SCO OpenServer/UnixWare.
63             solaris posix,sysv,unix This includes the old SunOS.
64             sunos bsd,posix,unix SunOS, BSD-based predecessor to the System V Solaris.
65             svr4 posix,sysv,unix System V Release 4.
66             svr5 posix,sysv,unix System V Release 5.
67             unicos posix,sysv,unix Unix-like operating system for Cray supercomputers.
68             unicosmk posix,sysv,unix Unix-like operating system for Cray supercomputers.
69             vmesa ebcdic
70             VMS -
71             vos -
72             _
73              
74             # dump: display data as table
75             #use Data::Format::Pretty::Text qw(format_pretty);
76             #say format_pretty($data, {
77             # table_column_formats=>[{description=>[[wrap=>{columns=>40}]]}],
78             # table_column_orders=>[[qw/code summary description/]],
79             #});
80              
81             # debug: dump data
82             #use Data::Dump::Color;
83             #dd $data;
84              
85             our $RE_OS_IS_KNOWN = do {
86             my $re = join "|", map { $_->[0] } @$data;
87             qr/\A(?:$re)\z/;
88             };
89              
90             our $RE_OS_IS_POSIX = do {
91             my @os;
92             OS:
93             for my $rec (@$data) {
94             for (@{$rec->[1]}) {
95             do { push @os, $rec->[0]; next OS } if $_ eq 'posix';
96             }
97             }
98             my $re = join("|", @os);
99             qr/\A(?:$re)\z/;
100             };
101              
102             our $RE_OS_IS_UNIX = do {
103             my @os;
104             OS:
105             for my $rec (@$data) {
106             for (@{$rec->[1]}) {
107             do { push @os, $rec->[0]; next OS } if $_ eq 'unix';
108             }
109             }
110             my $re = join("|", @os);
111             qr/\A(?:$re)\z/;
112             };
113              
114             sub is_posix {
115 3   33 3 1 1086 my $os = shift || $^O;
116 3 100       30 return undef unless $os =~ $RE_OS_IS_KNOWN;
117 2 100       15 $os =~ $RE_OS_IS_POSIX ? 1:0;
118             }
119              
120             sub is_unix {
121 3   33 3 1 2412 my $os = shift || $^O;
122 3 100       24 return undef unless $os =~ $RE_OS_IS_KNOWN;
123 2 100       19 $os =~ $RE_OS_IS_UNIX ? 1:0;
124             }
125              
126             1;
127             # ABSTRACT: List possible $^O ($OSNAME) values, with description
128              
129             __END__