From b2f1d405be4eba5f8d60717b4ea46daf1ae983f9 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Wed, 1 May 2024 18:53:14 +0100 Subject: [PATCH] Get rid of deprecated functionality; Add Mac OS 14 support --- CHANGELOG | 9 ++- MANIFEST | 1 + Makefile.PL | 1 + lib/Devel/AssertOS/MacOSX/v14.pm | 28 +++++++++ lib/Devel/CheckOS.pm | 58 +++++-------------- t/checkos.t | 16 +---- t/list_family_members.t | 19 ------ .../Devel/AssertOS/AnOperatingSystem.pm | 13 ----- 8 files changed, 53 insertions(+), 92 deletions(-) create mode 100644 lib/Devel/AssertOS/MacOSX/v14.pm diff --git a/CHANGELOG b/CHANGELOG index eba3746..8c44007 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,13 @@ +2.00 XXXX-XX-XX + +- list_* no longer have special behaviour when called in scalar context. This has + been deprecated since version 1.90; + +- Add Devel::AssertOS::MacOSX::v14 (Sonoma) + 1.96 2023-02-04 -- Add Devel::AssertOS::MacOSX::v13 +- Add Devel::AssertOS::MacOSX::v13 (Ventura) - Add Devel::AssertOS::OSFeatures::Systemd diff --git a/MANIFEST b/MANIFEST index db9aca5..3567571 100644 --- a/MANIFEST +++ b/MANIFEST @@ -127,3 +127,4 @@ t/int-size.t lib/Devel/AssertOS/HWCapabilities/Int32.pm lib/Devel/AssertOS/MacOSX/v13.pm lib/Devel/AssertOS/OSFeatures/Systemd.pm +lib/Devel/AssertOS/MacOSX/v14.pm diff --git a/Makefile.PL b/Makefile.PL index a378591..ed513fb 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -76,6 +76,7 @@ WriteMakefile( PREREQ_PM => { 'File::Find::Rule' => 0.28, 'File::Temp' => 0.19, + 'List::Util' => 0, 'Test::More' => 0.88, # done_testing 'Test::Warnings' => 0, # listed here as well as in TEST_REQUIRES in case we've got a Ye Olde Toolchaine # and not even the CONFIGURE_REQUIRES above is understood diff --git a/lib/Devel/AssertOS/MacOSX/v14.pm b/lib/Devel/AssertOS/MacOSX/v14.pm new file mode 100644 index 0000000..8b27256 --- /dev/null +++ b/lib/Devel/AssertOS/MacOSX/v14.pm @@ -0,0 +1,28 @@ +package Devel::AssertOS::MacOSX::v14; + +use Devel::CheckOS; +use strict; +use warnings; +no warnings 'redefine'; + +our $VERSION = '1.0'; + +sub os_is { + Devel::CheckOS::os_is('MacOSX') && + `sw_vers -productVersion` =~ /^14/ ? 1 : 0; +} + +sub expn { "The operating system is some version of Mac OS Sonoma" } + +Devel::CheckOS::die_unsupported() unless(os_is()); + +=head1 COPYRIGHT and LICENCE + +Copyright 2023 David Cantrell + +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. + +=cut + +1; + diff --git a/lib/Devel/CheckOS.pm b/lib/Devel/CheckOS.pm index c4fcdcb..3ecc770 100644 --- a/lib/Devel/CheckOS.pm +++ b/lib/Devel/CheckOS.pm @@ -7,10 +7,11 @@ use Exporter; # if we're loading this from Makefile.PL, FFR might not yet be installed eval 'use File::Find::Rule'; use File::Spec; +use List::Util qw(uniq); use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS %OS_ALIASES); -our $VERSION = '1.96'; +our $VERSION = '2.00'; @ISA = qw(Exporter); @EXPORT_OK = qw( @@ -196,18 +197,13 @@ sub die_unsupported { die("OS unsupported\n"); } =head3 list_platforms -When called in list context, -return a list of all the platforms for which the corresponding +Return a list of all the platforms for which the corresponding Devel::AssertOS::* module is available. This includes both OSes and OS families, and both those bundled with this module and any third-party add-ons you have installed. -In scalar context, returns a hashref keyed by platform with the filename -of the most recent version of the supporting module that is available to you. -This behaviour is deprecated. - -Unfortunately, on some platforms this list may have file case -broken. eg, some platforms might return 'freebsd' instead of 'FreeBSD'. +Unfortunately, on some platforms this list may have platform names' +case broken, eg you might see 'freebsd' instead of 'FreeBSD'. This is because they have case-insensitive filesystems so things should Just Work anyway. @@ -221,13 +217,8 @@ my $re_AssertOS = qr/$case_flag ^AssertOS$/x; my $re_Alias = qr/$case_flag ^Alias\b/x; sub list_platforms { - # sort by mtime, so oldest last. This was necessary so that if a module - # appears twice in @INC we pick the newer one but that functionality is - # no longer needed. We do need to de-dupe the list though - my @modules = sort { - (stat($a->{file}))[9] <=> (stat($b->{file}))[9] - } grep { - $_->{module} !~ $re_Alias + my @modules = uniq sort grep { + $_ !~ $re_Alias } map { my (undef, $dir_part, $file_part) = File::Spec->splitpath($_); $file_part =~ s/\.pm$//; @@ -240,32 +231,19 @@ sub list_platforms { splice @dirs, 0, $i + 1; last; } - { - module => join('::', @dirs, $file_part), - file => File::Spec->canonpath($_) - } + join('::', @dirs, $file_part); } _find_pm_files_in_dirs( grep { -d } map { File::Spec->catdir($_, qw(Devel AssertOS)) } @INC ); - my %modules = map { - $_->{module} => $_->{file} - } @modules; - - if(wantarray()) { - return sort keys %modules; - } else { - warn("Calling list_platforms in scalar context and getting back a reference is deprecated and will go away some time after April 2024. To disable this warning set \$Devel::CheckOS::NoDeprecationWarnings::Context to a true value.\n") unless($Devel::CheckOS::NoDeprecationWarnings::Context); - return \%modules; - } + return @modules; } =head3 list_family_members Takes the name of an OS 'family' and returns a list of all its members. -In list context, you get a list, in scalar context you get an arrayref. If called on something that isn't a family, you get an empty list (or a ref to an empty array). @@ -279,16 +257,10 @@ sub list_family_members { # this will die if it's the wrong OS, but the module is loaded ... eval qq{use Devel::AssertOS::$family}; # ... so we can now query it - my @members = eval qq{ + return eval qq{ no strict 'refs'; &{"Devel::AssertOS::${family}::matches"}() }; - if(wantarray()) { - return @members; - } else { - warn("Calling list_family_members in scalar context and getting back a reference is deprecated and will go away some time after April 2024. To disable this warning set \$Devel::CheckOS::NoDeprecationWarnings::Context to a true value.\n") unless($Devel::CheckOS::NoDeprecationWarnings::Context); - return \@members; - } } =head3 register_alias @@ -354,13 +326,9 @@ open source endeavours by buying me something from my wishlist: Version 1.90 made all matches case-insensitive. This is a change in behaviour, but if it breaks your code then your code was already broken, you just didn't know it. -=head1 DEPRECATIONS - -At some point after April 2024 the C and C -functions will stop being sensitive to whether they are called in list context or -not, and will always return a list. From now until then calling them in non-list -context will emit a warning. You can turn that off by setting -C<$Devel::CheckOS::NoDeprecationWarnings::Context> to a true value. +As of version 2.00 the list_* functions always return plain old lists. Calling them +in scalar context was deprecated and has emitted warnings for over 2 years, since +version 1.90. =head1 SEE ALSO diff --git a/t/checkos.t b/t/checkos.t index d92b91f..405778a 100644 --- a/t/checkos.t +++ b/t/checkos.t @@ -42,21 +42,9 @@ ok(!(grep { /^Alias::MacOS$/i } Devel::CheckOS::list_platforms()), "list_platforms excludes Aliases"); eval "use lib File::Spec->catdir(qw(t otherlib))"; -sleep(2); -utime time(), time(), File::Spec->catfile(qw(t otherlib Devel AssertOS AnOperatingSystem.pm)); +open(my $temp_fh, '>', File::Spec->catfile(qw(t otherlib Devel AssertOS AnOperatingSystem.pm))); -ok(1 == (grep { /^AnOperatingSystem$/i } Devel::CheckOS::list_platforms()), +is(1, (grep { /^AnOperatingSystem$/i } Devel::CheckOS::list_platforms()), "A platform is listed only once"); -{ - local $Devel::CheckOS::NoDeprecationWarnings::Context = 1; - ok(Devel::CheckOS::list_platforms->{AnOperatingSystem} eq - File::Spec->catfile(qw(t otherlib Devel AssertOS AnOperatingSystem.pm)), - "scalar list_platforms gives the most recent module for an OS"); -} - -is - warning { my $foo = Devel::CheckOS::list_platforms() }, - "Calling list_platforms in scalar context and getting back a reference is deprecated and will go away some time after April 2024. To disable this warning set \$Devel::CheckOS::NoDeprecationWarnings::Context to a true value.\n", - "list_platforms in scalar context == warning"; done_testing; diff --git a/t/list_family_members.t b/t/list_family_members.t index 921e2f0..54b3649 100644 --- a/t/list_family_members.t +++ b/t/list_family_members.t @@ -26,23 +26,4 @@ is_deeply( 'array list_family_members works for DEC family' ); -{ - local $Devel::CheckOS::NoDeprecationWarnings::Context = 1; - is_deeply( - scalar(Devel::CheckOS::list_family_members('DEC')), - [qw(OSF VMS)], - 'scalar list_family_members works for DEC family' - ); - is_deeply( - scalar(Devel::CheckOS::list_family_members('MicrosoftWindows')), - [qw(Cygwin MSWin32 MSYS)], - 'scalar list_family_members works for MicrosoftWindows family' - ); -} - -is - warning { my $foo = Devel::CheckOS::list_family_members('MicrosoftWindows') }, - "Calling list_family_members in scalar context and getting back a reference is deprecated and will go away some time after April 2024. To disable this warning set \$Devel::CheckOS::NoDeprecationWarnings::Context to a true value.\n", - "list_platforms in scalar context == warning"; - done_testing; diff --git a/t/otherlib/Devel/AssertOS/AnOperatingSystem.pm b/t/otherlib/Devel/AssertOS/AnOperatingSystem.pm index 52665e1..e69de29 100644 --- a/t/otherlib/Devel/AssertOS/AnOperatingSystem.pm +++ b/t/otherlib/Devel/AssertOS/AnOperatingSystem.pm @@ -1,13 +0,0 @@ -# $Id: AnOperatingSystem.pm,v 1.1 2008/05/29 21:55:46 drhyde Exp $ - -package Devel::AssertOS::AnOperatingSystem; - -use Devel::CheckOS qw(die_unsupported); - -$VERSION = '1.0'; - -sub os_is { 1; } - -die_unsupported() unless(os_is()); - -1;