| 1 | package Mac::OSVersion::Lite; | ||||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 8 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 8 | our $VERSION = "0.10"; | |||||||||||
| 7 | |||||||||||||
| 8 | 8 | ▶ | use constant VERSION_FORMAT => qr/(?<major>[0-9]+)(?:\.(?<minor>[0-9]+))?(?:\.(?<point>[0-9]+))?/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 8 | ▶ | use constant MAC_VERSION_NAMES => { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | catalina => "10.15", | ||||||||||||
| 11 | mojave => "10.14", | ||||||||||||
| 12 | high_sierra => "10.13", | ||||||||||||
| 13 | sierra => "10.12", | ||||||||||||
| 14 | el_capitan => "10.11", | ||||||||||||
| 15 | yosemite => "10.10", | ||||||||||||
| 16 | mavericks => "10.9", | ||||||||||||
| 17 | mountain_lion => "10.8", | ||||||||||||
| 18 | lion => "10.7", | ||||||||||||
| 19 | snow_leopard => "10.6", | ||||||||||||
| 20 | leopard => "10.5", | ||||||||||||
| 21 | tiger => "10.4", | ||||||||||||
| 22 | 8 | }; | |||||||||||
| 23 | |||||||||||||
| 24 | 8 | ▶ | use overload ( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 8 | q{""} => \&as_string, | |||||||||||
| 26 | q{<=>} => \&_cmp, | ||||||||||||
| 27 | fallback => 1, | ||||||||||||
| 28 | 8 | ); | |||||||||||
| 29 | |||||||||||||
| 30 | 18 | ▶ | sub major { shift->{major} } | ||||||||||
|
Subroutine
major: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 31 | 18 | ▶ | sub minor { shift->{minor} } | ||||||||||
|
Subroutine
minor: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 32 | |||||||||||||
| 33 | 10 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||
| 34 | 10 | my $class = shift; | |||||||||||
| 35 | 10 | my $self = bless {} => $class; | |||||||||||
| 36 | |||||||||||||
| 37 | 10 | ▶ | $self->_init_by_current_version if @_ == 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | 10 | ▶ | $self->_init_by_version_string(@_) if @_ == 1; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | 10 | ▶ | $self->_init_by_version_numbers(@_) if @_ >= 2; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | |||||||||||||
| 41 | 10 | return $self; | |||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | 2 | ▶ | sub _init_by_current_version { | ||||||||||
|
Subroutine
_init_by_current_version: called CC=2 SCAR=6.9
| |||||||||||||
| 45 | 2 | my $self = shift; | |||||||||||
| 46 | 2 | my $command = '/usr/bin/sw_vers -productVersion'; | |||||||||||
| 47 | 2 | my $version = `$command`; | |||||||||||
| 48 | |||||||||||||
| 49 | 2 | ▶ | die "Command \`$command\` failed: $version (exit code: $?)\n" if $? != 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | |||||||||||||
| 51 | 1 | $self->_init_by_version_string($version); | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 26 | ▶ | sub _init_by_version_string { | ||||||||||
|
Subroutine
_init_by_version_string: called CC=4 SCAR=13.9
| |||||||||||||
| 55 | 26 | my ($self, $string) = @_; | |||||||||||
| 56 | |||||||||||||
| 57 | 26 | ▶ | if (defined MAC_VERSION_NAMES->{$string}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | 11 | $string = MAC_VERSION_NAMES->{$string}; | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | 26 | ▶ | die "Invalid format: $string\n" unless $string =~ qr/^@{[VERSION_FORMAT]}$/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | |||||||||||||
| 63 | 25 | $self->{major} = $+{major}; | |||||||||||
| 64 | 25 | ▶ | $self->{minor} = $+{minor} // 0; | ||||||||||
|
Condition100%2/2
$+{"minor"} // 0
MC/DC100%1/1
$+{"minor"} // 0
$+{"minor"}
Truth table100%2/2
A
A= $+{"minor"}
| |||||||||||||
| 65 | } | ||||||||||||
| 66 | |||||||||||||
| 67 | 3 | ▶ | sub _init_by_version_numbers { | ||||||||||
|
Subroutine
_init_by_version_numbers: called CC=3 SCAR=11.0
| |||||||||||||
| 68 | 3 | my ($self, $major, $minor) = @_; | |||||||||||
| 69 | |||||||||||||
| 70 | 3 | ▶ | $self->{major} = $major // 0; | ||||||||||
|
Condition100%2/2
$major // 0
MC/DC100%1/1
$major // 0
$major
Truth table100%2/2
A
A= $major
| |||||||||||||
| 71 | 3 | ▶ | $self->{minor} = $minor // 0; | ||||||||||
|
Condition100%2/2
$minor // 0
MC/DC100%1/1
$minor // 0
$minor
Truth table100%2/2
A
A= $minor
| |||||||||||||
| 72 | } | ||||||||||||
| 73 | |||||||||||||
| 74 | 2 | ▶ | sub name { | ||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 75 | 2 | my $self = shift; | |||||||||||
| 76 | 2 | my %map = reverse %{ MAC_VERSION_NAMES() }; | |||||||||||
| 77 | 2 | return $map{$self->as_string}; | |||||||||||
| 78 | } | ||||||||||||
| 79 | |||||||||||||
| 80 | 4 | ▶ | sub as_string { | ||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 81 | 4 | my $self = shift; | |||||||||||
| 82 | 4 | return $self->{major}.'.'.$self->{minor}; | |||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | 4 | ▶ | sub _cmp { | ||||||||||
|
Subroutine
_cmp: called CC=2 SCAR=6.9
| |||||||||||||
| 86 | 4 | my ($self, $other) = @_; | |||||||||||
| 87 | |||||||||||||
| 88 | 4 | ▶ | return $self->{major} <=> $other->{major} if $self->{major} != $other->{major}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 89 | 2 | return $self->{minor} <=> $other->{minor}; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | 8 | 1; | |||||||||||
| 93 | __END__ | ||||||||||||