Files
perl-Hash-SafeKeys/perl-Hash-SafeKeys.spec

82 lines
2.6 KiB
RPMSpec
Raw Permalink Normal View History

#
# spec file for package perl-Hash-SafeKeys
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%define cpan_name Hash-SafeKeys
Name: perl-Hash-SafeKeys
Version: 0.40.0
Release: 0
# 0.04 -> normalize -> 0.40.0
%define cpan_version 0.04
License: Artistic-1.0 OR GPL-1.0-or-later
Summary: Get hash contents without resetting each iterator
URL: https://metacpan.org/release/%{cpan_name}
Source0: https://cpan.metacpan.org/authors/id/M/MO/MOB/%{cpan_name}-%{cpan_version}.tar.gz
2025-08-12 18:14:31 +02:00
Source100: README.md
BuildRequires: perl
BuildRequires: perl-macros
Provides: perl(Hash::SafeKeys) = %{version}
%undefine __perllib_provides
%{perl_requires}
%description
Every hash variable in Perl has its own internal iterator, accessed by the
builtin 'each', 'keys', and 'values' functions. The iterator is also
implicitly used whenever the hash is evaluated in list context. The
iterator is "reset" whenever 'keys' or 'values' is called on a hash,
including the implicit calls when the hash is evaluated in list context.
That makes it dangerous to do certain hash operations inside a 'while ...
each' loop:
while (my($k,$v) = each %hash) {
...
@k = sort keys %hash; # Infinite loop!
@v = grep { /foo/ }, values %hash; # Ack!
print join ' ', %hash; # Run away!
}
'Hash::SafeKeys' provides alternate functions to access the keys, values,
or entire contents of a hash in a way that does not reset the iterator,
making them safe to use in such contexts:
while (my($k,$v) = each %hash) {
...
@k = sort safekeys %hash; # Can do
@v = grep { /foo/ }, safevalues %hash; # No problem
print join ' ', safecopy %hash; # Right away, sir
}
%prep
%autosetup -n %{cpan_name}-%{cpan_version}
%build
perl Makefile.PL INSTALLDIRS=vendor OPTIMIZE="%{optflags}"
%make_build
%check
make test
%install
%perl_make_install
%perl_process_packlist
%perl_gen_filelist
%files -f %{name}.files
%doc Changes README
%changelog