Name : perl-Sub-Usage
| |
Version : 0.03
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : lp155.6.1
| Date : 2023-07-20 18:58:19
|
Group : Development/Libraries/Perl
| Source RPM : perl-Sub-Usage-0.03-lp155.6.1.src.rpm
|
Size : 0.01 MB
| |
Packager : https://www_suse_com/
| |
Summary : Issue subroutine/method usage
|
Description :
*Sub::Usage* provides functions to display usage of subroutines or methods from inside the stub. Some people like to check the parameters of the routine. For example,
sub turn_on { AATT_ >= 2 or die \"usage: turn_on(NAME, COLOR [, INTENSITY])\ \"; }
With the \'usage\' function (exported by default), you can achieve the same results (and more) without having to remember the subroutine name.
use Sub::Usage;
sub turn_on { AATT_ >= 2 or usage \'NAME, COLOR [, INTENSITY]\'; }
* *usage()*
The \'usage\' function makes use of the built-in \'caller\' function to determine the subroutine name. When, for example, \'turn_on\' is called with inappropriate parameters, \'usage\' will terminate the program with backtrace information and print an error message like the following:
usage: turn_on(NAME, COLOR [, INTENSITY])
If \'turn_on\' is a method, a prefix can be added to indicate whether it is being called as an object method or a class method.
package Light::My::Fire; use Sub::Usage;
sub turn_on { AATT_ >= 3 or usage \'NAME, COLOR [, INTENSITY]\', \'$light\'; }
or,
sub turn_on { AATT_ >= 3 or usage \'NAME, COLOR [, INTENSITY]\', __PACKAGE__; }
The error message will then be either:
usage: $light->turn_on(NAME, COLOR [, INTENSITY])
or,
usage: Light::My::Fire->turn_on(NAME, COLOR [, INTENSITY])
* *warn_hard*
* *warn_soft*
The \'warn_hard\' and \'warn_soft\' functions are similar to \'usage\', but they don\'t die. Instead, as the their names suggest, they only warn about the problem and return undef. This can be handy for having the subroutine print the error message and return immediately in one step.
sub turn_off { AATT_ >= 2 or return warn_hard(\'NAME\', \'$light\'); }
The difference between the two is that \'warn_soft\' only works when *$^W* holds true, while \'warn_hard\' always works regardless of the value of *$^W*.
* *parse_fqpn*
The \'parse_fqpn\' function is called internally. It takes a string that contains a fully qualified package name and returns pieces of the name. It can also accept numeric parameters that determine what it returns.
By default, it will just return the last part of the name, which is the subroutine name in this case. Of course it doesn\'t know whether it\'s really a subroutine name or another name from the symbol table, or even just garbage.
my $sub = parse_fqpn(\'Sub::Usage::usage\');
my $sub = parse_fqpn(\'Sub::Usage::usage\', 1);
my($pack, $sub) = parse_fqpn(\'Sub::Usage::usage\', 2);
my(AATTparts) = parse_fqpn(\'Sub::Usage::usage\', 3);
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl:/CPAN-S/15.5/noarch |