# # spec file for package perl-Class-StrongSingleton # # 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-StrongSingleton Name: perl-Class-StrongSingleton Version: 0.20.0 Release: 0 # 0.02 -> normalize -> 0.20.0 %define cpan_version 0.02 License: Artistic-1.0 OR GPL-1.0-or-later Summary: Stronger and more secure Singleton base class URL: https://metacpan.org/release/%{cpan_name} Source0: https://cpan.metacpan.org/authors/id/S/ST/STEVAN/%{cpan_name}-%{cpan_version}.tar.gz Source100: README.md BuildArch: noarch BuildRequires: perl BuildRequires: perl-macros Provides: perl(Class::StrongSingleton) = %{version} %undefine __perllib_provides %{perl_requires} %description This module is an alternative to Class::Singleton and Class::WeakSingleton, and provides a more secure Singleton class in that it takes steps to prevent the possibility of accidental creation of multiple instances and/or the overwriting of existsing Singleton instances. For a detailed comparison please see the SEE ALSO section. Here is a description of how it all works. First, the user creates the first Singleton instance of the class in the normal way. my $obj = My::Singleton::Class->new("variable", "parameter"); This instance is then stored inside a lexically scoped variable within the Class::StrongSingleton package. This prevents the variable from being accessed by anything but methods from the Class::StrongSingleton package. At this point as well, the 'new' method to the class is overridden so that it will always return the Singleton instance. This prevents any accidental overwriting of the Singleton instance. This means that any of the follow lines of code all produce the same instance: my $instance = $obj->instance(); my $instance = My::Singleton::Class->instance(); my $instance = $obj->new(); my $instance = My::Singleton::Class->new(); Personally, I see this an an improvement over the usual _Gang of Four_ style Singletons which discourages the use of the 'new' method entirely. Through this method, a user can be able to use the Singleton class in a normal way, not having to know it's actually a Singleton. This can be handy if your design changes and you no longer need the class as a Singleton. %prep %autosetup -n %{cpan_name}-%{cpan_version} %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