perl-Contextual-Return

Create context-sensitive return values

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) = @_; my %server_data = _ascertain_server_status($server_ID); 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) = @_; my %server_data = _ascertain_server_status($server_ID); 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!} } }

There is no official package available for openSUSE Leap 15.5

Distributions

openSUSE Tumbleweed

openSUSE Leap 15.6

openSUSE Leap 15.5

openSUSE Leap 15.4

SUSE SLE-15-SP1

RedHat RHEL-7

isv:perlur:epel Experimental
0.004007

Unsupported distributions

The following distributions are not officially supported. Use these packages at your own risk.