{
    "mode": "perldoc",
    "parameter": "Attribute::Handlers",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Attribute%3A%3AHandlers/json",
    "generated": "2026-06-10T23:07:32Z",
    "synopsis": "package MyClass;\nrequire 5.006;\nuse Attribute::Handlers;\nno warnings 'redefine';\nsub Good : ATTR(SCALAR) {\nmy ($package, $symbol, $referent, $attr, $data) = @;\n# Invoked for any scalar variable with a :Good attribute,\n# provided the variable was declared in MyClass (or\n# a derived class) or typed to MyClass.\n# Do whatever to $referent here (executed in CHECK phase).\n...\n}\nsub Bad : ATTR(SCALAR) {\n# Invoked for any scalar variable with a :Bad attribute,\n# provided the variable was declared in MyClass (or\n# a derived class) or typed to MyClass.\n...\n}\nsub Good : ATTR(ARRAY) {\n# Invoked for any array variable with a :Good attribute,\n# provided the variable was declared in MyClass (or\n# a derived class) or typed to MyClass.\n...\n}\nsub Good : ATTR(HASH) {\n# Invoked for any hash variable with a :Good attribute,\n# provided the variable was declared in MyClass (or\n# a derived class) or typed to MyClass.\n...\n}\nsub Ugly : ATTR(CODE) {\n# Invoked for any subroutine declared in MyClass (or a\n# derived class) with an :Ugly attribute.\n...\n}\nsub Omni : ATTR {\n# Invoked for any scalar, array, hash, or subroutine\n# with an :Omni attribute, provided the variable or\n# subroutine was declared in MyClass (or a derived class)\n# or the variable was typed to MyClass.\n# Use ref($[2]) to determine what kind of referent it was.\n...\n}\nuse Attribute::Handlers autotie => { Cycle => Tie::Cycle };\nmy $next : Cycle(['A'..'Z']);",
    "sections": {
        "NAME": {
            "content": "Attribute::Handlers - Simpler definition of attribute handlers\n",
            "subsections": []
        },
        "VERSION": {
            "content": "This document describes version 1.01 of Attribute::Handlers.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package MyClass;\nrequire 5.006;\nuse Attribute::Handlers;\nno warnings 'redefine';\n\n\nsub Good : ATTR(SCALAR) {\nmy ($package, $symbol, $referent, $attr, $data) = @;\n\n# Invoked for any scalar variable with a :Good attribute,\n# provided the variable was declared in MyClass (or\n# a derived class) or typed to MyClass.\n\n# Do whatever to $referent here (executed in CHECK phase).\n...\n}\n\nsub Bad : ATTR(SCALAR) {\n# Invoked for any scalar variable with a :Bad attribute,\n# provided the variable was declared in MyClass (or\n# a derived class) or typed to MyClass.\n...\n}\n\nsub Good : ATTR(ARRAY) {\n# Invoked for any array variable with a :Good attribute,\n# provided the variable was declared in MyClass (or\n# a derived class) or typed to MyClass.\n...\n}\n\nsub Good : ATTR(HASH) {\n# Invoked for any hash variable with a :Good attribute,\n# provided the variable was declared in MyClass (or\n# a derived class) or typed to MyClass.\n...\n}\n\nsub Ugly : ATTR(CODE) {\n# Invoked for any subroutine declared in MyClass (or a\n# derived class) with an :Ugly attribute.\n...\n}\n\nsub Omni : ATTR {\n# Invoked for any scalar, array, hash, or subroutine\n# with an :Omni attribute, provided the variable or\n# subroutine was declared in MyClass (or a derived class)\n# or the variable was typed to MyClass.\n# Use ref($[2]) to determine what kind of referent it was.\n...\n}\n\n\nuse Attribute::Handlers autotie => { Cycle => Tie::Cycle };\n\nmy $next : Cycle(['A'..'Z']);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module, when inherited by a package, allows that package's class to define attribute\nhandler subroutines for specific attributes. Variables and subroutines subsequently defined in\nthat package, or in packages derived from that package may be given attributes with the same\nnames as the attribute handler subroutines, which will then be called in one of the compilation\nphases (i.e. in a \"BEGIN\", \"CHECK\", \"INIT\", or \"END\" block). (\"UNITCHECK\" blocks don't\ncorrespond to a global compilation phase, so they can't be specified here.)\n\nTo create a handler, define it as a subroutine with the same name as the desired attribute, and\ndeclare the subroutine itself with the attribute \":ATTR\". For example:\n\npackage LoudDecl;\nuse Attribute::Handlers;\n\nsub Loud :ATTR {\nmy ($package, $symbol, $referent, $attr, $data, $phase,\n$filename, $linenum) = @;\nprint STDERR\nref($referent), \" \",\n*{$symbol}{NAME}, \" \",\n\"($referent) \", \"was just declared \",\n\"and ascribed the ${attr} attribute \",\n\"with data ($data)\\n\",\n\"in phase $phase\\n\",\n\"in file $filename at line $linenum\\n\";\n}\n\nThis creates a handler for the attribute \":Loud\" in the class LoudDecl. Thereafter, any\nsubroutine declared with a \":Loud\" attribute in the class LoudDecl:\n\npackage LoudDecl;\n\nsub foo: Loud {...}\n\ncauses the above handler to be invoked, and passed:\n\n[0] the name of the package into which it was declared;\n\n[1] a reference to the symbol table entry (typeglob) containing the subroutine;\n\n[2] a reference to the subroutine;\n\n[3] the name of the attribute;\n\n[4] any data associated with that attribute;\n\n[5] the name of the phase in which the handler is being invoked;\n\n[6] the filename in which the handler is being invoked;\n\n[7] the line number in this file.\n\nLikewise, declaring any variables with the \":Loud\" attribute within the package:\n\npackage LoudDecl;\n\nmy $foo :Loud;\nmy @foo :Loud;\nmy %foo :Loud;\n\nwill cause the handler to be called with a similar argument list (except, of course, that $[2]\nwill be a reference to the variable).\n\nThe package name argument will typically be the name of the class into which the subroutine was\ndeclared, but it may also be the name of a derived class (since handlers are inherited).\n\nIf a lexical variable is given an attribute, there is no symbol table to which it belongs, so\nthe symbol table argument ($[1]) is set to the string 'LEXICAL' in that case. Likewise,\nascribing an attribute to an anonymous subroutine results in a symbol table argument of 'ANON'.\n\nThe data argument passes in the value (if any) associated with the attribute. For example, if\n&foo had been declared:\n\nsub foo :Loud(\"turn it up to 11, man!\") {...}\n\nthen a reference to an array containing the string \"turn it up to 11, man!\" would be passed as\nthe last argument.\n\nAttribute::Handlers makes strenuous efforts to convert the data argument ($[4]) to a usable\nform before passing it to the handler (but see \"Non-interpretive attribute handlers\"). If those\nefforts succeed, the interpreted data is passed in an array reference; if they fail, the raw\ndata is passed as a string. For example, all of these:\n\nsub foo :Loud(till=>ears=>are=>bleeding) {...}\nsub foo :Loud(qw/till ears are bleeding/) {...}\nsub foo :Loud(qw/till, ears, are, bleeding/) {...}\nsub foo :Loud(till,ears,are,bleeding) {...}\n\ncauses it to pass \"['till','ears','are','bleeding']\" as the handler's data argument. While:\n\nsub foo :Loud(['till','ears','are','bleeding']) {...}\n\ncauses it to pass \"[ ['till','ears','are','bleeding'] ]\"; the array reference specified in the\ndata being passed inside the standard array reference indicating successful interpretation.\n\nHowever, if the data can't be parsed as valid Perl, then it is passed as an uninterpreted\nstring. For example:\n\nsub foo :Loud(my,ears,are,bleeding) {...}\nsub foo :Loud(qw/my ears are bleeding) {...}\n\ncause the strings 'my,ears,are,bleeding' and 'qw/my ears are bleeding' respectively to be passed\nas the data argument.\n\nIf no value is associated with the attribute, \"undef\" is passed.\n",
            "subsections": [
                {
                    "name": "Typed lexicals",
                    "content": "Regardless of the package in which it is declared, if a lexical variable is ascribed an\nattribute, the handler that is invoked is the one belonging to the package to which it is typed.\nFor example, the following declarations:\n\npackage OtherClass;\n\nmy LoudDecl $loudobj : Loud;\nmy LoudDecl @loudobjs : Loud;\nmy LoudDecl %loudobjex : Loud;\n\ncauses the LoudDecl::Loud handler to be invoked (even if OtherClass also defines a handler for\n\":Loud\" attributes).\n"
                },
                {
                    "name": "Type-specific attribute handlers",
                    "content": "If an attribute handler is declared and the \":ATTR\" specifier is given the name of a built-in\ntype (\"SCALAR\", \"ARRAY\", \"HASH\", or \"CODE\"), the handler is only applied to declarations of that\ntype. For example, the following definition:\n\npackage LoudDecl;\n\nsub RealLoud :ATTR(SCALAR) { print \"Yeeeeow!\" }\n\ncreates an attribute handler that applies only to scalars:\n\npackage Painful;\nuse base LoudDecl;\n\nmy $metal : RealLoud;           # invokes &LoudDecl::RealLoud\nmy @metal : RealLoud;           # error: unknown attribute\nmy %metal : RealLoud;           # error: unknown attribute\nsub metal : RealLoud {...}      # error: unknown attribute\n\nYou can, of course, declare separate handlers for these types as well (but you'll need to\nspecify \"no warnings 'redefine'\" to do it quietly):\n\npackage LoudDecl;\nuse Attribute::Handlers;\nno warnings 'redefine';\n\nsub RealLoud :ATTR(SCALAR) { print \"Yeeeeow!\" }\nsub RealLoud :ATTR(ARRAY) { print \"Urrrrrrrrrr!\" }\nsub RealLoud :ATTR(HASH) { print \"Arrrrrgggghhhhhh!\" }\nsub RealLoud :ATTR(CODE) { croak \"Real loud sub torpedoed\" }\n\nYou can also explicitly indicate that a single handler is meant to be used for all types of\nreferents like so:\n\npackage LoudDecl;\nuse Attribute::Handlers;\n\nsub SeriousLoud :ATTR(ANY) { warn \"Hearing loss imminent\" }\n\n(I.e. \"ATTR(ANY)\" is a synonym for \":ATTR\").\n"
                },
                {
                    "name": "Non-interpretive attribute handlers",
                    "content": "Occasionally the strenuous efforts Attribute::Handlers makes to convert the data argument\n($[4]) to a usable form before passing it to the handler get in the way.\n\nYou can turn off that eagerness-to-help by declaring an attribute handler with the keyword\n\"RAWDATA\". For example:\n\nsub Raw          : ATTR(RAWDATA) {...}\nsub Nekkid       : ATTR(SCALAR,RAWDATA) {...}\nsub Au::Naturale : ATTR(RAWDATA,ANY) {...}\n\nThen the handler makes absolutely no attempt to interpret the data it receives and simply passes\nit as a string:\n\nmy $power : Raw(1..100);        # handlers receives \"1..100\"\n"
                },
                {
                    "name": "Phase-specific attribute handlers",
                    "content": "By default, attribute handlers are called at the end of the compilation phase (in a \"CHECK\"\nblock). This seems to be optimal in most cases because most things that can be defined are\ndefined by that point but nothing has been executed.\n\nHowever, it is possible to set up attribute handlers that are called at other points in the\nprogram's compilation or execution, by explicitly stating the phase (or phases) in which you\nwish the attribute handler to be called. For example:\n\nsub Early    :ATTR(SCALAR,BEGIN) {...}\nsub Normal   :ATTR(SCALAR,CHECK) {...}\nsub Late     :ATTR(SCALAR,INIT) {...}\nsub Final    :ATTR(SCALAR,END) {...}\nsub Bookends :ATTR(SCALAR,BEGIN,END) {...}\n\nAs the last example indicates, a handler may be set up to be (re)called in two or more phases.\nThe phase name is passed as the handler's final argument.\n\nNote that attribute handlers that are scheduled for the \"BEGIN\" phase are handled as soon as the\nattribute is detected (i.e. before any subsequently defined \"BEGIN\" blocks are executed).\n\nAttributes as \"tie\" interfaces\nAttributes make an excellent and intuitive interface through which to tie variables. For\nexample:\n\nuse Attribute::Handlers;\nuse Tie::Cycle;\n\nsub UNIVERSAL::Cycle : ATTR(SCALAR) {\nmy ($package, $symbol, $referent, $attr, $data, $phase) = @;\n$data = [ $data ] unless ref $data eq 'ARRAY';\ntie $$referent, 'Tie::Cycle', $data;\n}\n\n# and thereafter...\n\npackage main;\n\nmy $next : Cycle('A'..'Z');     # $next is now a tied variable\n\nwhile (<>) {\nprint $next;\n}\n\nNote that, because the \"Cycle\" attribute receives its arguments in the $data variable, if the\nattribute is given a list of arguments, $data will consist of a single array reference;\notherwise, it will consist of the single argument directly. Since Tie::Cycle requires its\ncycling values to be passed as an array reference, this means that we need to wrap\nnon-array-reference arguments in an array constructor:\n\n$data = [ $data ] unless ref $data eq 'ARRAY';\n\nTypically, however, things are the other way around: the tieable class expects its arguments as\na flattened list, so the attribute looks like:\n\nsub UNIVERSAL::Cycle : ATTR(SCALAR) {\nmy ($package, $symbol, $referent, $attr, $data, $phase) = @;\nmy @data = ref $data eq 'ARRAY' ? @$data : $data;\ntie $$referent, 'Tie::Whatever', @data;\n}\n\nThis software pattern is so widely applicable that Attribute::Handlers provides a way to\nautomate it: specifying 'autotie' in the \"use Attribute::Handlers\" statement. So, the cycling\nexample, could also be written:\n\nuse Attribute::Handlers autotie => { Cycle => 'Tie::Cycle' };\n\n# and thereafter...\n\npackage main;\n\nmy $next : Cycle(['A'..'Z']);     # $next is now a tied variable\n\nwhile (<>) {\nprint $next;\n}\n\nNote that we now have to pass the cycling values as an array reference, since the \"autotie\"\nmechanism passes \"tie\" a list of arguments as a list (as in the Tie::Whatever example), *not* as\nan array reference (as in the original Tie::Cycle example at the start of this section).\n\nThe argument after 'autotie' is a reference to a hash in which each key is the name of an\nattribute to be created, and each value is the class to which variables ascribed that attribute\nshould be tied.\n\nNote that there is no longer any need to import the Tie::Cycle module -- Attribute::Handlers\ntakes care of that automagically. You can even pass arguments to the module's \"import\"\nsubroutine, by appending them to the class name. For example:\n\nuse Attribute::Handlers\nautotie => { Dir => 'Tie::Dir qw(DIRUNLINK)' };\n\nIf the attribute name is unqualified, the attribute is installed in the current package.\nOtherwise it is installed in the qualifier's package:\n\npackage Here;\n\nuse Attribute::Handlers autotie => {\nOther::Good => Tie::SecureHash, # tie attr installed in Other::\nBad => Tie::Taxes,      # tie attr installed in Here::\nUNIVERSAL::Ugly => Software::Patent # tie attr installed everywhere\n};\n\nAutoties are most commonly used in the module to which they actually tie, and need to export\ntheir attributes to any module that calls them. To facilitate this, Attribute::Handlers\nrecognizes a special \"pseudo-class\" -- \"CALLER\", which may be specified as the qualifier of\nan attribute:\n\npackage Tie::Me::Kangaroo:Down::Sport;\n\nuse Attribute::Handlers autotie =>\n{ 'CALLER::Roo' => PACKAGE };\n\nThis causes Attribute::Handlers to define the \"Roo\" attribute in the package that imports the\nTie::Me::Kangaroo:Down::Sport module.\n\nNote that it is important to quote the CALLER::Roo identifier because a bug in perl 5.8 will\nrefuse to parse it and cause an unknown error.\n\nPassing the tied object to \"tie\"\nOccasionally it is important to pass a reference to the object being tied to the TIESCALAR,\nTIEHASH, etc. that ties it.\n\nThe \"autotie\" mechanism supports this too. The following code:\n\nuse Attribute::Handlers autotieref => { Selfish => Tie::Selfish };\nmy $var : Selfish(@args);\n\nhas the same effect as:\n\ntie my $var, 'Tie::Selfish', @args;\n\nBut when \"autotieref\" is used instead of \"autotie\":\n\nuse Attribute::Handlers autotieref => { Selfish => Tie::Selfish };\nmy $var : Selfish(@args);\n\nthe effect is to pass the \"tie\" call an extra reference to the variable being tied:\n\ntie my $var, 'Tie::Selfish', \\$var, @args;\n"
                }
            ]
        },
        "EXAMPLES": {
            "content": "If the class shown in \"SYNOPSIS\" were placed in the MyClass.pm module, then the following code:\n\npackage main;\nuse MyClass;\n\nmy MyClass $slr :Good :Bad(11-1) :Omni(-vorous);\n\npackage SomeOtherClass;\nuse base MyClass;\n\nsub tent { 'acle' }\n\nsub fn :Ugly(sister) :Omni('po',tent()) {...}\nmy @arr :Good :Omni(s/cie/nt/);\nmy %hsh :Good(q/bye/) :Omni(q/bus/);\n\nwould cause the following handlers to be invoked:\n\n# my MyClass $slr :Good :Bad(11-1) :Omni(-vorous);\n\nMyClass::Good:ATTR(SCALAR)( 'MyClass',          # class\n'LEXICAL',          # no typeglob\n\\$slr,              # referent\n'Good',             # attr name\nundef               # no attr data\n'CHECK',            # compiler phase\n);\n\nMyClass::Bad:ATTR(SCALAR)( 'MyClass',           # class\n'LEXICAL',           # no typeglob\n\\$slr,               # referent\n'Bad',               # attr name\n0                    # eval'd attr data\n'CHECK',             # compiler phase\n);\n\nMyClass::Omni:ATTR(SCALAR)( 'MyClass',          # class\n'LEXICAL',          # no typeglob\n\\$slr,              # referent\n'Omni',             # attr name\n'-vorous'           # eval'd attr data\n'CHECK',            # compiler phase\n);\n\n\n# sub fn :Ugly(sister) :Omni('po',tent()) {...}\n\nMyClass::UGLY:ATTR(CODE)( 'SomeOtherClass',     # class\n\\*SomeOtherClass::fn, # typeglob\n\\&SomeOtherClass::fn, # referent\n'Ugly',               # attr name\n'sister'              # eval'd attr data\n'CHECK',              # compiler phase\n);\n\nMyClass::Omni:ATTR(CODE)( 'SomeOtherClass',     # class\n\\*SomeOtherClass::fn, # typeglob\n\\&SomeOtherClass::fn, # referent\n'Omni',               # attr name\n['po','acle']         # eval'd attr data\n'CHECK',              # compiler phase\n);\n\n\n# my @arr :Good :Omni(s/cie/nt/);\n\nMyClass::Good:ATTR(ARRAY)( 'SomeOtherClass',    # class\n'LEXICAL',           # no typeglob\n\\@arr,               # referent\n'Good',              # attr name\nundef                # no attr data\n'CHECK',             # compiler phase\n);\n\nMyClass::Omni:ATTR(ARRAY)( 'SomeOtherClass',    # class\n'LEXICAL',           # no typeglob\n\\@arr,               # referent\n'Omni',              # attr name\n\"\"                   # eval'd attr data\n'CHECK',             # compiler phase\n);\n\n\n# my %hsh :Good(q/bye) :Omni(q/bus/);\n\nMyClass::Good:ATTR(HASH)( 'SomeOtherClass',     # class\n'LEXICAL',            # no typeglob\n\\%hsh,                # referent\n'Good',               # attr name\n'q/bye'               # raw attr data\n'CHECK',              # compiler phase\n);\n\nMyClass::Omni:ATTR(HASH)( 'SomeOtherClass',     # class\n'LEXICAL',            # no typeglob\n\\%hsh,                # referent\n'Omni',               # attr name\n'bus'                 # eval'd attr data\n'CHECK',              # compiler phase\n);\n\nInstalling handlers into UNIVERSAL, makes them...err..universal. For example:\n\npackage Descriptions;\nuse Attribute::Handlers;\n\nmy %name;\nsub name { return $name{$[2]}||*{$[1]}{NAME} }\n\nsub UNIVERSAL::Name :ATTR {\n$name{$[2]} = $[4];\n}\n\nsub UNIVERSAL::Purpose :ATTR {\nprint STDERR \"Purpose of \", &name, \" is $[4]\\n\";\n}\n\nsub UNIVERSAL::Unit :ATTR {\nprint STDERR &name, \" measured in $[4]\\n\";\n}\n\nLet's you write:\n\nuse Descriptions;\n\nmy $capacity : Name(capacity)\n: Purpose(to store max storage capacity for files)\n: Unit(Gb);\n\n\npackage Other;\n\nsub foo : Purpose(to foo all data before barring it) { }\n\n# etc.\n",
            "subsections": []
        },
        "UTILITY FUNCTIONS": {
            "content": "This module offers a single utility function, \"findsym()\".\n\nfindsym\nmy $symbol = Attribute::Handlers::findsym($package, $referent);\n\nThe function looks in the symbol table of $package for the typeglob for $referent, which is\na reference to a variable or subroutine (SCALAR, ARRAY, HASH, or CODE). If it finds the\ntypeglob, it returns it. Otherwise, it returns undef. Note that \"findsym\" memoizes the\ntypeglobs it has previously successfully found, so subsequent calls with the same arguments\nshould be much faster.\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "\"Bad attribute type: ATTR(%s)\"\nAn attribute handler was specified with an \":ATTR(*reftype*)\", but the type of referent it\nwas defined to handle wasn't one of the five permitted: \"SCALAR\", \"ARRAY\", \"HASH\", \"CODE\",\nor \"ANY\".\n\n\"Attribute handler %s doesn't handle %s attributes\"\nA handler for attributes of the specified name *was* defined, but not for the specified type\nof declaration. Typically encountered when trying to apply a \"VAR\" attribute handler to a\nsubroutine, or a \"SCALAR\" attribute handler to some other type of variable.\n\n\"Declaration of %s attribute in package %s may clash with future reserved word\"\nA handler for an attributes with an all-lowercase name was declared. An attribute with an\nall-lowercase name might have a meaning to Perl itself some day, even though most don't yet.\nUse a mixed-case attribute name, instead.\n\n\"Can't have two ATTR specifiers on one subroutine\"\nYou just can't, okay? Instead, put all the specifications together with commas between them\nin a single \"ATTR(*specification*)\".\n\n\"Can't autotie a %s\"\nYou can only declare autoties for types \"SCALAR\", \"ARRAY\", and \"HASH\". They're the only\nthings (apart from typeglobs -- which are not declarable) that Perl can tie.\n\n\"Internal error: %s symbol went missing\"\nSomething is rotten in the state of the program. An attributed subroutine ceased to exist\nbetween the point it was declared and the point at which its attribute handler(s) would have\nbeen called.\n\n\"Won't be able to apply END handler\"\nYou have defined an END handler for an attribute that is being applied to a lexical\nvariable. Since the variable may not be available during END this won't happen.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Damian Conway (damian@conway.org). The maintainer of this module is now Rafael Garcia-Suarez\n(rgarciasuarez@gmail.com).\n\nMaintainer of the CPAN release is Steffen Mueller (smueller@cpan.org). Contact him with\ntechnical difficulties with respect to the packaging of the CPAN module.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "There are undoubtedly serious bugs lurking somewhere in code this funky :-) Bug reports and\nother feedback are most welcome.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "Copyright (c) 2001-2014, Damian Conway. All Rights Reserved.\nThis module is free software. It may be used, redistributed\nand/or modified under the same terms as Perl itself.\n",
            "subsections": []
        }
    },
    "summary": "Attribute::Handlers - Simpler definition of attribute handlers",
    "flags": [],
    "examples": [
        "If the class shown in \"SYNOPSIS\" were placed in the MyClass.pm module, then the following code:",
        "package main;",
        "use MyClass;",
        "my MyClass $slr :Good :Bad(11-1) :Omni(-vorous);",
        "package SomeOtherClass;",
        "use base MyClass;",
        "sub tent { 'acle' }",
        "sub fn :Ugly(sister) :Omni('po',tent()) {...}",
        "my @arr :Good :Omni(s/cie/nt/);",
        "my %hsh :Good(q/bye/) :Omni(q/bus/);",
        "would cause the following handlers to be invoked:",
        "# my MyClass $slr :Good :Bad(11-1) :Omni(-vorous);",
        "MyClass::Good:ATTR(SCALAR)( 'MyClass',          # class",
        "'LEXICAL',          # no typeglob",
        "\\$slr,              # referent",
        "'Good',             # attr name",
        "undef               # no attr data",
        "'CHECK',            # compiler phase",
        ");",
        "MyClass::Bad:ATTR(SCALAR)( 'MyClass',           # class",
        "'LEXICAL',           # no typeglob",
        "\\$slr,               # referent",
        "'Bad',               # attr name",
        "0                    # eval'd attr data",
        "'CHECK',             # compiler phase",
        ");",
        "MyClass::Omni:ATTR(SCALAR)( 'MyClass',          # class",
        "'LEXICAL',          # no typeglob",
        "\\$slr,              # referent",
        "'Omni',             # attr name",
        "'-vorous'           # eval'd attr data",
        "'CHECK',            # compiler phase",
        ");",
        "# sub fn :Ugly(sister) :Omni('po',tent()) {...}",
        "MyClass::UGLY:ATTR(CODE)( 'SomeOtherClass',     # class",
        "\\*SomeOtherClass::fn, # typeglob",
        "\\&SomeOtherClass::fn, # referent",
        "'Ugly',               # attr name",
        "'sister'              # eval'd attr data",
        "'CHECK',              # compiler phase",
        ");",
        "MyClass::Omni:ATTR(CODE)( 'SomeOtherClass',     # class",
        "\\*SomeOtherClass::fn, # typeglob",
        "\\&SomeOtherClass::fn, # referent",
        "'Omni',               # attr name",
        "['po','acle']         # eval'd attr data",
        "'CHECK',              # compiler phase",
        ");",
        "# my @arr :Good :Omni(s/cie/nt/);",
        "MyClass::Good:ATTR(ARRAY)( 'SomeOtherClass',    # class",
        "'LEXICAL',           # no typeglob",
        "\\@arr,               # referent",
        "'Good',              # attr name",
        "undef                # no attr data",
        "'CHECK',             # compiler phase",
        ");",
        "MyClass::Omni:ATTR(ARRAY)( 'SomeOtherClass',    # class",
        "'LEXICAL',           # no typeglob",
        "\\@arr,               # referent",
        "'Omni',              # attr name",
        "\"\"                   # eval'd attr data",
        "'CHECK',             # compiler phase",
        ");",
        "# my %hsh :Good(q/bye) :Omni(q/bus/);",
        "MyClass::Good:ATTR(HASH)( 'SomeOtherClass',     # class",
        "'LEXICAL',            # no typeglob",
        "\\%hsh,                # referent",
        "'Good',               # attr name",
        "'q/bye'               # raw attr data",
        "'CHECK',              # compiler phase",
        ");",
        "MyClass::Omni:ATTR(HASH)( 'SomeOtherClass',     # class",
        "'LEXICAL',            # no typeglob",
        "\\%hsh,                # referent",
        "'Omni',               # attr name",
        "'bus'                 # eval'd attr data",
        "'CHECK',              # compiler phase",
        ");",
        "Installing handlers into UNIVERSAL, makes them...err..universal. For example:",
        "package Descriptions;",
        "use Attribute::Handlers;",
        "my %name;",
        "sub name { return $name{$[2]}||*{$[1]}{NAME} }",
        "sub UNIVERSAL::Name :ATTR {",
        "$name{$[2]} = $[4];",
        "sub UNIVERSAL::Purpose :ATTR {",
        "print STDERR \"Purpose of \", &name, \" is $[4]\\n\";",
        "sub UNIVERSAL::Unit :ATTR {",
        "print STDERR &name, \" measured in $[4]\\n\";",
        "Let's you write:",
        "use Descriptions;",
        "my $capacity : Name(capacity)",
        ": Purpose(to store max storage capacity for files)",
        ": Unit(Gb);",
        "package Other;",
        "sub foo : Purpose(to foo all data before barring it) { }",
        "# etc."
    ],
    "see_also": []
}