{
    "content": [
        {
            "type": "text",
            "text": "# Attribute::Handlers (perldoc)\n\n## NAME\n\nAttribute::Handlers - Simpler definition of attribute handlers\n\n## SYNOPSIS\n\npackage 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']);\n\n## DESCRIPTION\n\nThis module, when inherited by a package, allows that package's class to\ndefine attribute handler subroutines for specific attributes. Variables\nand subroutines subsequently defined in that package, or in packages\nderived from that package may be given attributes with the same names as\nthe attribute handler subroutines, which will then be called in one of\nthe compilation phases (i.e. in a \"BEGIN\", \"CHECK\", \"INIT\", or \"END\"\nblock). (\"UNITCHECK\" blocks don't correspond to a global compilation\nphase, so they can't be specified here.)\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **SYNOPSIS**\n- **DESCRIPTION** (4 subsections)\n- **EXAMPLES**\n- **UTILITY FUNCTIONS**\n- **DIAGNOSTICS**\n- **AUTHOR**\n- **BUGS**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Attribute::Handlers",
        "section": "",
        "mode": "perldoc",
        "summary": "Attribute::Handlers - Simpler definition of attribute handlers",
        "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']);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "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": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 58,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 116,
                "subsections": [
                    {
                        "name": "Typed lexicals",
                        "lines": 14
                    },
                    {
                        "name": "Type-specific attribute handlers",
                        "lines": 41
                    },
                    {
                        "name": "Non-interpretive attribute handlers",
                        "lines": 16
                    },
                    {
                        "name": "Phase-specific attribute handlers",
                        "lines": 151
                    }
                ]
            },
            {
                "name": "EXAMPLES",
                "lines": 138,
                "subsections": []
            },
            {
                "name": "UTILITY FUNCTIONS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "DIAGNOSTICS",
                "lines": 37,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 4,
                "subsections": []
            }
        ],
        "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\ndefine attribute handler subroutines for specific attributes. Variables\nand subroutines subsequently defined in that package, or in packages\nderived from that package may be given attributes with the same names as\nthe attribute handler subroutines, which will then be called in one of\nthe compilation phases (i.e. in a \"BEGIN\", \"CHECK\", \"INIT\", or \"END\"\nblock). (\"UNITCHECK\" blocks don't correspond to a global compilation\nphase, so they can't be specified here.)\n\nTo create a handler, define it as a subroutine with the same name as the\ndesired attribute, and declare the subroutine itself with the attribute\n\":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.\nThereafter, any subroutine declared with a \":Loud\" attribute in the\nclass 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\nsubroutine;\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\npackage:\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\n(except, of course, that $[2] will be a reference to the variable).\n\nThe package name argument will typically be the name of the class into\nwhich the subroutine was declared, but it may also be the name of a\nderived class (since handlers are inherited).\n\nIf a lexical variable is given an attribute, there is no symbol table to\nwhich it belongs, so the symbol table argument ($[1]) is set to the\nstring 'LEXICAL' in that case. Likewise, ascribing an attribute to an\nanonymous subroutine results in a symbol table argument of 'ANON'.\n\nThe data argument passes in the value (if any) associated with the\nattribute. For example, if &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,\nman!\" would be passed as the last argument.\n\nAttribute::Handlers makes strenuous efforts to convert the data argument\n($[4]) to a usable form before passing it to the handler (but see\n\"Non-interpretive attribute handlers\"). If those efforts succeed, the\ninterpreted 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\ndata argument. While:\n\nsub foo :Loud(['till','ears','are','bleeding']) {...}\n\ncauses it to pass \"[ ['till','ears','are','bleeding'] ]\"; the array\nreference specified in the data being passed inside the standard array\nreference indicating successful interpretation.\n\nHowever, if the data can't be parsed as valid Perl, then it is passed as\nan uninterpreted string. 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'\nrespectively to be passed as 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\nis ascribed an attribute, the handler that is invoked is the one\nbelonging to the package to which it is typed. For example, the\nfollowing 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\ndefines a handler for \":Loud\" attributes).\n"
                    },
                    {
                        "name": "Type-specific attribute handlers",
                        "content": "If an attribute handler is declared and the \":ATTR\" specifier is given\nthe name of a built-in type (\"SCALAR\", \"ARRAY\", \"HASH\", or \"CODE\"), the\nhandler is only applied to declarations of that type. For example, the\nfollowing 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\n(but you'll need to specify \"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\nused for all types of referents 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\nthe data argument ($[4]) to a usable form before passing it to the\nhandler get in the way.\n\nYou can turn off that eagerness-to-help by declaring an attribute\nhandler with the keyword \"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\nreceives and simply passes it 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\nphase (in a \"CHECK\" block). This seems to be optimal in most cases\nbecause most things that can be defined are defined by that point but\nnothing has been executed.\n\nHowever, it is possible to set up attribute handlers that are called at\nother points in the program's compilation or execution, by explicitly\nstating the phase (or phases) in which you wish the attribute handler to\nbe 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\nin two or more phases. The phase name is passed as the handler's final\nargument.\n\nNote that attribute handlers that are scheduled for the \"BEGIN\" phase\nare handled as soon as the attribute is detected (i.e. before any\nsubsequently defined \"BEGIN\" blocks are executed).\n\nAttributes as \"tie\" interfaces\nAttributes make an excellent and intuitive interface through which to\ntie variables. For example:\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\n$data variable, if the attribute is given a list of arguments, $data\nwill consist of a single array reference; otherwise, it will consist of\nthe single argument directly. Since Tie::Cycle requires its cycling\nvalues to be passed as an array reference, this means that we need to\nwrap non-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\nexpects its arguments as a 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\nprovides a way to automate it: specifying 'autotie' in the \"use\nAttribute::Handlers\" statement. So, the cycling example, could also be\nwritten:\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,\nsince the \"autotie\" mechanism passes \"tie\" a list of arguments as a list\n(as in the Tie::Whatever example), *not* as an array reference (as in\nthe 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\nis the name of an attribute to be created, and each value is the class\nto which variables ascribed that attribute should be tied.\n\nNote that there is no longer any need to import the Tie::Cycle module --\nAttribute::Handlers takes care of that automagically. You can even pass\narguments to the module's \"import\" subroutine, by appending them to the\nclass 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\ncurrent package. Otherwise 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\ntie, and need to export their attributes to any module that calls them.\nTo facilitate this, Attribute::Handlers recognizes a special\n\"pseudo-class\" -- \"CALLER\", which may be specified as the qualifier\nof an 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\npackage that imports the Tie::Me::Kangaroo:Down::Sport module.\n\nNote that it is important to quote the CALLER::Roo identifier\nbecause a bug in perl 5.8 will refuse to parse it and cause an unknown\nerror.\n\nPassing the tied object to \"tie\"\nOccasionally it is important to pass a reference to the object being\ntied to the TIESCALAR, TIEHASH, 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\nbeing 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,\nthen 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\nexample:\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\nfor $referent, which is a reference to a variable or subroutine\n(SCALAR, ARRAY, HASH, or CODE). If it finds the typeglob, it returns\nit. Otherwise, it returns undef. Note that \"findsym\" memoizes the\ntypeglobs it has previously successfully found, so subsequent calls\nwith the same arguments should be much faster.\n",
                "subsections": []
            },
            "DIAGNOSTICS": {
                "content": "\"Bad attribute type: ATTR(%s)\"\nAn attribute handler was specified with an \":ATTR(*reftype*)\", but\nthe type of referent it was defined to handle wasn't one of the five\npermitted: \"SCALAR\", \"ARRAY\", \"HASH\", \"CODE\", or \"ANY\".\n\n\"Attribute handler %s doesn't handle %s attributes\"\nA handler for attributes of the specified name *was* defined, but\nnot for the specified type of declaration. Typically encountered\nwhen trying to apply a \"VAR\" attribute handler to a subroutine, or a\n\"SCALAR\" attribute handler to some other type of variable.\n\n\"Declaration of %s attribute in package %s may clash with future\nreserved word\"\nA handler for an attributes with an all-lowercase name was declared.\nAn attribute with an all-lowercase name might have a meaning to Perl\nitself some day, even though most don't yet. Use a mixed-case\nattribute name, instead.\n\n\"Can't have two ATTR specifiers on one subroutine\"\nYou just can't, okay? Instead, put all the specifications together\nwith commas between them in a single \"ATTR(*specification*)\".\n\n\"Can't autotie a %s\"\nYou can only declare autoties for types \"SCALAR\", \"ARRAY\", and\n\"HASH\". They're the only things (apart from typeglobs -- which are\nnot declarable) that Perl can tie.\n\n\"Internal error: %s symbol went missing\"\nSomething is rotten in the state of the program. An attributed\nsubroutine ceased to exist between the point it was declared and the\npoint at which its attribute handler(s) would have been called.\n\n\"Won't be able to apply END handler\"\nYou have defined an END handler for an attribute that is being\napplied to a lexical variable. Since the variable may not be\navailable during END this won't happen.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Damian Conway (damian@conway.org). The maintainer of this module is now\nRafael Garcia-Suarez (rgarciasuarez@gmail.com).\n\nMaintainer of the CPAN release is Steffen Mueller (smueller@cpan.org).\nContact him with technical difficulties with respect to the packaging of\nthe CPAN module.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "There are undoubtedly serious bugs lurking somewhere in code this funky\n:-) Bug reports and other 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": []
            }
        }
    }
}