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

📄 perltie.1

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 1
📖 第 1 页 / 共 4 页
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings.  \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote.  \*(C+ will.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\.    ds -- \(*W-.    ds PI pi.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch.    ds L" "".    ds R" "".    ds C` "".    ds C' ""'br\}.el\{\.    ds -- \|\(em\|.    ds PI \(*p.    ds L" ``.    ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el       .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD.  Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\.    de IX.    tm Index:\\$1\t\\n%\t"\\$2"...    nr % 0.    rr F.\}.el \{\.    de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear.  Run.  Save yourself.  No user-serviceable parts..    \" fudge factors for nroff and troff.if n \{\.    ds #H 0.    ds #V .8m.    ds #F .3m.    ds #[ \f1.    ds #] \fP.\}.if t \{\.    ds #H ((1u-(\\\\n(.fu%2u))*.13m).    ds #V .6m.    ds #F 0.    ds #[ \&.    ds #] \&.\}.    \" simple accents for nroff and troff.if n \{\.    ds ' \&.    ds ` \&.    ds ^ \&.    ds , \&.    ds ~ ~.    ds /.\}.if t \{\.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u".    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}.    \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E.    \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'.    \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\.    ds : e.    ds 8 ss.    ds o a.    ds d- d\h'-1'\(ga.    ds D- D\h'-1'\(hy.    ds th \o'bp'.    ds Th \o'LP'.    ds ae ae.    ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "PERLTIE 1".TH PERLTIE 1 "2007-12-18" "perl v5.10.0" "Perl Programmers Reference Guide".\" For nroff, turn off justification.  Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"perltie \- how to hide an object class in a simple variable.IX Xref "tie".SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 1\& tie VARIABLE, CLASSNAME, LIST\&\& $object = tied VARIABLE\&\& untie VARIABLE.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION"Prior to release 5.0 of Perl, a programmer could use \fIdbmopen()\fRto connect an on-disk database in the standard Unix \fIdbm\fR\|(3x)format magically to a \f(CW%HASH\fR in their program.  However, their Perl was eitherbuilt with one particular dbm library or another, but not both, andyou couldn't extend this mechanism to other packages or types of variables..PPNow you can..PPThe \fItie()\fR function binds a variable to a class (package) that will providethe implementation for access methods for that variable.  Once this magichas been performed, accessing a tied variable automatically triggersmethod calls in the proper class.  The complexity of the class ishidden behind magic methods calls.  The method names are in \s-1ALL\s0 \s-1CAPS\s0,which is a convention that Perl uses to indicate that they're calledimplicitly rather than explicitly\*(--just like the \s-1\fIBEGIN\s0()\fR and \s-1\fIEND\s0()\fRfunctions..PPIn the \fItie()\fR call, \f(CW\*(C`VARIABLE\*(C'\fR is the name of the variable to beenchanted.  \f(CW\*(C`CLASSNAME\*(C'\fR is the name of a class implementing objects ofthe correct type.  Any additional arguments in the \f(CW\*(C`LIST\*(C'\fR are passed tothe appropriate constructor method for that class\*(--meaning \s-1\fITIESCALAR\s0()\fR,\&\s-1\fITIEARRAY\s0()\fR, \s-1\fITIEHASH\s0()\fR, or \s-1\fITIEHANDLE\s0()\fR.  (Typically these are argumentssuch as might be passed to the \fIdbminit()\fR function of C.) The objectreturned by the \*(L"new\*(R" method is also returned by the \fItie()\fR function,which would be useful if you wanted to access other methods in\&\f(CW\*(C`CLASSNAME\*(C'\fR. (You don't actually have to return a reference to a right\&\*(L"type\*(R" (e.g., \s-1HASH\s0 or \f(CW\*(C`CLASSNAME\*(C'\fR) so long as it's a properly blessedobject.)  You can also retrieve a reference to the underlying objectusing the \fItied()\fR function..PPUnlike \fIdbmopen()\fR, the \fItie()\fR function will not \f(CW\*(C`use\*(C'\fR or \f(CW\*(C`require\*(C'\fR a modulefor you\*(--you need to do that explicitly yourself..Sh "Tying Scalars".IX Xref "scalar, tying".IX Subsection "Tying Scalars"A class implementing a tied scalar should define the following methods:\&\s-1TIESCALAR\s0, \s-1FETCH\s0, \s-1STORE\s0, and possibly \s-1UNTIE\s0 and/or \s-1DESTROY\s0..PPLet's look at each in turn, using as an example a tie class forscalars that allows the user to do something like:.PP.Vb 2\&    tie $his_speed, \*(AqNice\*(Aq, getppid();\&    tie $my_speed,  \*(AqNice\*(Aq, $$;.Ve.PPAnd now whenever either of those variables is accessed, its currentsystem priority is retrieved and returned.  If those variables are set,then the process's priority is changed!.PPWe'll use Jarkko Hietaniemi <\fIjhi@iki.fi\fR>'s BSD::Resource class (notincluded) to access the \s-1PRIO_PROCESS\s0, \s-1PRIO_MIN\s0, and \s-1PRIO_MAX\s0 constantsfrom your system, as well as the \fIgetpriority()\fR and \fIsetpriority()\fR systemcalls.  Here's the preamble of the class..PP.Vb 5\&    package Nice;\&    use Carp;\&    use BSD::Resource;\&    use strict;\&    $Nice::DEBUG = 0 unless defined $Nice::DEBUG;.Ve.IP "\s-1TIESCALAR\s0 classname, \s-1LIST\s0" 4.IX Xref "TIESCALAR".IX Item "TIESCALAR classname, LIST"This is the constructor for the class.  That means it isexpected to return a blessed reference to a new scalar(probably anonymous) that it's creating.  For example:.Sp.Vb 3\&    sub TIESCALAR {\&        my $class = shift;\&        my $pid = shift || $$; # 0 means me\&\&        if ($pid !~ /^\ed+$/) {\&            carp "Nice::Tie::Scalar got non\-numeric pid $pid" if $^W;\&            return undef;\&        }\&\&        unless (kill 0, $pid) { # EPERM or ERSCH, no doubt\&            carp "Nice::Tie::Scalar got bad pid $pid: $!" if $^W;\&            return undef;\&        }\&\&        return bless \e$pid, $class;\&    }.Ve.SpThis tie class has chosen to return an error rather than raising anexception if its constructor should fail.  While this is how \fIdbmopen()\fR works,other classes may well not wish to be so forgiving.  It checks the globalvariable \f(CW$^W\fR to see whether to emit a bit of noise anyway..IP "\s-1FETCH\s0 this" 4.IX Xref "FETCH".IX Item "FETCH this"This method will be triggered every time the tied variable is accessed(read).  It takes no arguments beyond its self reference, which is theobject representing the scalar we're dealing with.  Because in this casewe're using just a \s-1SCALAR\s0 ref for the tied scalar object, a simple $$selfallows the method to get at the real value stored there.  In our examplebelow, that real value is the process \s-1ID\s0 to which we've tied our variable..Sp.Vb 10\&    sub FETCH {\&        my $self = shift;\&        confess "wrong type" unless ref $self;\&        croak "usage error" if @_;\&        my $nicety;\&        local($!) = 0;\&        $nicety = getpriority(PRIO_PROCESS, $$self);\&        if ($!) { croak "getpriority failed: $!" }\&        return $nicety;\&    }.Ve.SpThis time we've decided to blow up (raise an exception) if the renicefails\*(--there's no place for us to return an error otherwise, and it'sprobably the right thing to do..IP "\s-1STORE\s0 this, value" 4.IX Xref "STORE".IX Item "STORE this, value"This method will be triggered every time the tied variable is set(assigned).  Beyond its self reference, it also expects one (and only one)argument\*(--the new value the user is trying to assign. Don't worry aboutreturning a value from \s-1STORE\s0 \*(-- the semantic of assignment returning theassigned value is implemented with \s-1FETCH\s0..Sp.Vb 5\&    sub STORE {\&        my $self = shift;\&        confess "wrong type" unless ref $self;\&        my $new_nicety = shift;\&        croak "usage error" if @_;\&\&        if ($new_nicety < PRIO_MIN) {\&            carp sprintf\&              "WARNING: priority %d less than minimum system priority %d",\&                  $new_nicety, PRIO_MIN if $^W;\&            $new_nicety = PRIO_MIN;\&        }\&\&        if ($new_nicety > PRIO_MAX) {\&            carp sprintf\&              "WARNING: priority %d greater than maximum system priority %d",\&                  $new_nicety, PRIO_MAX if $^W;\&            $new_nicety = PRIO_MAX;\&        }\&\&        unless (defined setpriority(PRIO_PROCESS, $$self, $new_nicety)) {\&            confess "setpriority failed: $!";\&        }\&    }.Ve.IP "\s-1UNTIE\s0 this" 4.IX Xref "UNTIE".IX Item "UNTIE this"This method will be triggered when the \f(CW\*(C`untie\*(C'\fR occurs. This can be usefulif the class needs to know when no further calls will be made. (Except \s-1DESTROY\s0of course.) See "The \f(CW\*(C`untie\*(C'\fR Gotcha" below for more details..IP "\s-1DESTROY\s0 this" 4.IX Xref "DESTROY".IX Item "DESTROY this"This method will be triggered when the tied variable needs to be destructed.As with other object classes, such a method is seldom necessary, because Perldeallocates its moribund object's memory for you automatically\*(--this isn't\&\*(C+, you know.  We'll use a \s-1DESTROY\s0 method here for debugging purposes only..Sp.Vb 5\&    sub DESTROY {\&        my $self = shift;\&        confess "wrong type" unless ref $self;\&        carp "[ Nice::DESTROY pid $$self ]" if $Nice::DEBUG;\&    }.Ve.PPThat's about all there is to it.  Actually, it's more than all thereis to it, because we've done a few nice things here for the sakeof completeness, robustness, and general aesthetics.  Simpler\&\s-1TIESCALAR\s0 classes are certainly possible..Sh "Tying Arrays".IX Xref "array, tying".IX Subsection "Tying Arrays"A class implementing a tied ordinary array should define the followingmethods: \s-1TIEARRAY\s0, \s-1FETCH\s0, \s-1STORE\s0, \s-1FETCHSIZE\s0, \s-1STORESIZE\s0 and perhaps \s-1UNTIE\s0 and/or \s-1DESTROY\s0..PP\&\s-1FETCHSIZE\s0 and \s-1STORESIZE\s0 are used to provide \f(CW$#array\fR andequivalent \f(CW\*(C`scalar(@array)\*(C'\fR access..PPThe methods \s-1POP\s0, \s-1PUSH\s0, \s-1SHIFT\s0, \s-1UNSHIFT\s0, \s-1SPLICE\s0, \s-1DELETE\s0, and \s-1EXISTS\s0 arerequired if the perl operator with the corresponding (but lowercase) name

⌨️ 快捷键说明

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