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

📄 object::accessor.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
respective input validators. The validators can be anything that\&\f(CW\*(C`Params::Check\*(C'\fR's \f(CW\*(C`allow\*(C'\fR function accepts. Please see its manpagefor details..PPFor example:.PP.Vb 5\&    $object\->mk_accessors( {\&        foo     => qr/^\ed+$/,       # digits only\&        bar     => [0,1],           # booleans\&        zot     => \e&my_sub         # a custom verification sub\&    } );.Ve.PPReturns true on success, false on failure..PPAccessors that are called on an object, that do not exist return\&\f(CW\*(C`undef\*(C'\fR by default, but you can make this a fatal error by setting theglobal variable \f(CW$FATAL\fR to true. See the section on \f(CW\*(C`GLOBALVARIABLES\*(C'\fR for details..PPNote that you can bind the values of attributes to a scope. This allowsyou to \f(CW\*(C`temporarily\*(C'\fR change a value of an attribute, and have it's original value restored up on the end of it's bound variable's scope;.PPFor example, in this snippet of code, the attribute \f(CW\*(C`foo\*(C'\fR will temporarily be set to \f(CW2\fR, until the end of the scope of \f(CW$x\fR, at which point the original value of \f(CW1\fR will be restored..PP.Vb 1\&    my $obj = Object::Accessor\->new;\&    \&    $obj\->mk_accessors(\*(Aqfoo\*(Aq);\&    $obj\->foo( 1 );\&    print $obj\->foo;                # will print 1\&\&    ### bind the scope of the value of attribute \*(Aqfoo\*(Aq\&    ### to the scope of \*(Aq$x\*(Aq \-\- when $x goes out of \&    ### scope, \*(Aqfoo\*(Aq previous value will be restored\&    {   $obj\->foo( 2 => \emy $x );\&        print $obj\->foo, \*(Aq \*(Aq, $x;   # will print \*(Aq2 2\*(Aq\&    }\&    print $obj\->foo;                # will print 1.Ve.PPNote that all accessors are read/write for everyone. See the \f(CW\*(C`TODO\*(C'\fRsection for details..ie n .Sh "@list\fP = \f(CW$self\->ls_accessors;".el .Sh "\f(CW@list\fP = \f(CW$self\fP\->ls_accessors;".IX Subsection "@list = $self->ls_accessors;"Returns a list of accessors that are supported by the current object.The corresponding coderefs can be retrieved by passing this list oneby one to the \f(CW\*(C`can\*(C'\fR method..ie n .Sh "$ref\fP = \f(CW$self\->ls_allow(\s-1KEY\s0)".el .Sh "\f(CW$ref\fP = \f(CW$self\fP\->ls_allow(\s-1KEY\s0)".IX Subsection "$ref = $self->ls_allow(KEY)"Returns the allow handler for the given key, which can be used with\&\f(CW\*(C`Params::Check\*(C'\fR's \f(CW\*(C`allow()\*(C'\fR handler. If there was no allow handlerspecified, an allow handler that always returns true will be returned..ie n .Sh "$clone\fP = \f(CW$self\->mk_clone;".el .Sh "\f(CW$clone\fP = \f(CW$self\fP\->mk_clone;".IX Subsection "$clone = $self->mk_clone;"Makes a clone of the current object, which will have the exact sameaccessors as the current object, but without the data stored in them..ie n .Sh "$bool\fP = \f(CW$self\->mk_flush;".el .Sh "\f(CW$bool\fP = \f(CW$self\fP\->mk_flush;".IX Subsection "$bool = $self->mk_flush;"Flushes all the data from the current object; all accessors will beset back to their default state of \f(CW\*(C`undef\*(C'\fR..PPReturns true on success and false on failure..ie n .Sh "$bool\fP = \f(CW$self\->mk_verify;".el .Sh "\f(CW$bool\fP = \f(CW$self\fP\->mk_verify;".IX Subsection "$bool = $self->mk_verify;"Checks if all values in the current object are in accordance with theirown allow handler. Specifically useful to check if an empty initialisedobject has been filled with values satisfying their own allow criteria..ie n .Sh "$bool\fP = \f(CW$self\->register_callback( sub { ... } );".el .Sh "\f(CW$bool\fP = \f(CW$self\fP\->register_callback( sub { ... } );".IX Subsection "$bool = $self->register_callback( sub { ... } );"This method allows you to register a callback, that is invokedevery time an accessor is called. This allows you to munge inputdata, access external data stores, etc..PPYou are free to return whatever you wish. On a \f(CW\*(C`set\*(C'\fR call, thedata is even stored in the object..PPBelow is an example of the use of a callback..PP.Vb 1\&    $object\->some_method( "some_value" );\&    \&    my $callback = sub {\&        my $self    = shift; # the object\&        my $meth    = shift; # "some_method"\&        my $val     = shift; # ["some_value"]  \&                             # could be undef \-\- check \*(Aqexists\*(Aq;\&                             # if scalar @$val is empty, it was a \*(Aqget\*(Aq\&    \&        # your code here\&\&        return $new_val;     # the value you want to be set/returned\&    }.Ve.PPTo access the values stored in the object, circumventing thecallback structure, you should use the \f(CW\*(C`_\|_\|_get\*(C'\fR and \f(CW\*(C`_\|_\|_set\*(C'\fR methodsdocumented further down..ie n .Sh "$bool\fP = \f(CW$self\->can( \s-1METHOD_NAME\s0 )".el .Sh "\f(CW$bool\fP = \f(CW$self\fP\->can( \s-1METHOD_NAME\s0 )".IX Subsection "$bool = $self->can( METHOD_NAME )"This method overrides \f(CW\*(C`UNIVERAL::can\*(C'\fR in order to provide coderefs toaccessors which are loaded on demand. It will behave just like\&\f(CW\*(C`UNIVERSAL::can\*(C'\fR where it can \*(-- returning a class method if it exists,or a closure pointing to a valid accessor of this particular object..PPYou can use it as follows:.PP.Vb 5\&    $sub = $object\->can(\*(Aqsome_accessor\*(Aq);   # retrieve the coderef\&    $sub\->(\*(Aqfoo\*(Aq);                          # \*(Aqsome_accessor\*(Aq now set\&                                            # to \*(Aqfoo\*(Aq for $object\&    $foo = $sub\->();                        # retrieve the contents\&                                            # of \*(Aqsome_accessor\*(Aq.Ve.PPSee the \f(CW\*(C`SYNOPSIS\*(C'\fR for more examples..ie n .Sh "$val\fP = \f(CW$self\->_\|_\|_get( \s-1METHOD_NAME\s0 );".el .Sh "\f(CW$val\fP = \f(CW$self\fP\->_\|_\|_get( \s-1METHOD_NAME\s0 );".IX Subsection "$val = $self->___get( METHOD_NAME );"Method to directly access the value of the given accessor in theobject. It circumvents all calls to allow checks, callbakcs, etc..PPUse only if you \f(CW\*(C`Know What You Are Doing\*(C'\fR! General usage for this functionality would be in your own custom callbacks..ie n .Sh "$bool\fP = \f(CW$self\->_\|_\|_set( \s-1METHOD_NAME\s0 => \s-1VALUE\s0 );".el .Sh "\f(CW$bool\fP = \f(CW$self\fP\->_\|_\|_set( \s-1METHOD_NAME\s0 => \s-1VALUE\s0 );".IX Subsection "$bool = $self->___set( METHOD_NAME => VALUE );"Method to directly set the value of the given accessor in theobject. It circumvents all calls to allow checks, callbakcs, etc..PPUse only if you \f(CW\*(C`Know What You Are Doing\*(C'\fR! General usage for this functionality would be in your own custom callbacks..SH "LVALUE ACCESSORS".IX Header "LVALUE ACCESSORS"\&\f(CW\*(C`Object::Accessor\*(C'\fR supports \f(CW\*(C`lvalue\*(C'\fR attributes as well. To enablethese, you should create your objects in the designated namespace,\&\f(CW\*(C`Object::Accessor::Lvalue\*(C'\fR. For example:.PP.Vb 3\&    my $obj = Object::Accessor::Lvalue\->new(\*(Aqfoo\*(Aq);\&    $obj\->foo += 1;\&    print $obj\->foo;.Ve.PPwill actually print \f(CW1\fR and work as expected. Since this is anoptional feature, that's not desirable in all cases, we requireyou to explicitly use the \f(CW\*(C`Object::Accessor::Lvalue\*(C'\fR class..PPDoing the same on the standard \f(CW\*(C`Object\*(C'\fR>Accessor> class wouldgenerate the following code & errors:.PP.Vb 2\&    my $obj = Object::Accessor\->new(\*(Aqfoo\*(Aq);\&    $obj\->foo += 1;\&\&    Can\*(Aqt modify non\-lvalue subroutine call.Ve.PPNote that \f(CW\*(C`lvalue\*(C'\fR support on \f(CW\*(C`AUTOLOAD\*(C'\fR routines is a\&\f(CW\*(C`perl 5.8.x\*(C'\fR feature. See perldoc perl58delta for details..Sh "\s-1CAVEATS\s0".IX Subsection "CAVEATS".IP "\(bu" 4Allow handlers.SpDue to the nature of \f(CW\*(C`lvalue subs\*(C'\fR, we never get access to thevalue you are assigning, so we can not check it againt your allowhandler. Allow handlers are therefor unsupported under \f(CW\*(C`lvalue\*(C'\fRconditions..SpSee \f(CW\*(C`perldoc perlsub\*(C'\fR for details..IP "\(bu" 4Callbacks.SpDue to the nature of \f(CW\*(C`lvalue subs\*(C'\fR, we never get access to thevalue you are assigning, so we can not check provide this valueto your callback. Furthermore, we can not distinguish betweena \f(CW\*(C`get\*(C'\fR and a \f(CW\*(C`set\*(C'\fR call. Callbacks are therefor unsupported under \f(CW\*(C`lvalue\*(C'\fR conditions..SpSee \f(CW\*(C`perldoc perlsub\*(C'\fR for details..SH "GLOBAL VARIABLES".IX Header "GLOBAL VARIABLES".ie n .Sh "$Object::Accessor::FATAL".el .Sh "\f(CW$Object::Accessor::FATAL\fP".IX Subsection "$Object::Accessor::FATAL"Set this variable to true to make all attempted access to non-existantaccessors be fatal.This defaults to \f(CW\*(C`false\*(C'\fR..ie n .Sh "$Object::Accessor::DEBUG".el .Sh "\f(CW$Object::Accessor::DEBUG\fP".IX Subsection "$Object::Accessor::DEBUG"Set this variable to enable debugging output.This defaults to \f(CW\*(C`false\*(C'\fR..SH "TODO".IX Header "TODO".Sh "Create read-only accessors".IX Subsection "Create read-only accessors"Currently all accessors are read/write for everyone. Perhaps a futurerelease should make it possible to have read-only accessors as well..SH "CAVEATS".IX Header "CAVEATS"If you use codereferences for your allow handlers, you will not be ableto freeze the data structures using \f(CW\*(C`Storable\*(C'\fR..PPDue to a bug in storable (until at least version 2.15), \f(CW\*(C`qr//\*(C'\fR compiled regexes also don't de-serialize properly. Although this bug has been reported, you should be aware of this issue when serializing your objects..PPYou can track the bug here:.PP.Vb 1\&    http://rt.cpan.org/Ticket/Display.html?id=1827.Ve.SH "AUTHOR".IX Header "AUTHOR"This module byJos Boumans <kane@cpan.org>..SH "COPYRIGHT".IX Header "COPYRIGHT"This module iscopyright (c) 2004\-2005 Jos Boumans <kane@cpan.org>.All rights reserved..PPThis library is free software;you may redistribute and/or modify it under the sameterms as Perl itself..SH "POD ERRORS".IX Header "POD ERRORS"Hey! \fBThe above document had some coding errors, which are explained below:\fR.IP "Around line 700:" 4.IX Item "Around line 700:"You forgot a '=back' before '=head1'

⌨️ 快捷键说明

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