Package: perl-Contextual-Return (0.004014-bp156.3.1)
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!} } }
Package information
- Homepage
- [http://search.cpan.org/dist/Contextual-Return/]
- License
- Artistic-1.0 or GPL-1.0+
- Downstream package maintainer
- Unknown: not reported in the indexed source
- Source package
- [perl-Contextual-Return]
- Software project
- [perl-Contextual-Return]
Versions and downloads for perl-Contextual-Return
| Version / release | Architecture / repository | Package size | Installed size | Files | Publisher repository artifact |
|---|---|---|---|---|---|
| 0.004014-bp156.3.1leap-15.6 / oss | noarchopenSUSE Leap 15.6 · OSS · multi-architecture | 64 KiB | 159 KiB | list of files | perl-Contextual-Return-0.004014-bp156.3.1.noarch.rpm |
About these downloads
Each row is recorded package-index metadata for one version, architecture, suite, and repository. Names, URLs, and sizes are source-reported; a link is a potentially mutable retrieval location, not an OpenFactory redistribution claim or proof that OpenFactory retained the artifact bytes.
Dependencies and recommendations for perl-Contextual-Return
dep: perl(:MODULE_COMPAT_5.26.1)
Package not available
dep: perl(Want)
Package not available
dep: perl(version)
Package not available
Package file paths (10)
Paths come from the repository package-file index for the observed builds. They describe archive/package associations, not every file that will exist on a running system after maintainer scripts, alternatives, generated state, diversions, or installation choices.
- /usr/lib/perl5/vendor_perl/5.26.1/Contextual
- /usr/lib/perl5/vendor_perl/5.26.1/Contextual/Return
- /usr/lib/perl5/vendor_perl/5.26.1/Contextual/Return/Failure.pm
- /usr/lib/perl5/vendor_perl/5.26.1/Contextual/Return.pm
- /usr/lib/perl5/vendor_perl/5.26.1/x86_64-linux-thread-multi
- /usr/share/doc/packages/perl-Contextual-Return
- /usr/share/doc/packages/perl-Contextual-Return/Changes
- /usr/share/doc/packages/perl-Contextual-Return/README
- /usr/share/man/man3/Contextual::Return.3pm.gz
- /usr/share/man/man3/Contextual::Return::Failure.3pm.gz
Field source: openSUSE Leap 15.6 OSS
