2011-07-19 19:32:50 +00:00
|
|
|
#
|
2011-07-25 15:34:01 +00:00
|
|
|
# spec file for package perl-Contextual-Return
|
2011-07-19 19:32:50 +00:00
|
|
|
#
|
2025-06-23 21:27:19 +00:00
|
|
|
# Copyright (c) 2025 SUSE LLC
|
2011-07-19 19:32:50 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2025-06-23 21:27:19 +00:00
|
|
|
# Please submit bugfixes or comments via https://bugs.opensuse.org/
|
2011-07-19 19:32:50 +00:00
|
|
|
#
|
2010-11-19 20:11:05 +00:00
|
|
|
|
2011-07-25 15:34:01 +00:00
|
|
|
|
2025-06-23 21:27:19 +00:00
|
|
|
%define cpan_name Contextual-Return
|
2010-11-19 20:11:05 +00:00
|
|
|
Name: perl-Contextual-Return
|
2025-06-23 21:27:19 +00:00
|
|
|
Version: 0.4.14
|
2012-02-27 09:03:22 +00:00
|
|
|
Release: 0
|
2025-06-23 21:27:19 +00:00
|
|
|
# 0.004014 -> normalize -> 0.4.14
|
|
|
|
%define cpan_version 0.004014
|
|
|
|
License: Artistic-1.0 OR GPL-1.0-or-later
|
2012-05-30 11:32:53 +00:00
|
|
|
Summary: Create context-sensitive return values
|
2025-06-23 21:27:19 +00:00
|
|
|
URL: https://metacpan.org/release/%{cpan_name}
|
|
|
|
Source0: https://cpan.metacpan.org/authors/id/D/DC/DCONWAY/%{cpan_name}-%{cpan_version}.tar.gz
|
2015-09-14 19:30:32 +00:00
|
|
|
Source1: cpanspec.yml
|
2025-08-12 18:12:41 +02:00
|
|
|
Source100: README.md
|
2011-07-19 19:32:50 +00:00
|
|
|
BuildArch: noarch
|
2010-11-19 20:11:05 +00:00
|
|
|
BuildRequires: perl
|
2010-12-03 13:58:48 +00:00
|
|
|
BuildRequires: perl-macros
|
2011-07-19 19:32:50 +00:00
|
|
|
BuildRequires: perl(Want)
|
2012-02-27 09:03:22 +00:00
|
|
|
BuildRequires: perl(version)
|
2011-07-19 19:32:50 +00:00
|
|
|
Requires: perl(Want)
|
2012-02-27 09:03:22 +00:00
|
|
|
Requires: perl(version)
|
2025-06-23 21:27:19 +00:00
|
|
|
Provides: perl(Contextual::Return) = %{version}
|
|
|
|
Provides: perl(Contextual::Return::Failure) = 0.0.3
|
|
|
|
Provides: perl(Contextual::Return::Lvalue)
|
|
|
|
Provides: perl(Contextual::Return::Value)
|
|
|
|
Provides: perl(DB)
|
|
|
|
%undefine __perllib_provides
|
2011-07-19 19:32:50 +00:00
|
|
|
%{perl_requires}
|
2010-11-19 20:11:05 +00:00
|
|
|
|
|
|
|
%description
|
2011-07-19 19:32:50 +00:00
|
|
|
Usually, when you need to create a subroutine that returns different values
|
|
|
|
in different contexts (list, scalar, or void), you write something like:
|
|
|
|
|
|
|
|
sub get_server_status {
|
|
|
|
my ($server_ID) = @_;
|
|
|
|
|
|
|
|
# Acquire server data somehow...
|
|
|
|
my %server_data = _ascertain_server_status($server_ID);
|
|
|
|
|
|
|
|
# Return different components of that data,
|
|
|
|
# depending on call context...
|
|
|
|
if (wantarray()) {
|
|
|
|
return @server_data{ qw(name uptime load users) };
|
|
|
|
}
|
|
|
|
if (defined wantarray()) {
|
|
|
|
return $server_data{load};
|
|
|
|
}
|
|
|
|
if (!defined wantarray()) {
|
|
|
|
carp 'Useless use of get_server_status() in void context';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
croak q{Bad context! No biscuit!};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
That works okay, but the code could certainly be more readable. In its
|
|
|
|
simplest usage, this module makes that code more readable by providing
|
|
|
|
three subroutines--'LIST()', 'SCALAR()', 'VOID()'--that are true only when
|
|
|
|
the current subroutine is called in the corresponding context:
|
|
|
|
|
|
|
|
use Contextual::Return;
|
|
|
|
|
|
|
|
sub get_server_status {
|
|
|
|
my ($server_ID) = @_;
|
|
|
|
|
|
|
|
# Acquire server data somehow...
|
|
|
|
my %server_data = _ascertain_server_status($server_ID);
|
|
|
|
|
|
|
|
# Return different components of that data
|
|
|
|
# depending on call context...
|
|
|
|
if (LIST) { return @server_data{ qw(name uptime load users) } }
|
|
|
|
if (SCALAR) { return $server_data{load} }
|
|
|
|
if (VOID) { print "$server_data{load}\n" }
|
|
|
|
else { croak q{Bad context! No biscuit!} }
|
|
|
|
}
|
2010-11-19 20:11:05 +00:00
|
|
|
|
|
|
|
%prep
|
2025-06-23 21:27:19 +00:00
|
|
|
%autosetup -n %{cpan_name}-%{cpan_version} -p1
|
2010-11-19 20:11:05 +00:00
|
|
|
|
|
|
|
%build
|
2025-06-23 21:27:19 +00:00
|
|
|
perl Makefile.PL INSTALLDIRS=vendor
|
|
|
|
%make_build
|
2010-11-19 20:11:05 +00:00
|
|
|
|
|
|
|
%check
|
2025-06-23 21:27:19 +00:00
|
|
|
make test
|
2010-11-19 20:11:05 +00:00
|
|
|
|
2011-07-19 19:32:50 +00:00
|
|
|
%install
|
2015-09-14 19:30:32 +00:00
|
|
|
%perl_make_install
|
|
|
|
%perl_process_packlist
|
2011-07-19 19:32:50 +00:00
|
|
|
%perl_gen_filelist
|
|
|
|
|
|
|
|
%files -f %{name}.files
|
2010-11-19 20:11:05 +00:00
|
|
|
%doc Changes README
|
|
|
|
|
2011-07-19 19:32:50 +00:00
|
|
|
%changelog
|