178 lines
6.2 KiB
RPMSpec
178 lines
6.2 KiB
RPMSpec
#
|
|
# spec file for package perl-Hash-AutoHash-Args
|
|
#
|
|
# 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-AutoHash-Args
|
|
Name: perl-Hash-AutoHash-Args
|
|
Version: 1.180.0
|
|
Release: 0
|
|
# 1.18 -> normalize -> 1.180.0
|
|
%define cpan_version 1.18
|
|
License: Artistic-1.0 OR GPL-1.0-or-later
|
|
Summary: Object-oriented processing of keyword-based argument lists
|
|
URL: https://metacpan.org/release/%{cpan_name}
|
|
Source0: https://cpan.metacpan.org/authors/id/N/NA/NATG/%{cpan_name}-%{cpan_version}.tar.gz
|
|
Source1: cpanspec.yml
|
|
Source100: README.md
|
|
BuildArch: noarch
|
|
BuildRequires: perl
|
|
BuildRequires: perl-macros
|
|
BuildRequires: perl(Carp) >= 1.2
|
|
BuildRequires: perl(Cwd) >= 3.4
|
|
BuildRequires: perl(Exporter) >= 5.68
|
|
BuildRequires: perl(File::Basename) >= 2.82
|
|
BuildRequires: perl(File::Spec) >= 3.4
|
|
BuildRequires: perl(Hash::AutoHash) >= 1.170
|
|
BuildRequires: perl(List::MoreUtils) >= 0.33
|
|
BuildRequires: perl(List::Util) >= 1.32
|
|
BuildRequires: perl(Module::Build) >= 0.4007
|
|
BuildRequires: perl(Test::Deep) >= 0.11
|
|
BuildRequires: perl(Test::More) >= 0.98
|
|
BuildRequires: perl(Test::Pod) >= 1.48
|
|
BuildRequires: perl(Test::Pod::Content) >= 0.0.6
|
|
BuildRequires: perl(Tie::Hash) >= 1.04
|
|
BuildRequires: perl(Tie::ToObject) >= 0.03
|
|
BuildRequires: perl(XSLoader) >= 0.16
|
|
Requires: perl(Carp) >= 1.2
|
|
Requires: perl(Cwd) >= 3.4
|
|
Requires: perl(Exporter) >= 5.68
|
|
Requires: perl(Hash::AutoHash) >= 1.170
|
|
Requires: perl(List::MoreUtils) >= 0.33
|
|
Requires: perl(List::Util) >= 1.32
|
|
Requires: perl(Tie::Hash) >= 1.04
|
|
Requires: perl(Tie::ToObject) >= 0.03
|
|
Requires: perl(XSLoader) >= 0.16
|
|
Provides: perl(Hash::AutoHash::Args) = %{version}
|
|
Provides: perl(Hash::AutoHash::Args::V0) = %{version}
|
|
Provides: perl(Hash::AutoHash::Args::V0::helper)
|
|
Provides: perl(Hash::AutoHash::Args::helper)
|
|
Provides: perl(Hash::AutoHash::Args::tie)
|
|
%undefine __perllib_provides
|
|
%{perl_requires}
|
|
|
|
%description
|
|
This class simplifies the handling of keyword argument lists. It replaces
|
|
Class::AutoClass::Args. See DIFFERENCES FROM Class::AutoClass::Args for a
|
|
discussion of what's new. See Hash::AutoHash::Args::V0 for a subclass which
|
|
is more compatible with the original.
|
|
|
|
The 'new' method accepts a list, ARRAY, or HASH of keyword=>value pairs,
|
|
another Hash::AutoHash::Args object, or any object that can be coerced into
|
|
a HASH . It normalizes the keywords to ignore case and leading dashes
|
|
('-'). The following keywords are all equivalent:
|
|
|
|
name, -name, -NAME, --NAME, Name, -Name
|
|
|
|
Arguments can be accessed using HASH or method notation; the following are
|
|
equivalent (assuming the keyword 'name' exists in $args).
|
|
|
|
my $name=$args->{name};
|
|
my $name=$args->name;
|
|
|
|
Arguments values can also be changed using either notation:
|
|
|
|
$args->{name}='Jonathan';
|
|
$args->name('Jonathan');
|
|
|
|
Keywords are normalized automatically; the following are all equivalent.
|
|
|
|
my $name=$args->{name}; # lower case HASH key
|
|
my $name=$args->{Name}; # capitalized HASH key
|
|
my $name=$args->{NAME}; # upper case HASH key
|
|
my $name=$args->{NaMe}; # mixed case HASH key
|
|
my $name=$args->{-name}; # leading - in HASH key
|
|
|
|
The following are also all equivalent, and are equivalent to the ones above
|
|
assuming the keyword 'name' exists in $args.
|
|
|
|
my $name=$args->name; # lower case method
|
|
my $name=$args->Name; # capitalized method
|
|
my $name=$args->NAME; # upper case method
|
|
my $name=$args->NaMe; # mixed case method
|
|
|
|
One caution is that when using method notation, keywords must be
|
|
syntactically legal method names and cannot include leading dashes. The
|
|
following is NOT legal.
|
|
|
|
my $name=$args->-name; # leading dash in method - ILLEGAL
|
|
|
|
Repeated keyword arguments are converted into an ARRAY of the values.
|
|
|
|
new Hash::AutoHash::Args(hobbies=>'hiking', hobbies=>'cooking')
|
|
|
|
is equivalent to
|
|
|
|
new Hash::AutoHash::Args(hobbies=>['hiking', 'cooking'])
|
|
|
|
Caution: when setting values using HASH or method notation, the grouping of
|
|
repeated arguments does NOT occur. Thus,
|
|
|
|
@$args{qw(hobbies hobbies)}=qw(running rowing);
|
|
|
|
leaves 'hobbies' set to the last value presented, namely 'rowing', as does
|
|
|
|
$args->hobbies('running');
|
|
$args->hobbies('rowing');
|
|
|
|
New keywords can be added using either notation. For example,
|
|
|
|
$args->{first_name}='Joe';
|
|
$args->last_name('Plumber');
|
|
|
|
If a keyword does not exist, the method notation returns nothing, while the
|
|
HASH notation returns undef. This difference matters in array context
|
|
(including when passing the result as a parameter).
|
|
|
|
my @list=$args->non_existent; # @list will contain 0 elements
|
|
my @list=$args->{non_existent}; # @list will contain 1 element
|
|
|
|
We find the method behavior (returning nothing) to be more natural and is
|
|
the behavior in Class::AutoClass::Args. Unfortunately, Perl does not
|
|
support this behavior with HASH notation; if the tied hash code returns
|
|
nothing, Perl converts this into undef before passing the result to the
|
|
caller. Too bad.
|
|
|
|
You can alias the object to a regular hash for more concise hash notation.
|
|
|
|
use Hash::AutoHash::Args qw(autoargs_alias);
|
|
autoargs_alias($args,%args);
|
|
my($name,$hobbies)=@args{qw(name hobbies)};
|
|
$args{name}='Joseph';
|
|
|
|
By aliasing $args to %args, you avoid the need to dereference the variable
|
|
when using hash notation. Admittedly, this is a minor convenience, but then
|
|
again, this entire class is about convenience.
|
|
|
|
%prep
|
|
%autosetup -n %{cpan_name}-%{cpan_version}
|
|
|
|
%build
|
|
perl Build.PL --installdirs=vendor
|
|
./Build build --flags=%{?_smp_mflags}
|
|
|
|
%check
|
|
./Build test
|
|
|
|
%install
|
|
./Build install --destdir=%{buildroot} --create_packlist=0
|
|
%perl_gen_filelist
|
|
|
|
%files -f %{name}.files
|
|
%doc Changes README
|
|
|
|
%changelog
|