# # spec file for package perl-Class-Constructor # # 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 Class-Constructor Name: perl-Class-Constructor Version: 1.1.4 Release: 0 License: Artistic-1.0 OR GPL-1.0-or-later Summary: Simplify the creation of object constructors URL: https://metacpan.org/release/%{cpan_name} Source0: https://cpan.metacpan.org/authors/id/M/MG/MGRAHAM/%{cpan_name}-%{version}.tar.gz Source1: cpanspec.yml Source100: README.md BuildArch: noarch BuildRequires: perl BuildRequires: perl-macros BuildRequires: perl(Class::Accessor) Requires: perl(Class::Accessor) %{perl_requires} %description Simplifies the creation of object constructors. Instead of writing: sub new { my $proto = shift; my $class = ref $proto || $proto; my $self = {}; bless $self, $class; my %args = @_; foreach my $attr ('first_attribute', 'second_attribute') { $self->$attr($args{$attr}); } $self->_init(); return $self; } You can just write: CLASS->mk_constructor( Auto_Init => [ 'first_attribute', 'second_attribute' ], ); There are other features as well: * Automatically call other initialization methods. Using the 'Init_Methods' method of 'mk_constructor', you can have your constructor method automatically call one or more initialization methods. * Automatic Construction of objects of Subclasses Your constructor can bless objects into one of its subclasses. For instance, the 'Fruit' class could bless objects into the 'Fruit::Apple' or 'Fruit::Orange' classes depending on a parameter passed to the constructor. See Subclass_Param for details. %prep %autosetup -n %{cpan_name}-%{version} find . -type f ! -path "*/t/*" ! -name "*.pl" ! -path "*/bin/*" ! -path "*/script/*" ! -path "*/scripts/*" ! -name "configure" -print0 | xargs -0 chmod 644 %build perl Makefile.PL INSTALLDIRS=vendor %make_build %check make test %install %perl_make_install %perl_process_packlist %perl_gen_filelist %files -f %{name}.files %doc Changes README %changelog