File perl-Hash-Wrap.spec of Package perl-Hash-Wrap

#
# spec file for package perl-Hash-Wrap
#
# 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-Wrap
Name:           perl-Hash-Wrap
Version:        1.03
Release:        0
License:        GPL-1.0-or-later
Summary:        Create on-the-fly objects from hashes
URL:            https://metacpan.org/release/%{cpan_name}
Source0:        https://cpan.metacpan.org/authors/id/D/DJ/DJERIUS/%{cpan_name}-%{version}.tar.gz
BuildArch:      noarch
BuildRequires:  perl
BuildRequires:  perl-macros
BuildRequires:  perl(Module::Build)
BuildRequires:  perl(Module::Build::Tiny) >= 0.034
BuildRequires:  perl(Test2::V0)
%{perl_requires}

%description
*Hash::Wrap* creates objects from hashes, providing accessors for hash
elements. The objects are hashes, and may be modified using the standard
Perl hash operations and the object's accessors will behave accordingly.

Why use this class? Sometimes a hash is created on the fly and it's too
much of a hassle to build a class to encapsulate it.

  sub foo () { ... ; return { a => 1 }; }

With 'Hash::Wrap':

  use Hash::Wrap;

  sub foo () { ... ; return wrap_hash( { a => 1 ); }

  my $obj = foo ();
  print $obj->a;

Elements can be added or removed to the object and accessors will track
them. The object may be made immutable, or may have a restricted set of
attributes.

There are many similar modules on CPAN (see SEE ALSO for comparisons).

What sets *Hash::Wrap* apart is that it's possible to customize object
construction and accessor behavior:

  * It's possible to use the passed hash directly, or make shallow or deep
copies of it.

  * Accessors can be customized so that accessing a non-existent element can
throw an exception or return the undefined value.

  * On recent enough versions of Perl, accessors can be lvalues, e.g.

   $obj->existing_key = $value;

%prep
%autosetup  -n %{cpan_name}-%{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 CONTRIBUTING.md hgrc README
%license LICENSE

%changelog
openSUSE Build Service is sponsored by