Files
perl-Syntax-Keyword-Defer/perl-Syntax-Keyword-Defer.spec
2025-08-12 18:17:21 +02:00

98 lines
3.6 KiB
RPMSpec

#
# spec file for package perl-Syntax-Keyword-Defer
#
# Copyright (c) 2025 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 Syntax-Keyword-Defer
Name: perl-Syntax-Keyword-Defer
Version: 0.110.0
Release: 0
# 0.11 -> normalize -> 0.110.0
%define cpan_version 0.11
License: Artistic-1.0 OR GPL-1.0-or-later
Summary: Execute code when leaving a block
URL: https://metacpan.org/release/%{cpan_name}
Source0: https://cpan.metacpan.org/authors/id/P/PE/PEVANS/%{cpan_name}-%{cpan_version}.tar.gz
Source1: cpanspec.yml
Source100: README.md
BuildRequires: perl
BuildRequires: perl-macros
BuildRequires: perl(ExtUtils::CBuilder)
BuildRequires: perl(Module::Build) >= 0.4004
BuildRequires: perl(Test2::V0)
BuildRequires: perl(XS::Parse::Keyword) >= 0.13
BuildRequires: perl(XS::Parse::Keyword::Builder) >= 0.13
Requires: perl(XS::Parse::Keyword) >= 0.13
Provides: perl(Syntax::Keyword::Defer) = %{version}
%undefine __perllib_provides
%{perl_requires}
%description
This module provides a syntax plugin that implements a block which executes
when the containing scope has finished.
It similar to features provided by other languages; Swift, Zig, Jai, Nim
and Odin all provide this. Note that while Go also provides a 'defer'
keyword, the semantics here are not the same. Go's version defers until the
end of the entire function, rather than the closest enclosing scope as is
common to most other languages, and this module.
The operation can be considered a little similar to an 'END' block, but
with the following key differences:
* A 'defer' block runs at the time that execution leaves the block it is
declared inside, whereas an 'END' block runs at the end time of the entire
program regardless of its location.
* A 'defer' block is invoked at the time its containing scope has finished,
which means it might run again if the block is entered again later in the
program. An 'END' block will only ever run once.
* A 'defer' block will only take effect if execution reaches the line it is
declared on; if the line is not reached then nothing happens. An 'END'
block will always be invoked once declared, regardless of the dynamic
extent of execution at runtime.
'defer' blocks are primarily intended for cases such as resource
finalisation tasks that may be conditionally required.
For example in the synopsis code, after normal execution the statement
handle will be finished using the '$sth->finish' method, then the database
will be disconnected with '$dbh->disconnect'. If instead the prepare method
failed then the database will still be disconnected, but there is no need
to finish with the statement handle as the second 'defer' block was never
encountered.
%prep
%autosetup -n %{cpan_name}-%{cpan_version} -p1
%build
perl Build.PL --installdirs=vendor optimize="%{optflags}"
./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
%license LICENSE
%changelog