Name : perl-Attribute-Handlers-Prospective
| |
Version : 0.01
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : lp155.9.1
| Date : 2023-07-20 21:15:31
|
Group : Development/Libraries/Perl
| Source RPM : perl-Attribute-Handlers-Prospective-0.01-lp155.9.1.src.rpm
|
Size : 0.03 MB
| |
Packager : https://www_suse_com/
| |
Summary : Richer semantics for attribute handlers
|
Description :
This module, when inherited by a package, allows that package\'s class to define attribute handler subroutines for specific attributes. Variables and subroutines subsequently defined in that package, or in packages derived from that package may be given attributes with the same names as the attribute handler subroutines, which will then be called in one of the compilation phases (i.e. in a \'BEGIN\', \'CHECK\', \'INIT\', run-time, or \'END\' block).
To create a handler, define it as a subroutine with the same name as the desired attribute, and declare the subroutine itself with the attribute \':ATTR\'. For example:
package LoudDecl; use Attribute::Handlers::Prospective;
sub Loud :ATTR { my ($package, $symbol, $referent, $attr, $data, $phase) = AATT_; print STDERR ref($referent), \" \", *{$symbol}{NAME}, \" \", \"($referent) \", \"was just declared \", \"and ascribed the ${attr} attribute \", \"with data ($data)\ \", \"in phase $phase\ \"; }
This creates an handler for the attribute \':Loud\' in the class LoudDecl. Thereafter, any subroutine declared with a \':Loud\' attribute in the class LoudDecl:
package LoudDecl;
sub foo: Loud {...}
causes the above handler to be invoked, and passed:
* [0]
the name of the package into which it was declared;
* [1]
a reference to the symbol table entry (typeglob) containing the subroutine;
* [2]
a reference to the subroutine;
* [3]
the name of the attribute;
* [4]
any data associated with that attribute;
* [5]
the name of the phase in which the handler is being invoked.
Likewise, declaring any variables with the \':Loud\' attribute within the package:
package LoudDecl;
my $foo :Loud; my AATTfoo :Loud; my %foo :Loud;
will cause the handler to be called with a similar argument list (except, of course, that \'$_[2]\' will be a reference to the variable).
The package name argument will typically be the name of the class into which the subroutine was declared, but it may also be the name of a derived class (since handlers are inherited).
If a lexical variable is given an attribute, there is no symbol table to which it belongs, so the symbol table argument (\'$_[1]\') is set to the string \'\'LEXICAL(_name_)\'\', where _name_ is the name of the lexical (including its sigil). Likewise, ascribing an attribute to an anonymous subroutine results in a symbol table argument of \'\'ANON\'\'.
The data argument passes in the value (if any) associated with the attribute. For example, if \'&foo\' had been declared:
sub foo :Loud(\"turn it up to 11, man!\") {...}
then the string \'\"turn it up to 11, man!\"\' would be passed as the last argument.
Attribute::Handlers::Prospective usually treats the value(s) passed as the the data argument (\'$_[4]\') as standard Perl (but see \"Non-interpretive attribute handlers\"). The attribute\'s arguments are evaluated in an array context and passed as an anonymous array.
For example, all of these:
sub foo :Loud(till=>ears=>are=>bleeding) {...} sub foo :Loud([\'till\',\'ears\',\'are\',\'bleeding\']) {...} sub foo :Loud(qw/till ears are bleeding/) {...}
causes it to pass \'[\'till\',\'ears\',\'are\',\'bleeding\']\' as the handler\'s data argument. If the data can\'t be parsed as valid Perl, then a compilation error will occur.
If no value is associated with the attribute, \'undef\' is passed.
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl:/CPAN-A/15.5/noarch |