Name : perl-Contextual-Return
| |
Version : 0.004014
| Vendor : openSUSE
|
Release : lp151.2.2
| Date : 2018-07-21 11:54:42
|
Group : Development/Libraries/Perl
| Source RPM : perl-Contextual-Return-0.004014-lp151.2.2.src.rpm
|
Size : 0.16 MB
| |
Packager : https://bugs_opensuse_org
| |
Summary : Create context-sensitive return values
|
Description :
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) = AATT_;
my %server_data = _ascertain_server_status($server_ID);
if (wantarray()) { return AATTserver_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) = AATT_;
my %server_data = _ascertain_server_status($server_ID);
if (LIST) { return AATTserver_data{ qw(name uptime load users) } } if (SCALAR) { return $server_data{load} } if (VOID) { print \"$server_data{load}\ \" } else { croak q{Bad context! No biscuit!} } }
|
RPM found in directory: /vol/rzm3/linux-opensuse/ports/armv7hl/distribution/leap/15.1/repo/oss/noarch |