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

📄 perltoot.1

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 1
📖 第 1 页 / 共 5 页
字号:
.\" 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 "PERLTOOT 1".TH PERLTOOT 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"perltoot \- Tom's object\-oriented tutorial for perl.SH "DESCRIPTION".IX Header "DESCRIPTION"Object-oriented programming is a big seller these days.  Some managerswould rather have objects than sliced bread.  Why is that?  What's sospecial about an object?  Just what \fIis\fR an object anyway?.PPAn object is nothing but a way of tucking away complex behaviours intoa neat little easy-to-use bundle.  (This is what professors callabstraction.) Smart people who have nothing to do but sit around forweeks on end figuring out really hard problems make these niftyobjects that even regular people can use. (This is what professors callsoftware reuse.)  Users (well, programmers) can play with this littlebundle all they want, but they aren't to open it up and mess with theinsides.  Just like an expensive piece of hardware, the contract saysthat you void the warranty if you muck with the cover.  So don't do that..PPThe heart of objects is the class, a protected little private namespacefull of data and functions.  A class is a set of related routines thataddresses some problem area.  You can think of it as a user-defined type.The Perl package mechanism, also used for more traditional modules,is used for class modules as well.  Objects \*(L"live\*(R" in a class, meaningthat they belong to some package..PPMore often than not, the class provides the user with little bundles.These bundles are objects.  They know whose class they belong to,and how to behave.  Users ask the class to do something, like \*(L"giveme an object.\*(R"  Or they can ask one of these objects to do something.Asking a class to do something for you is calling a \fIclass method\fR.Asking an object to do something for you is calling an \fIobject method\fR.Asking either a class (usually) or an object (sometimes) to give youback an object is calling a \fIconstructor\fR, which is just akind of method..PPThat's all well and good, but how is an object different from any otherPerl data type?  Just what is an object \fIreally\fR; that is, what's itsfundamental type?  The answer to the first question is easy.  An objectis different from any other data type in Perl in one and only one way:you may dereference it using not merely string or numeric subscriptsas with simple arrays and hashes, but with named subroutine calls.In a word, with \fImethods\fR..PPThe answer to the second question is that it's a reference, and not justany reference, mind you, but one whose referent has been \fIbless\fR()edinto a particular class (read: package).  What kind of reference?  Well,the answer to that one is a bit less concrete.  That's because in Perlthe designer of the class can employ any sort of reference they'd likeas the underlying intrinsic data type.  It could be a scalar, an array,or a hash reference.  It could even be a code reference.  But becauseof its inherent flexibility, an object is usually a hash reference..SH "Creating a Class".IX Header "Creating a Class"Before you create a class, you need to decide what to name it.  That'sbecause the class (package) name governs the name of the file used tohouse it, just as with regular modules.  Then, that class (package)should provide one or more ways to generate objects.  Finally, it shouldprovide mechanisms to allow users of its objects to indirectly manipulatethese objects from a distance..PPFor example, let's make a simple Person class module.  It gets stored inthe file Person.pm.  If it were called a Happy::Person class, it wouldbe stored in the file Happy/Person.pm, and its package would becomeHappy::Person instead of just Person.  (On a personal computer notrunning Unix or Plan 9, but something like Mac \s-1OS\s0 or \s-1VMS\s0, the directoryseparator may be different, but the principle is the same.)  Do not assumeany formal relationship between modules based on their directory names.This is merely a grouping convenience, and has no effect on inheritance,variable accessibility, or anything else..PPFor this module we aren't going to use Exporter, because we'rea well-behaved class module that doesn't export anything at all.In order to manufacture objects, a class needs to have a \fIconstructormethod\fR.  A constructor gives you back not just a regular data type,but a brand-new object in that class.  This magic is taken care of bythe \fIbless()\fR function, whose sole purpose is to enable its referent tobe used as an object.  Remember: being an object really means nothingmore than that methods may now be called against it..PPWhile a constructor may be named anything you'd like, most Perlprogrammers seem to like to call theirs \fInew()\fR.  However, \fInew()\fR is nota reserved word, and a class is under no obligation to supply such.Some programmers have also been known to use a function withthe same name as the class as the constructor..Sh "Object Representation".IX Subsection "Object Representation"By far the most common mechanism used in Perl to represent a Pascalrecord, a C struct, or a \*(C+ class is an anonymous hash.  That's because ahash has an arbitrary number of data fields, each conveniently accessed byan arbitrary name of your own devising..PPIf you were just doing a simplestruct-like emulation, you would likely go about it something like this:.PP.Vb 5\&    $rec = {\&        name  => "Jason",\&        age   => 23,\&        peers => [ "Norbert", "Rhys", "Phineas"],\&    };.Ve.PPIf you felt like it, you could add a bit of visual distinctionby up-casing the hash keys:.PP.Vb 5\&    $rec = {\&        NAME  => "Jason",\&        AGE   => 23,\&        PEERS => [ "Norbert", "Rhys", "Phineas"],\&    };.Ve.PPAnd so you could get at \f(CW\*(C`$rec\->{NAME}\*(C'\fR to find \*(L"Jason\*(R", or\&\f(CW\*(C`@{ $rec\->{PEERS} }\*(C'\fR to get at \*(L"Norbert\*(R", \*(L"Rhys\*(R", and \*(L"Phineas\*(R".(Have you ever noticed how many 23\-year\-old programmers seem tobe named \*(L"Jason\*(R" these days? :\-).PPThis same model is often used for classes, although it is not consideredthe pinnacle of programming propriety for folks from outside theclass to come waltzing into an object, brazenly accessing its datamembers directly.  Generally speaking, an object should be consideredan opaque cookie that you use \fIobject methods\fR to access.  Visually,methods look like you're dereffing a reference using a function nameinstead of brackets or braces..Sh "Class Interface".IX Subsection "Class Interface"Some languages provide a formal syntactic interface to a class's methods,but Perl does not.  It relies on you to read the documentation of eachclass.  If you try to call an undefined method on an object, Perl won'tcomplain, but the program will trigger an exception while it's running.Likewise, if you call a method expecting a prime number as its argumentwith a non-prime one instead, you can't expect the compiler to catch this.(Well, you can expect it all you like, but it's not going to happen.).PPLet's suppose you have a well-educated user of your Person class,someone who has read the docs that explain the prescribedinterface.  Here's how they might use the Person class:.PP.Vb 1\&    use Person;\&\&    $him = Person\->new();\&    $him\->name("Jason");\&    $him\->age(23);\&    $him\->peers( "Norbert", "Rhys", "Phineas" );\&\&    push @All_Recs, $him;  # save object in array for later\&\&    printf "%s is %d years old.\en", $him\->name, $him\->age;\&    print "His peers are: ", join(", ", $him\->peers), "\en";\&\&    printf "Last rec\*(Aqs name is %s\en", $All_Recs[\-1]\->name;.Ve.PPAs you can see, the user of the class doesn't know (or at least, has nobusiness paying attention to the fact) that the object has one particularimplementation or another.  The interface to the class and its objectsis exclusively via methods, and that's all the user of the class shouldever play with..Sh "Constructors and Instance Methods".IX Subsection "Constructors and Instance Methods"Still, \fIsomeone\fR has to know what's in the object.  And that someone isthe class.  It implements methods that the programmer uses to accessthe object.  Here's how to implement the Person class using the standardhash-ref-as-an-object idiom.  We'll make a class method called \fInew()\fR toact as the constructor, and three object methods called \fIname()\fR, \fIage()\fR, and\&\fIpeers()\fR to get at per-object data hidden away in our anonymous hash..PP.Vb 2\&    package Person;\&    use strict;\&\&    ##################################################\&    ## the object constructor (simplistic version)  ##\&    ##################################################\&    sub new {\&        my $self  = {};\&        $self\->{NAME}   = undef;\&        $self\->{AGE}    = undef;\&        $self\->{PEERS}  = [];\&        bless($self);           # but see below\&        return $self;\&    }\&\&    ##############################################\&    ## methods to access per\-object data        ##\&    ##                                          ##\&    ## With args, they set the value.  Without  ##\&    ## any, they only retrieve it/them.         ##\&    ##############################################\&\&    sub name {\&        my $self = shift;\&        if (@_) { $self\->{NAME} = shift }\&        return $self\->{NAME};

⌨️ 快捷键说明

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