| 1 | package Devel::CheckOS; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 92 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 55 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 54 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | # if we're loading this from Makefile.PL, FFR might not yet be installed | ||||||||||||||||||||||||||||
| 8 | 48 | ▶ | eval 'use File::Find::Rule'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 53 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 54 | ▶ | use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS %OS_ALIASES); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 40 | our $VERSION = '2.04'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 38 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 16 | 38 | @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 17 | os_is os_isnt die_if_os_is die_if_os_isnt die_unsupported | ||||||||||||||||||||||||||||
| 18 | list_platforms list_family_members register_alias | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | 40 | %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 21 | all => \@EXPORT_OK, | ||||||||||||||||||||||||||||
| 22 | booleans => [qw(os_is os_isnt die_unsupported)], | ||||||||||||||||||||||||||||
| 23 | fatal => [qw(die_if_os_is die_if_os_isnt)] | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # get a list of the .pm files under a list of dirs, or the empty list | ||||||||||||||||||||||||||||
| 27 | # in taint mode | ||||||||||||||||||||||||||||
| 28 | 1193 | ▶ | sub _find_pm_files_in_dirs { | ||||||||||||||||||||||||||
|
Subroutine
_find_pm_files_in_dirs: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 1193 | my @files; | |||||||||||||||||||||||||||
| 30 | 1184 | eval { @files = File::Find::Rule->file()->name('*.pm')->in(@_) }; | |||||||||||||||||||||||||||
| 31 | 1192 | return @files; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 38 | ▶ | if(exists($INC{'File/Find/Rule.pm'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 38 | foreach my $alias_module ( | |||||||||||||||||||||||||||
| 36 | _find_pm_files_in_dirs( | ||||||||||||||||||||||||||||
| 37 | 340 | grep { -d } | |||||||||||||||||||||||||||
| 38 | 338 | map { File::Spec->catdir($_, qw(Devel AssertOS Alias)) } | |||||||||||||||||||||||||||
| 39 | @INC | ||||||||||||||||||||||||||||
| 40 | ) | ||||||||||||||||||||||||||||
| 41 | ) { | ||||||||||||||||||||||||||||
| 42 | 108 | my(undef, undef, $file_part) = File::Spec->splitpath($alias_module); | |||||||||||||||||||||||||||
| 43 | 110 | $file_part =~ s/\.pm$//; | |||||||||||||||||||||||||||
| 44 | 46 | ▶ | eval "use Devel::AssertOS::Alias::$file_part"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 108 | ▶ | warn("Bad alias module 'Devel::AssertOS::Alias::$file_part' ignored\n") if($@); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head1 NAME | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | Devel::CheckOS - check what OS we're running on | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | A learned sage once wrote on IRC: | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | $^O is stupid and ugly, it wears its pants as a hat | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | Devel::CheckOS provides a more friendly interface to $^O, and also lets | ||||||||||||||||||||||||||||
| 60 | you check for various OS "families" such as "Unix", which includes things | ||||||||||||||||||||||||||||
| 61 | like Linux, Solaris, AIX etc. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | It spares perl the embarrassment of wearing its pants on its head by | ||||||||||||||||||||||||||||
| 64 | covering them with a splendid Fedora. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | use Devel::CheckOS qw(os_is); | ||||||||||||||||||||||||||||
| 69 | print "Hey, I know this, it's a Unix system\n" if(os_is('Unix')); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | print "You've got Linux 2.6\n" if(os_is('Linux::v2_6')); | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head1 USING IT IN Makefile.PL or Build.PL | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | If you want to use this from Makefile.PL or Build.PL, do | ||||||||||||||||||||||||||||
| 76 | not simply copy the module into your distribution as this may cause | ||||||||||||||||||||||||||||
| 77 | problems when PAUSE and search.cpan.org index the distro. Instead, use | ||||||||||||||||||||||||||||
| 78 | the use-devel-assertos script. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Devel::CheckOS implements the following functions, which load subsidiary | ||||||||||||||||||||||||||||
| 83 | OS-specific modules on demand to do the real work. They can all be exported | ||||||||||||||||||||||||||||
| 84 | by listing their names after C<use Devel::CheckOS>. You can also export | ||||||||||||||||||||||||||||
| 85 | groups of functions thus: | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | use Devel::CheckOS qw(:booleans); # export the boolean functions | ||||||||||||||||||||||||||||
| 88 | # and 'die_unsupported' | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | use Devel::CheckOS qw(:fatal); # export those that die on no match | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | use Devel::CheckOS qw(:all); # export everything exportable | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head2 Boolean functions | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head3 os_is | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Takes a list of OS names. If the current platform matches any of them, | ||||||||||||||||||||||||||||
| 99 | it returns true, otherwise it returns false. The names can be a mixture | ||||||||||||||||||||||||||||
| 100 | of OSes and OS families, eg ... | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | os_is(qw(Unix VMS)); # Unix is a family, VMS is an OS | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Matching is case-insensitive provided that Taint-mode is not enabled, so the | ||||||||||||||||||||||||||||
| 105 | above could also be written: | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | os_is(qw(unix vms)); | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 692 | ▶ | sub os_is { | ||||||||||||||||||||||||||
|
Subroutine
os_is: called CC=10 SCAR=23.6
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 686 | my @targets = @_; | |||||||||||||||||||||||||||
| 113 | 686 | my $rval = 0; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 692 | TARGET: foreach my $target (@targets) { | |||||||||||||||||||||||||||
| 116 | # resolve aliases | ||||||||||||||||||||||||||||
| 117 | 1138 | ALIAS: foreach my $alias (keys %OS_ALIASES) { | |||||||||||||||||||||||||||
| 118 | 1138 | ▶ | if($target =~ /^$alias$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 13 | $target = $OS_ALIASES{$alias}; | |||||||||||||||||||||||||||
| 120 | 5 | last ALIAS; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | # resolve case-insensitive names (no-op in taint-mode as list_platforms | ||||||||||||||||||||||||||||
| 125 | # won't work) | ||||||||||||||||||||||||||||
| 126 | 1139 | my @available_platforms = list_platforms(); | |||||||||||||||||||||||||||
| 127 | 1147 | CANDIDATE: foreach my $candidate (@available_platforms) { | |||||||||||||||||||||||||||
| 128 | 41714 | ▶ | if($target =~ /^\Q$candidate\E$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 1138 | $target = $candidate; | |||||||||||||||||||||||||||
| 130 | 1146 | last CANDIDATE; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 1139 | ▶ | die("Devel::CheckOS: $target isn't a legal OS name\n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | unless($target =~ /^\w+(::\w+)*$/); | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1138 | $@ = undef; | |||||||||||||||||||||||||||
| 138 | 1146 | ▶ | if(! "Devel::AssertOS::$target"->can('os_is')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | eval "use Devel::AssertOS::$target"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | 1138 | ▶ | if(!$@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 50 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 143 | 862 | ▶ | $rval = 1 if(&{"Devel::AssertOS::${target}::os_is"}()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 684 | return $rval; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =head3 os_isnt | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | If the current platform matches (case-insensitively) any of the parameters it | ||||||||||||||||||||||||||||
| 152 | returns false, otherwise it returns true. | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 64 | ▶ | sub os_isnt { | ||||||||||||||||||||||||||
|
Subroutine
os_isnt: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 65 | my @targets = @_; | |||||||||||||||||||||||||||
| 158 | 56 | my $rval = 1; | |||||||||||||||||||||||||||
| 159 | 56 | foreach my $target (@targets) { | |||||||||||||||||||||||||||
| 160 | 86 | ▶ | $rval = 0 if(os_is($target)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | 57 | return $rval; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =head2 Fatal functions | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =head3 die_if_os_isnt | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | As C<os_is()>, except that it dies instead of returning false. The die() | ||||||||||||||||||||||||||||
| 170 | message matches what the CPAN-testers look for to determine if a module | ||||||||||||||||||||||||||||
| 171 | doesn't support a particular platform. | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 31 | ▶ | sub die_if_os_isnt { | ||||||||||||||||||||||||||
|
Subroutine
die_if_os_isnt: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 176 | 23 | ▶ | os_is(@_) ? 1 : die_unsupported(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =head3 die_if_os_is | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | As C<os_isnt()>, except that it dies instead of returning false. | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =cut | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 20 | ▶ | sub die_if_os_is { | ||||||||||||||||||||||||||
|
Subroutine
die_if_os_is: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | 20 | ▶ | os_isnt(@_) ? 1 : die_unsupported(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =head2 And some utility functions ... | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =head3 die_unsupported | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | This function simply dies with the message "OS unsupported", which is what | ||||||||||||||||||||||||||||
| 194 | the CPAN testers look for to figure out whether a platform is supported or | ||||||||||||||||||||||||||||
| 195 | not. | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 378 | ▶ | sub die_unsupported { die("OS unsupported\n"); } | ||||||||||||||||||||||||||
|
Subroutine
die_unsupported: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =head3 list_platforms | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | Return a list of all the platforms for which the corresponding | ||||||||||||||||||||||||||||
| 204 | Devel::AssertOS::* module is available. This includes both OSes and OS | ||||||||||||||||||||||||||||
| 205 | families, and both those bundled with this module and any third-party | ||||||||||||||||||||||||||||
| 206 | add-ons you have installed. | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Unfortunately, on some platforms this list may have platform names' | ||||||||||||||||||||||||||||
| 209 | case broken, eg you might see 'freebsd' instead of 'FreeBSD'. | ||||||||||||||||||||||||||||
| 210 | This is because they have case-insensitive filesystems so things | ||||||||||||||||||||||||||||
| 211 | should Just Work anyway. | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | This function does not work in taint-mode. | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | =cut | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 40 | ▶ | my $case_flag = File::Spec->case_tolerant ? '(?i)' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 38 | my $re_Devel = qr/$case_flag ^Devel$/x; | |||||||||||||||||||||||||||
| 219 | 38 | my $re_AssertOS = qr/$case_flag ^AssertOS$/x; | |||||||||||||||||||||||||||
| 220 | 40 | my $re_Alias = qr/$case_flag ^Alias\b/x; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 1157 | ▶ | sub list_platforms { | ||||||||||||||||||||||||||
|
Subroutine
list_platforms: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 223 | 1148 | my @modules = sort keys %{ {map { $_ => 1 } grep { | |||||||||||||||||||||||||||
| 224 | 361907 | $_ !~ $re_Alias | |||||||||||||||||||||||||||
| 225 | } map { | ||||||||||||||||||||||||||||
| 226 | 361915 | my (undef, $dir_part, $file_part) = File::Spec->splitpath($_); | |||||||||||||||||||||||||||
| 227 | 361906 | $file_part =~ s/\.pm$//; | |||||||||||||||||||||||||||
| 228 | 361906 | my (@dirs) = grep {+length} File::Spec->splitdir($dir_part); | |||||||||||||||||||||||||||
| 229 | 361908 | foreach my $i (reverse 1..$#dirs) { | |||||||||||||||||||||||||||
| 230 | next unless( | ||||||||||||||||||||||||||||
| 231 | 534420 | ▶ | $dirs[$i] =~ $re_AssertOS && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dirs[$i] =~ /$re_AssertOS/x and $dirs[$i - 1] =~ /$re_Devel/x
MC/DC50%1/2
$dirs[$i] =~ /$re_AssertOS/x and $dirs[$i - 1] =~ /$re_Devel/x
$dirs[$i] =~ /$re_AssertOS/x
$dirs[$i - 1] =~ /$re_Devel/x
Truth table66%2/3
A and B
A= $dirs[$i] =~ /$re_AssertOS/xB= $dirs[$i - 1] =~ /$re_Devel/x
| |||||||||||||||||||||||||||||
| 232 | $dirs[$i - 1] =~ $re_Devel | ||||||||||||||||||||||||||||
| 233 | );; | ||||||||||||||||||||||||||||
| 234 | 361915 | splice @dirs, 0, $i + 1; | |||||||||||||||||||||||||||
| 235 | 361907 | last; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | 361907 | join('::', @dirs, $file_part); | |||||||||||||||||||||||||||
| 238 | } _find_pm_files_in_dirs( | ||||||||||||||||||||||||||||
| 239 | 10094 | grep { -d } | |||||||||||||||||||||||||||
| 240 | 1157 | map { File::Spec->catdir($_, qw(Devel AssertOS)) } | |||||||||||||||||||||||||||
| 241 | @INC | ||||||||||||||||||||||||||||
| 242 | )}}; | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 1150 | return @modules; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | =head3 list_family_members | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | Takes the name of an OS 'family' and returns a list of all its members. | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | If called on something that isn't a family, you get an empty list. | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | =cut | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 125 | ▶ | sub list_family_members { | ||||||||||||||||||||||||||
|
Subroutine
list_family_members: called CC=2 SCAR=7.5
Pod
documented
| |||||||||||||||||||||||||||||
| 256 | 125 | ▶ | my $family = shift() || | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || die("Devel::CheckOS::list_family_members needs a parameter\n")
MC/DC100%1/1
shift() || die("Devel::CheckOS::list_family_members needs a parameter\n")
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 257 | die(__PACKAGE__."::list_family_members needs a parameter\n"); | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | # this will die if it's the wrong OS, but the module is loaded ... | ||||||||||||||||||||||||||||
| 260 | 0 | ▶ | eval qq{use Devel::AssertOS::$family}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
| |||||||||||||||||||||||||||||
| 261 | # ... so we can now query it | ||||||||||||||||||||||||||||
| 262 | 0 | ▶ | return eval qq{ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
BEGIN: called CC=1 SCAR=0.3
| |||||||||||||||||||||||||||||
| 263 | no strict 'refs'; | ||||||||||||||||||||||||||||
| 264 | &{"Devel::AssertOS::${family}::matches"}() | ||||||||||||||||||||||||||||
| 265 | }; | ||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | =head3 register_alias | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | It takes two arguments, the first being an alias name, the second being the | ||||||||||||||||||||||||||||
| 271 | name of an OS. After the alias has been registered, any queries about the | ||||||||||||||||||||||||||||
| 272 | alias will return the appropriate result for the named OS. | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | It returns true unless you invoke it incorrectly or you attempt to change | ||||||||||||||||||||||||||||
| 275 | an existing alias. | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | Aliases don't work under taint-mode. | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | See L<Devel::AssertOS::Extending>. | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | =cut | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 46 | ▶ | sub register_alias { | ||||||||||||||||||||||||||
|
Subroutine
register_alias: called CC=5 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||
| 284 | 46 | my($alias, $os) = @_; | |||||||||||||||||||||||||||
| 285 | 38 | ▶ | ($alias && $os) || return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$alias and $os
MC/DC0%0/2
$alias and $os
$alias
$os
Truth table33%1/3
A and B
A= $aliasB= $os
| |||||||||||||||||||||||||||||
| 286 | 38 | ▶ | if(!exists($OS_ALIASES{$alias}) || $OS_ALIASES{$alias} eq $os) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not exists $Devel::CheckOS::OS_ALIASES{$alias} or $Devel::CheckOS::OS_ALIASES{$alias} eq $os
MC/DC0%0/2
not exists $Devel::CheckOS::OS_ALIASES{$alias} or $Devel::CheckOS::OS_ALIASES{$alias} eq $os
not exists $Devel::CheckOS::OS_ALIASES{$alias}
$Devel::CheckOS::OS_ALIASES{$alias} eq $os
Truth table33%1/3
not(A) or B
A= not exists $Devel::CheckOS::OS_ALIASES{$alias}B= $Devel::CheckOS::OS_ALIASES{$alias} eq $os
| |||||||||||||||||||||||||||||
| 287 | 40 | return $OS_ALIASES{$alias} = $os; | |||||||||||||||||||||||||||
| 288 | } else { | ||||||||||||||||||||||||||||
| 289 | 2 | return 0 | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =head1 PLATFORMS SUPPORTED | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | To see the list of platforms for which information is available, run this: | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | perl -MDevel::CheckOS -e 'print join(", ", Devel::CheckOS::list_platforms())' | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | These are the names of the underlying Devel::AssertOS::* modules | ||||||||||||||||||||||||||||
| 300 | which do the actual platform detection, so they have to | ||||||||||||||||||||||||||||
| 301 | be 'legal' filenames and module names, which unfortunately precludes | ||||||||||||||||||||||||||||
| 302 | funny characters, so platforms like OS/2 are mis-spelt deliberately. | ||||||||||||||||||||||||||||
| 303 | Sorry. | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | Also be aware that not all of them have been properly tested. I don't | ||||||||||||||||||||||||||||
| 306 | have access to most of them and have had to work from information | ||||||||||||||||||||||||||||
| 307 | gleaned from L<perlport> and a few other places. For a complete list of | ||||||||||||||||||||||||||||
| 308 | OS families, see L<Devel::CheckOS::Families>. | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | If you want to add your own OSes or families, see L<Devel::AssertOS::Extending> | ||||||||||||||||||||||||||||
| 311 | and please feel free to upload the results to the CPAN. | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | =head1 BUGS and FEEDBACK | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | I welcome feedback about my code, including constructive criticism. | ||||||||||||||||||||||||||||
| 316 | Bug reports should be made using L<https://github.com/DrHyde/perl-modules-Devel-CheckOS/issues>. | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | You will need to include in your bug report the exact value of $^O, what | ||||||||||||||||||||||||||||
| 319 | the OS is called (eg Windows Vista 64 bit Ultimate Home Edition), and, | ||||||||||||||||||||||||||||
| 320 | if relevant, what "OS family" it should be in and who wrote it. | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | If you are feeling particularly generous you can encourage me in my | ||||||||||||||||||||||||||||
| 323 | open source endeavours by buying me something from my wishlist: | ||||||||||||||||||||||||||||
| 324 | L<http://www.cantrell.org.uk/david/wishlist/> | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | =head1 COMPATIBILITY | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | Version 1.90 made all matches case-insensitive. This is a change in behaviour, but | ||||||||||||||||||||||||||||
| 329 | if it breaks your code then your code was already broken, you just didn't know it. | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | As of version 2.00 the list_* functions always return plain old lists. Calling them | ||||||||||||||||||||||||||||
| 332 | in scalar context was deprecated and has emitted warnings for over 2 years, since | ||||||||||||||||||||||||||||
| 333 | version 1.90. | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | $^O in L<perlvar> | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | L<perlport> | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | L<Devel::AssertOS> | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | L<Devel::AssertOS::Extending> | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | L<Probe::Perl> | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | The use-devel-assertos script | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | L<Module::Install::AssertOS> | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | David Cantrell E<lt>F<david@cantrell.org.uk>E<gt> | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | Thanks to David Golden for the name and ideas about the interface, and | ||||||||||||||||||||||||||||
| 356 | to the cpan-testers-discuss mailing list for prompting me to write it | ||||||||||||||||||||||||||||
| 357 | in the first place. | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | Thanks to Ken Williams, from whose L<Module::Build> I lifted some of the | ||||||||||||||||||||||||||||
| 360 | information about what should be in the Unix family. | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | Thanks to Billy Abbott for finding some bugs for me on VMS. | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | Thanks to Matt Kraai for information about QNX. | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | Thanks to Kenichi Ishigaki and Gabor Szabo for reporting a bug on Windows, | ||||||||||||||||||||||||||||
| 367 | and to the former for providing a patch. | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | Thanks to Paul Green for some information about VOS. | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | Thanks to Yanick Champoux for a patch to let Devel::AssertOS support | ||||||||||||||||||||||||||||
| 372 | negative assertions. | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | Thanks to Brian Fraser for adding Android support. | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | Thanks to Dale Evans for Debian detection, a bunch of Mac OS X specific version | ||||||||||||||||||||||||||||
| 377 | detection modules, and perl 5.6 support. | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | Thanks to Graham Knop for fixing a build bug on perl 5.8. | ||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | Thanks to Alceu Rodrigues de Freitas Junior for improving Ubuntu detection | ||||||||||||||||||||||||||||
| 382 | and providing a way to detect a lot more Linux variants. | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | Thanks to Leos Stejskal for https://github.com/stejskalleos/os_release from | ||||||||||||||||||||||||||||
| 385 | which I got many sample /etc/os-release files. | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | =head1 SOURCE CODE REPOSITORY | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | L<git://github.com/DrHyde/perl-modules-Devel-CheckOS.git> | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | =head1 COPYRIGHT and LICENCE | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | Copyright 2024 David Cantrell | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 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. | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | =head1 HATS | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | I recommend buying a Fedora from L<http://hatsdirect.com/>. | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | =head1 CONSPIRACY | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | This module is also free-as-in-mason software. | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | =cut | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 38 | 1; | |||||||||||||||||||||||||||