Attribute::Handlers::Prospective

Richer semantics for attribute handlers
Download

Attribute::Handlers::Prospective Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Damian Conway
  • Publisher web site:
  • http://search.cpan.org/~dconway/

Attribute::Handlers::Prospective Tags


Attribute::Handlers::Prospective Description

Richer semantics for attribute handlers Attribute::Handlers::Prospective is a Perl module, that 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).SYNOPSIS package MyClass; require v5.6.1; use Attribute::Handlers::Prospective; sub Good : ATTR(SCALAR) { my ($package, $symbol, $referent, $attr, $data, $phase) = @_; # Invoked for any scalar variable with a :Good attribute, # provided the variable was declared in MyClass (or # a derived class) or typed to MyClass. # Do whatever to $referent here (executed in INIT phase). ... } sub Bad : ATTR(SCALAR) { # Invoked for any scalar variable with a :Bad attribute, # provided the variable was declared in MyClass (or # a derived class) or typed to MyClass. ... } sub Good : ATTR(ARRAY) { # Invoked for any array variable with a :Good attribute, # provided the variable was declared in MyClass (or # a derived class) or typed to MyClass. ... } sub Ugly : ATTR(CODE) { # Invoked for any subroutine declared in MyClass (or a # derived class) with an :Ugly attribute. ... } sub Omni : ATTR { # Invoked for any scalar, array, hash, or subroutine # with an :Omni attribute, provided the variable or # subroutine was declared in MyClass (or a derived class) # or the variable was typed to MyClass. # Use ref($_) to determine what kind of referent it was. ... } sub AUTOATTR : ATTR { # A handler named AUTOATTR is automagically invoked for # any scalar, array, hash, or subroutine with an attribute # for which no explicit handler is defined # This is analogous to sub AUTOLOAD for method calls. # Use $_ to determine the actual name of the attribute ... } sub PREATTR : ATTR { my ($package, $symbol, $referent, $attr, $arglists, $phase) = @_; # Any handler named PREATTR is automagically invoked before # any other attribute handlers on the referent. # $_ contains an array of arrays, each of which is the # complete argument list that will be sent to each attribute # ascribed to the referent ... sub POSTATTR : ATTR { my ($package, $symbol, $referent, $attr, $arglists, $phase) = @_; # Any handler named POSTATTR is automagically invoked after # any other attribute handlers on the referent. # $_ contains an array of arrays, each of which is the # complete argument list that was sent to each attribute # ascribed to the referent ... } Requirements: · Perl


Attribute::Handlers::Prospective Related Software