⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attribute::handlers.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 3 页
字号:
If the attribute name is unqualified, the attribute is installed in thecurrent package. Otherwise it is installed in the qualifier's package:.PP.Vb 1\&        package Here;\&\&        use Attribute::Handlers autotie => {\&                Other::Good => Tie::SecureHash, # tie attr installed in Other::\&                        Bad => Tie::Taxes,      # tie attr installed in Here::\&            UNIVERSAL::Ugly => Software::Patent # tie attr installed everywhere\&        };.Ve.PPAutoties are most commonly used in the module to which they actually tie, and need to export their attributes to any module that calls them. Tofacilitate this, Attribute::Handlers recognizes a special \*(L"pseudo-class\*(R" \*(--\&\f(CW\*(C`_\|_CALLER_\|_\*(C'\fR, which may be specified as the qualifier of an attribute:.PP.Vb 1\&        package Tie::Me::Kangaroo:Down::Sport;\&\&        use Attribute::Handlers autotie => { \*(Aq_\|_CALLER_\|_::Roo\*(Aq => _\|_PACKAGE_\|_ };.Ve.PPThis causes Attribute::Handlers to define the \f(CW\*(C`Roo\*(C'\fR attribute in the packagethat imports the Tie::Me::Kangaroo:Down::Sport module..PPNote that it is important to quote the _\|_CALLER_\|_::Roo identifier becausea bug in perl 5.8 will refuse to parse it and cause an unknown error..PP\fIPassing the tied object to \f(CI\*(C`tie\*(C'\fI\fR.IX Subsection "Passing the tied object to tie".PPOccasionally it is important to pass a reference to the object being tiedto the \s-1TIESCALAR\s0, \s-1TIEHASH\s0, etc. that ties it..PPThe \f(CW\*(C`autotie\*(C'\fR mechanism supports this too. The following code:.PP.Vb 2\&        use Attribute::Handlers autotieref => { Selfish => Tie::Selfish };\&        my $var : Selfish(@args);.Ve.PPhas the same effect as:.PP.Vb 1\&        tie my $var, \*(AqTie::Selfish\*(Aq, @args;.Ve.PPBut when \f(CW"autotieref"\fR is used instead of \f(CW"autotie"\fR:.PP.Vb 2\&        use Attribute::Handlers autotieref => { Selfish => Tie::Selfish };\&        my $var : Selfish(@args);.Ve.PPthe effect is to pass the \f(CW\*(C`tie\*(C'\fR call an extra reference to the variablebeing tied:.PP.Vb 1\&        tie my $var, \*(AqTie::Selfish\*(Aq, \e$var, @args;.Ve.SH "EXAMPLES".IX Header "EXAMPLES"If the class shown in \s-1SYNOPSIS\s0 were placed in the MyClass.pmmodule, then the following code:.PP.Vb 2\&        package main;\&        use MyClass;\&\&        my MyClass $slr :Good :Bad(1**1\-1) :Omni(\-vorous);\&\&        package SomeOtherClass;\&        use base MyClass;\&\&        sub tent { \*(Aqacle\*(Aq }\&\&        sub fn :Ugly(sister) :Omni(\*(Aqpo\*(Aq,tent()) {...}\&        my @arr :Good :Omni(s/cie/nt/);\&        my %hsh :Good(q/bye) :Omni(q/bus/);.Ve.PPwould cause the following handlers to be invoked:.PP.Vb 1\&        # my MyClass $slr :Good :Bad(1**1\-1) :Omni(\-vorous);\&\&        MyClass::Good:ATTR(SCALAR)( \*(AqMyClass\*(Aq,          # class\&                                    \*(AqLEXICAL\*(Aq,          # no typeglob\&                                    \e$slr,              # referent\&                                    \*(AqGood\*(Aq,             # attr name\&                                    undef               # no attr data\&                                    \*(AqCHECK\*(Aq,            # compiler phase\&                                  );\&\&        MyClass::Bad:ATTR(SCALAR)( \*(AqMyClass\*(Aq,           # class\&                                   \*(AqLEXICAL\*(Aq,           # no typeglob\&                                   \e$slr,               # referent\&                                   \*(AqBad\*(Aq,               # attr name\&                                   0                    # eval\*(Aqd attr data\&                                   \*(AqCHECK\*(Aq,             # compiler phase\&                                 );\&\&        MyClass::Omni:ATTR(SCALAR)( \*(AqMyClass\*(Aq,          # class\&                                    \*(AqLEXICAL\*(Aq,          # no typeglob\&                                    \e$slr,              # referent\&                                    \*(AqOmni\*(Aq,             # attr name\&                                    \*(Aq\-vorous\*(Aq           # eval\*(Aqd attr data\&                                    \*(AqCHECK\*(Aq,            # compiler phase\&                                  );\&\&\&        # sub fn :Ugly(sister) :Omni(\*(Aqpo\*(Aq,tent()) {...}\&\&        MyClass::UGLY:ATTR(CODE)( \*(AqSomeOtherClass\*(Aq,     # class\&                                  \e*SomeOtherClass::fn, # typeglob\&                                  \e&SomeOtherClass::fn, # referent\&                                  \*(AqUgly\*(Aq,               # attr name\&                                  \*(Aqsister\*(Aq              # eval\*(Aqd attr data\&                                  \*(AqCHECK\*(Aq,              # compiler phase\&                                );\&\&        MyClass::Omni:ATTR(CODE)( \*(AqSomeOtherClass\*(Aq,     # class\&                                  \e*SomeOtherClass::fn, # typeglob\&                                  \e&SomeOtherClass::fn, # referent\&                                  \*(AqOmni\*(Aq,               # attr name\&                                  [\*(Aqpo\*(Aq,\*(Aqacle\*(Aq]         # eval\*(Aqd attr data\&                                  \*(AqCHECK\*(Aq,              # compiler phase\&                                );\&\&\&        # my @arr :Good :Omni(s/cie/nt/);\&\&        MyClass::Good:ATTR(ARRAY)( \*(AqSomeOtherClass\*(Aq,    # class\&                                   \*(AqLEXICAL\*(Aq,           # no typeglob\&                                   \e@arr,               # referent\&                                   \*(AqGood\*(Aq,              # attr name\&                                   undef                # no attr data\&                                   \*(AqCHECK\*(Aq,             # compiler phase\&                                 );\&\&        MyClass::Omni:ATTR(ARRAY)( \*(AqSomeOtherClass\*(Aq,    # class\&                                   \*(AqLEXICAL\*(Aq,           # no typeglob\&                                   \e@arr,               # referent\&                                   \*(AqOmni\*(Aq,              # attr name\&                                   ""                   # eval\*(Aqd attr data \&                                   \*(AqCHECK\*(Aq,             # compiler phase\&                                 );\&\&\&        # my %hsh :Good(q/bye) :Omni(q/bus/);\&                                  \&        MyClass::Good:ATTR(HASH)( \*(AqSomeOtherClass\*(Aq,     # class\&                                  \*(AqLEXICAL\*(Aq,            # no typeglob\&                                  \e%hsh,                # referent\&                                  \*(AqGood\*(Aq,               # attr name\&                                  \*(Aqq/bye\*(Aq               # raw attr data\&                                  \*(AqCHECK\*(Aq,              # compiler phase\&                                );\&                        \&        MyClass::Omni:ATTR(HASH)( \*(AqSomeOtherClass\*(Aq,     # class\&                                  \*(AqLEXICAL\*(Aq,            # no typeglob\&                                  \e%hsh,                # referent\&                                  \*(AqOmni\*(Aq,               # attr name\&                                  \*(Aqbus\*(Aq                 # eval\*(Aqd attr data\&                                  \*(AqCHECK\*(Aq,              # compiler phase\&                                );.Ve.PPInstalling handlers into \s-1UNIVERSAL\s0, makes them...err..universal.For example:.PP.Vb 2\&        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]\en";\&        }\&\&        sub UNIVERSAL::Unit :ATTR {\&                print STDERR &name, " measured in $_[4]\en";\&        }.Ve.PPLet's you write:.PP.Vb 1\&        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..Ve.SH "DIAGNOSTICS".IX Header "DIAGNOSTICS".ie n .IP """Bad attribute type: ATTR(%s)""" 4.el .IP "\f(CWBad attribute type: ATTR(%s)\fR" 4.IX Item "Bad attribute type: ATTR(%s)"An attribute handler was specified with an \f(CW\*(C`:ATTR(\f(CIref_type\f(CW)\*(C'\fR, but thetype of referent it was defined to handle wasn't one of the five permitted:\&\f(CW\*(C`SCALAR\*(C'\fR, \f(CW\*(C`ARRAY\*(C'\fR, \f(CW\*(C`HASH\*(C'\fR, \f(CW\*(C`CODE\*(C'\fR, or \f(CW\*(C`ANY\*(C'\fR..ie n .IP """Attribute handler %s doesn\*(Aqt handle %s attributes""" 4.el .IP "\f(CWAttribute handler %s doesn\*(Aqt handle %s attributes\fR" 4.IX Item "Attribute handler %s doesnt handle %s attributes"A handler for attributes of the specified name \fIwas\fR defined, but notfor the specified type of declaration. Typically encountered whe tryingto apply a \f(CW\*(C`VAR\*(C'\fR attribute handler to a subroutine, or a \f(CW\*(C`SCALAR\*(C'\fRattribute handler to some other type of variable..ie n .IP """Declaration of %s attribute in package %s may clash with future reserved word""" 4.el .IP "\f(CWDeclaration of %s attribute in package %s may clash with future reserved word\fR" 4.IX Item "Declaration of %s attribute in package %s may clash with future reserved word"A handler for an attributes with an all-lowercase name was declared. Anattribute with an all-lowercase name might have a meaning to Perlitself some day, even though most don't yet. Use a mixed-case attributename, instead..ie n .IP """Can\*(Aqt have two ATTR specifiers on one subroutine""" 4.el .IP "\f(CWCan\*(Aqt have two ATTR specifiers on one subroutine\fR" 4.IX Item "Cant have two ATTR specifiers on one subroutine"You just can't, okay?Instead, put all the specifications together with commas between themin a single \f(CW\*(C`ATTR(\f(CIspecification\f(CW)\*(C'\fR..ie n .IP """Can\*(Aqt autotie a %s""" 4.el .IP "\f(CWCan\*(Aqt autotie a %s\fR" 4.IX Item "Cant autotie a %s"You can only declare autoties for types \f(CW"SCALAR"\fR, \f(CW"ARRAY"\fR, and\&\f(CW"HASH"\fR. They're the only things (apart from typeglobs \*(-- which arenot declarable) that Perl can tie..ie n .IP """Internal error: %s symbol went missing""" 4.el .IP "\f(CWInternal error: %s symbol went missing\fR" 4.IX Item "Internal error: %s symbol went missing"Something is rotten in the state of the program. An attributedsubroutine ceased to exist between the point it was declared and the pointat which its attribute handler(s) would have been called..ie n .IP """Won\*(Aqt be able to apply END handler""" 4.el .IP "\f(CWWon\*(Aqt be able to apply END handler\fR" 4.IX Item "Wont be able to apply END handler"You have defined an \s-1END\s0 handler for an attribute that is being appliedto a lexical variable.  Since the variable may not be available during \s-1END\s0this won't happen..SH "AUTHOR".IX Header "AUTHOR"Damian Conway (damian@conway.org).SH "BUGS".IX Header "BUGS"There are undoubtedly serious bugs lurking somewhere in code this funky :\-)Bug reports and other feedback are most welcome..SH "COPYRIGHT".IX Header "COPYRIGHT".Vb 3\&         Copyright (c) 2001, Damian Conway. All Rights Reserved.\&       This module is free software. It may be used, redistributed\&           and/or modified under the same terms as Perl itself..Ve

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -