Info/Darwin.pm

filter: Statementstmt 96.7% 60 / 62 Branchbran 72.7% 16 / 22 Conditioncond 56.0% 14 / 25 MC/DCmcdc 13.3% 2 / 15 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 75.5% 99 / 131 CC 23 SCAR 23.8
CC
23
Cov
83%
__get_system_profiler
14.3
prepare_sysinfo
10.9
__get_sysctl
2.0
CRAP 10.8
« Info/BSD.pm ↑ Summary Info/Windows.pm »
1 package System::Info::Darwin;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base "System::Info::BSD";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = "0.057";
9  
10 =head1 NAME
11  
12 System::Info::Darwin - Object for specific Darwin info.
13  
14 =head1 DESCRIPTION
15  
16 =head2 $si->prepare_sysinfo
17  
18 Use os-specific tools to find out more about the system.
19  
20 =cut
21  
22 4 ▶sub prepare_sysinfo {
Subroutine prepare_sysinfo: called CC=10 SCAR=23.9
Pod documented
23 4 my $self = shift;
24 4 $self->System::Info::Base::prepare_sysinfo ();
25  
26 4 $self->{__os} .= " (Mac OS X)";
27  
28 4 my $scl = __get_sysctl ();
29  
30 4 ▶ my $system_profiler = __get_system_profiler () or
Branch: 1 branch
BranchTrueFalseTotal
my $system_profiler = __get_system_profiler() or return $self->SUPER::prepare_sysinfo 4 0 4
31 return $self->SUPER::prepare_sysinfo ();
32  
33 4 $self->{__system_profiler} = $system_profiler;
34 4 ▶ if (my $kv = $system_profiler->{"system version"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $kv = $system_profiler->{"system version"}) 0 4 4
35 0 $self->{__os} =~ s{\)$}{ - $kv)};
36 }
37  
38 # This is physical processors (sockets) which os not returned anywhere for Apple Silicon (implied 1)
39 4 ▶ my $ncpu = $system_profiler->{"number of cpus"} || 1;
Condition100%2/2
$system_profiler->{'number of cpus'} || 1
l!l
31
MC/DC100%1/1
$system_profiler->{'number of cpus'} || 1
$system_profiler->{'number of cpus'}
Truth table100%2/2
A
A= $system_profiler->{'number of cpus'}
Aresult
11
00
40 4 ▶ $system_profiler->{"total number of cores"} and
Branch: 1 branch
BranchTrueFalseTotal
$system_profiler->{"total number of cores"} and $ncpu .= qq[ [$system_profiler->{"total number of cores"} cores]] 3 1 4
41 $ncpu .= " [$system_profiler->{'total number of cores'} cores]";
42  
43 # Confusingly, System::Info uses "cpu_type" for architecture and Apple uses
44 # "CPU Type" as the CPU model name. They are not the same thing.
45 $self->{__cpu} = $system_profiler->{chip} ||
46 4 ▶ $system_profiler->{"cpu type"};
Condition66%2/3
$system_profiler->{'chip'} || $system_profiler->{'cpu type'}
l!l&&r!l&&!r
130
MC/DC0%0/2
$system_profiler->{'chip'} || $system_profiler->{'cpu type'}
$system_profiler->{'chip'} $system_profiler->{'cpu type'}
Truth table66%2/3
A || B
A= $system_profiler->{'chip'}B= $system_profiler->{'cpu type'}
ABresult
1X1
011
000
47 $self->{__cpu} .= " ($system_profiler->{'cpu speed'})"
48 4 ▶ if $system_profiler->{"cpu speed"};
Branch: 1 branch
BranchTrueFalseTotal
if $system_profiler->{"cpu speed"} 3 1 4
49 4 $self->{__cpu_type} = $system_profiler->{arch};
50 4 $self->{__cpu_count} = $ncpu;
51 # _ncore reports hyperthreads for other platforms, so it would be
52 # hw.logicalcpu (or hw.logicalcpu_max which is the same unless the system
53 # has disabled cores).
54 # Alternative hw.ncpu is deprecated, keeping for ancient systems.
55 4 ▶ $self->{_ncore} = $scl->{"hw.logicalcpu"} || $scl->{"hw.ncpu"};
Condition33%1/3
$scl->{'hw.logicalcpu'} || $scl->{'hw.ncpu'}
l!l&&r!l&&!r
004
MC/DC0%0/2
$scl->{'hw.logicalcpu'} || $scl->{'hw.ncpu'}
$scl->{'hw.logicalcpu'} $scl->{'hw.ncpu'}
Truth table33%1/3
A || B
A= $scl->{'hw.logicalcpu'}B= $scl->{'hw.ncpu'}
ABresult
1X1
011
000
56 4 ▶ $self->{_phys_core} = $scl->{"hw.physicalcpu"} || $scl->{"hw.ncpu"};
Condition33%1/3
$scl->{'hw.physicalcpu'} || $scl->{'hw.ncpu'}
l!l&&r!l&&!r
004
MC/DC0%0/2
$scl->{'hw.physicalcpu'} || $scl->{'hw.ncpu'}
$scl->{'hw.physicalcpu'} $scl->{'hw.ncpu'}
Truth table33%1/3
A || B
A= $scl->{'hw.physicalcpu'}B= $scl->{'hw.ncpu'}
ABresult
1X1
011
000
57  
58 4 ▶ my $osv = do {
Condition50%1/2
do { local $^W = 0; `sw_vers -productVersion 2>/dev/null` } || ''
l!l
04
MC/DC0%0/1
do { local $^W = 0; `sw_vers -productVersion 2>/dev/null` } || ''
do { local $^W = 0; `sw_vers -productVersion 2>/dev/null` }
Truth table50%1/2
A
A= do { local $^W = 0; `sw_vers -productVersion 2>/dev/null` }
Aresult
11
00
59 4 local $^W = 0;
60 4 `sw_vers -productVersion 2>/dev/null`;
61 } || "";
62 4 chomp ($self->{__osvers} = $osv);
63  
64 4 $self->{__memsize} = $scl->{"hw.memsize"};
65  
66 4 return $self;
67 } # prepare_sysinfo
68  
69 # System::Info::BSD.pm only uses hw
70 4 ▶sub __get_sysctl {
Subroutine __get_sysctl: called CC=2 SCAR=7.0
71 4 ▶ my $sysctl_cmd = -x "/sbin/sysctl" ? "/sbin/sysctl" : "sysctl";
Branch: 1 branch
BranchTrueFalseTotal
-x '/sbin/sysctl' ? : 4 0 4
72 4 chomp (my @sysctl = do {
73 4 local $^W = 0;
74 4 `$sysctl_cmd -a 2>/dev/null`;
75 });
76 4 my %sysctl = map { split m/\s*[:=]\s*/, $_, 2 } grep m/[:=]/ => @sysctl;
77 4 return \%sysctl;
78 } # __get_sysctl
79  
80 4 ▶sub __get_system_profiler {
Subroutine __get_system_profiler: called CC=13 SCAR=26.6
81 4 ▶ my $system_profiler_output = do {
Branch: 1 branch
BranchTrueFalseTotal
my $system_profiler_output = do { local $^W = 0; `/usr/sbin/system_profiler -detailLevel mini SPHardwareDataType SPSoftwareDataType 2>&1` } or return 4 0 4
82 4 local $^W = 0;
83 4 `/usr/sbin/system_profiler -detailLevel mini SPHardwareDataType SPSoftwareDataType 2>&1`;
84 } or return;
85  
86 # From CPANTESTERS
87 4 ▶ $system_profiler_output =~ m/^\d{4}-\d\d-\d\d .+ system_profiler\[.+?\] Timed out waiting for the Activation Lock/ and return;
Branch: 1 branch
BranchTrueFalseTotal
$system_profiler_output =~ /^\d{4}-\d\d-\d\d .+ system_profiler\[.+?\] Timed out waiting for the Activation Lock/ and return 0 4 4
88  
89 # From RT#97441
90 # In Yosemite the system_profiler started emitting these warnings:
91 # 2015-07-24 06:54:06.842 system_profiler[59780:1318389] platformPluginDictionary: Can\'t get X86PlatformPlugin, return value 0
92 # They seem to be harmless, but annoying.
93 # Clean them out, but then warn about others from system_profiler.
94 4 $system_profiler_output =~ s/^\d{4}-\d\d-\d\d .+ system_profiler\[.+?\] platformPluginDictionary: Can't get X86PlatformPlugin, return value 0$//mg;
95  
96 # Sevan Janiyan found:
97 # I think I found the issue. On macOS 26.6.1 which is currently the latest patch release there's an artifact when `system_profiler` is invoked. That artifact is what's being picked up during the System::Info test.
98 #
99 # Note the first line:
100 # ```
101 # 2026-08-17 12:42:20.121 system_profiler[911:9351] hw.cpufamily: 0x1b588bb3
102 # Hardware:
103 4 $system_profiler_output =~ s/^\d{4}-\d\d-\d\d .+ system_profiler\[.+?\] hw.cpufamily: 0x\w+\s*\r?\n//;
104  
105 4 ▶ warn "Unexpected warning from system_profiler:\n$1\n"
Branch: 1 branch
BranchTrueFalseTotal
$system_profiler_output =~ /^(.+system_profiler.+)/gm and do { warn "Unexpected warning from system_profiler:\n$1\n" } 0 4 4
106 while $system_profiler_output =~ /^(.+system_profiler.+)/mg;
107  
108 4 my %system_profiler;
109 4 ▶ $system_profiler{lc $1} = $2
Branch: 1 branch
BranchTrueFalseTotal
$system_profiler_output =~ /^\s*([\w ]+):\s+(.+)$/gm and do { $system_profiler{lc $1} = $2 } 42 4 46
110 while $system_profiler_output =~ m/^\s*([\w ]+):\s+(.+)$/gm;
111  
112 # convert newer output from Intel core duo
113 4 my %keymap = (
114 "processor name" => "cpu type",
115 "processor speed" => "cpu speed",
116 "model name" => "machine name",
117 "model identifier" => "machine model",
118 "number of processors" => "number of cpus",
119 "total number of cores" => "total number of cores",
120 );
121 4 for my $newkey (keys %keymap) {
122 24 my $oldkey = $keymap{$newkey};
123 exists $system_profiler{$newkey} and
124 24 ▶ $system_profiler{$oldkey} = delete $system_profiler{$newkey};
Branch: 1 branch
BranchTrueFalseTotal
exists $system_profiler{$newkey} and $system_profiler{$oldkey} = delete $system_profiler{$newkey} 15 9 24
125 }
126  
127 4 ▶ chomp ($system_profiler{"cpu type"} ||= `uname -m`);
Condition66%2/3
$system_profiler{"cpu type"} ||= `uname -m`
l!l&&r!l&&!r
310
MC/DC0%0/2
$system_profiler{"cpu type"} ||= `uname -m`
$system_profiler{"cpu type"} `uname -m`
Truth table66%2/3
A ||= B
A= $system_profiler{"cpu type"}B= `uname -m`
ABresult
1X1
011
000
128 4 ▶ $system_profiler{"cpu speed"} ||= 0; # Mac M1 does not show CPU speed
Condition100%2/2
$system_profiler{"cpu speed"} ||= 0
l!l
31
MC/DC100%1/1
$system_profiler{"cpu speed"} ||= 0
$system_profiler{"cpu speed"}
Truth table100%2/2
A
A= $system_profiler{"cpu speed"}
Aresult
11
00
129 4 $system_profiler{"cpu speed"} =~
130 0 s/(0(?:\.\d+)?)\s*GHz/sprintf "%d MHz", $1 * 1000/e;
131 4 ▶ $system_profiler{"cpu type"} ||= "Unknown";
Condition50%1/2
$system_profiler{"cpu type"} ||= "Unknown"
l!l
40
MC/DC0%0/1
$system_profiler{"cpu type"} ||= "Unknown"
$system_profiler{"cpu type"}
Truth table50%1/2
A
A= $system_profiler{"cpu type"}
Aresult
11
00
132 $system_profiler{"cpu type"} =~ s/\s*\([\d.]+\)//
133 4 ▶ if $system_profiler{"cpu speed"};
Branch: 1 branch
BranchTrueFalseTotal
if $system_profiler{"cpu speed"} 3 1 4
134 4 ▶ chomp ($system_profiler{arch} ||= `uname -m`);
Condition33%1/3
$system_profiler{"arch"} ||= `uname -m`
l!l&&r!l&&!r
040
MC/DC0%0/2
$system_profiler{"arch"} ||= `uname -m`
$system_profiler{"arch"} `uname -m`
Truth table33%1/3
A ||= B
A= $system_profiler{"arch"}B= `uname -m`
ABresult
1X1
011
000
135 4 ▶ $system_profiler{arch} ||= "Unknown";
Condition50%1/2
$system_profiler{"arch"} ||= "Unknown"
l!l
40
MC/DC0%0/1
$system_profiler{"arch"} ||= "Unknown"
$system_profiler{"arch"}
Truth table50%1/2
A
A= $system_profiler{"arch"}
Aresult
11
00
136 4 return \%system_profiler;
137 } # __get_system_profiler
138  
139 3 1;
140  
141 __END__
« Info/BSD.pm ↑ Summary Info/Windows.pm »