# Detect the distribution in use
%global __despace head -n 1 | tr -d '[:space:]' | sed -e 's/[(].*[)]//g'
%global __lower4 cut -c 1-4 | tr '[:upper:]' '[:lower:]'
%global __distfile %([ -f /etc/SuSE-release ] && echo /etc/SuSE-release || echo /etc/redhat-release)
%global __distinit %(sed -e 's/ release .*//' -e 's/\\([A-Za-z]\\)[^ ]*/\\1/g' %{__distfile} | %{__despace} | %{__lower4})
%global __distvers %(sed -e 's/.* release \\([^. ]*\\).*/\\1/' %{__distfile} | %{__despace})
# Identify Alma, CentOS, CentOS Stream and Rocky Linux as rhel
%if "%{__distinit}" == "a" || "%{__distinit}" == "c" || "%{__distinit}" == "cl" || "%{__distinit}" == "cs" || "%{__distinit}" == "rl"
%global __distinit rhel
%endif
# Dist tag for Fedora is still "fc"
%if "%{__distinit}" == "f"
%global __distinit fc
%endif

Name:		perl-Test-Needs
Version:	0.002010
Release:	1.%{__distinit}%{__distvers}
Summary:	Skip tests when modules not available
License:	GPL-1.0-or-later OR Artistic-1.0-Perl
URL:		https://metacpan.org/release/Test-Needs
Source0:	https://cpan.metacpan.org/modules/by-module/Test/Test-Needs-%{version}.tar.gz
BuildArch:	noarch
# Module Build
BuildRequires:	coreutils
BuildRequires:	findutils
BuildRequires:	grep
BuildRequires:	make
BuildRequires:	perl-generators
BuildRequires:	perl-interpreter
BuildRequires:	perl(ExtUtils::MakeMaker)
# Module Runtime
BuildRequires:	perl(strict)
BuildRequires:	perl(warnings)
# Test Suite
BuildRequires:	perl(Config)
BuildRequires:	perl(IPC::Open3)
BuildRequires:	perl(lib)
BuildRequires:	perl(Test::More) >= 0.45
# Optional Tests
BuildRequires:	perl(Test::Builder)
BuildRequires:	perl(Test2::API)
BuildRequires:	perl(Test2::Event)
BuildRequires:	perl(version)
# Dependencies
%if 0%{?fedora} < 38 && 0%{?rhel} < 10
Requires:	perl(:MODULE_COMPAT_%(eval "`perl -V:version`"; echo $version))
%endif

# This module does not really require Test2::Event
%global __requires_exclude ^perl\\(Test2::Event\\)

%description
Skip test scripts if modules are not available. The requested modules will
be loaded, and optionally have their versions checked. If the module is
missing, the test script will be skipped. Modules that are found but fail
to compile will exit with an error rather than skip.

%prep
%setup -q -n Test-Needs-%{version}

%build
perl Makefile.PL INSTALLDIRS=vendor
make %{?_smp_mflags}

%install
make pure_install DESTDIR=%{buildroot}
find %{buildroot} -type f -name .packlist -delete
%{_fixperms} -c %{buildroot}

%check
make test

%files
%license LICENSE
%doc Changes README
%{perl_vendorlib}/Test/
%{_mandir}/man3/Test::Needs.3*

%changelog
* Mon Jan 23 2023 Paul Howarth <paul@city-fan.org> - 0.002010-1
- Update to 0.002010
  - Split main test into three separate scripts
  - Avoid outputting multiple plans if used with no_plan
- Use SPDX-format license tag

* Wed May 26 2021 Paul Howarth <paul@city-fan.org> - 0.002009-1
- Update to 0.002009
  - Fix tests when @INC includes directories that shouldn't have their archname
    or version subdirectories added
  - Fix test compatibility with Windows
  - Fix warnings from Test::Builder if Test::Needs is loaded first, and is used
    to check for a Test module
  - Fix location in code reported when a module check fails
  - Support short forms of perl versions
  - Support perl versions greater than 5
  - Fix handling of v-string versions on perl 5.6

* Fri Apr  5 2019 Paul Howarth <paul@city-fan.org> - 0.002006-1
- Update to 0.002006
  - Added additional references to related modules in pod
  - Various internal clean-ups
  - Fix backwards compatibility with earlier versions of version.pm
  - Fix output from test script when tests fail
  - Added note about RELEASE_TESTING to test message on forced failures
- Package LICENSE file
- Switch upstream from search.cpan.org to metacpan.org

* Fri Apr  6 2018 Paul Howarth <paul@city-fan.org> - 0.002005-5
- BR: perl-generators unconditionally
- BR: perl-interpreter rather than perl
- Drop support for EOL distributions prior to F-13
  - Drop BuildRoot: and Group: tags
  - Drop explicit buildroot cleaning in %%install section
  - Drop explicit %%clean section

* Tue Sep 27 2016 Paul Howarth <paul@city-fan.org> - 0.002005-1
- Update to 0.002005
  - Fix skipping when Test::Tester (Test::More < v2) is loaded

* Fri Aug 19 2016 Paul Howarth <paul@city-fan.org> - 0.002004-1
- Update to 0.002004
  - Fix test counts when Test2 not available

* Thu Aug 18 2016 Paul Howarth <paul@city-fan.org> - 0.002003-1
- Update to 0.002003
  - Fix loud warnings when aborting a test under Test2
  - Some kwalitee improvements
- Filter unnecessary dependency on Test2::Event

* Thu Jun 30 2016 Paul Howarth <paul@city-fan.org> - 0.002002-2
- Import from Fedora

* Fri Jun 10 2016 Emmanuel Seyman <emmanuel@seyman.fr> - 0.002002-1
- Specfile autogenerated by cpanspec 1.78