📄 perlbot.1
字号:
.\" 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 "PERLBOT 1".TH PERLBOT 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"perlbot \- Bag'o Object Tricks (the BOT).SH "DESCRIPTION".IX Header "DESCRIPTION"The following collection of tricks and hints is intended to whet curiousappetites about such things as the use of instance variables and themechanics of object and class relationships. The reader is encouraged toconsult relevant textbooks for discussion of Object Oriented definitions andmethodology. This is not intended as a tutorial for object-orientedprogramming or as a comprehensive guide to Perl's object oriented features,nor should it be construed as a style guide. If you're looking for tutorials,be sure to read perlboot, perltoot, and perltooc..PPThe Perl motto still holds: There's more than one way to do it..SH "OO SCALING TIPS".IX Header "OO SCALING TIPS".IP "1." 5Do not attempt to verify the type of \f(CW$self\fR. That'll break if the class isinherited, when the type of \f(CW$self\fR is valid but its package isn't what youexpect. See rule 5..IP "2." 5If an object-oriented (\s-1OO\s0) or indirect-object (\s-1IO\s0) syntax was used, then theobject is probably the correct type and there's no need to become paranoidabout it. Perl isn't a paranoid language anyway. If people subvert the \s-1OO\s0or \s-1IO\s0 syntax then they probably know what they're doing and you should letthem do it. See rule 1..IP "3." 5Use the two-argument form of \fIbless()\fR. Let a subclass use your constructor.See \*(L"\s-1INHERITING\s0 A \s-1CONSTRUCTOR\s0\*(R"..IP "4." 5The subclass is allowed to know things about its immediate superclass, thesuperclass is allowed to know nothing about a subclass..IP "5." 5Don't be trigger happy with inheritance. A \*(L"using\*(R", \*(L"containing\*(R", or\&\*(L"delegation\*(R" relationship (some sort of aggregation, at least) is often moreappropriate. See \*(L"\s-1OBJECT\s0 \s-1RELATIONSHIPS\s0\*(R", \*(L"\s-1USING\s0 \s-1RELATIONSHIP\s0 \s-1WITH\s0 \s-1SDBM\s0\*(R",and \*(L"\s-1DELEGATION\s0\*(R"..IP "6." 5The object is the namespace. Make package globals accessible via theobject. This will remove the guess work about the symbol's home package.See \*(L"\s-1CLASS\s0 \s-1CONTEXT\s0 \s-1AND\s0 \s-1THE\s0 \s-1OBJECT\s0\*(R"..IP "7." 5\&\s-1IO\s0 syntax is certainly less noisy, but it is also prone to ambiguities thatcan cause difficult-to-find bugs. Allow people to use the sure-thing \s-1OO\s0syntax, even if you don't like it..IP "8." 5Do not use function-call syntax on a method. You're going to be bittensomeday. Someone might move that method into a superclass and your codewill be broken. On top of that you're feeding the paranoia in rule 2..IP "9." 5Don't assume you know the home package of a method. You're making itdifficult for someone to override that method. See \*(L"\s-1THINKING\s0 \s-1OF\s0 \s-1CODE\s0 \s-1REUSE\s0\*(R"..SH "INSTANCE VARIABLES".IX Header "INSTANCE VARIABLES"An anonymous array or anonymous hash can be used to hold instancevariables. Named parameters are also demonstrated..PP.Vb 1\& package Foo;\&\& sub new {\& my $type = shift;\& my %params = @_;\& my $self = {};\& $self\->{\*(AqHigh\*(Aq} = $params{\*(AqHigh\*(Aq};\& $self\->{\*(AqLow\*(Aq} = $params{\*(AqLow\*(Aq};\& bless $self, $type;\& }\&\&\& package Bar;\&\& sub new {\& my $type = shift;\& my %params = @_;\& my $self = [];\& $self\->[0] = $params{\*(AqLeft\*(Aq};\& $self\->[1] = $params{\*(AqRight\*(Aq};\& bless $self, $type;\& }\&\& package main;\&\& $a = Foo\->new( \*(AqHigh\*(Aq => 42, \*(AqLow\*(Aq => 11 );\& print "High=$a\->{\*(AqHigh\*(Aq}\en";\& print "Low=$a\->{\*(AqLow\*(Aq}\en";\&\& $b = Bar\->new( \*(AqLeft\*(Aq => 78, \*(AqRight\*(Aq => 40 );\& print "Left=$b\->[0]\en";\& print "Right=$b\->[1]\en";.Ve.SH "SCALAR INSTANCE VARIABLES".IX Header "SCALAR INSTANCE VARIABLES"An anonymous scalar can be used when only one instance variable is needed..PP.Vb 1\& package Foo;\&\& sub new {\& my $type = shift;\& my $self;\& $self = shift;\& bless \e$self, $type;\& }\&\& package main;\&\& $a = Foo\->new( 42 );\& print "a=$$a\en";.Ve.SH "INSTANCE VARIABLE INHERITANCE".IX Header "INSTANCE VARIABLE INHERITANCE"This example demonstrates how one might inherit instance variables from asuperclass for inclusion in the new class. This requires calling thesuperclass's constructor and adding one's own instance variables to the newobject..PP.Vb 1\& package Bar;\&\& sub new {\& my $type = shift;\& my $self = {};\& $self\->{\*(Aqbuz\*(Aq} = 42;\& bless $self, $type;\& }\&\& package Foo;\& @ISA = qw( Bar );\&\& sub new {\& my $type = shift;\& my $self = Bar\->new;\& $self\->{\*(Aqbiz\*(Aq} = 11;\& bless $self, $type;\& }\&\& package main;\&\& $a = Foo\->new;\& print "buz = ", $a\->{\*(Aqbuz\*(Aq}, "\en";\& print "biz = ", $a\->{\*(Aqbiz\*(Aq}, "\en";.Ve.SH "OBJECT RELATIONSHIPS".IX Header "OBJECT RELATIONSHIPS"The following demonstrates how one might implement \*(L"containing\*(R" and \*(L"using\*(R"relationships between objects..PP.Vb 1\& package Bar;\&\& sub new {\& my $type = shift;\& my $self = {};\& $self\->{\*(Aqbuz\*(Aq} = 42;\& bless $self, $type;\& }\&\& package Foo;\&\& sub new {\& my $type = shift;\& my $self = {};\& $self\->{\*(AqBar\*(Aq} = Bar\->new;\& $self\->{\*(Aqbiz\*(Aq} = 11;\& bless $self, $type;\& }\&\& package main;\&\& $a = Foo\->new;\& print "buz = ", $a\->{\*(AqBar\*(Aq}\->{\*(Aqbuz\*(Aq}, "\en";\& print "biz = ", $a\->{\*(Aqbiz\*(Aq}, "\en";.Ve.SH "OVERRIDING SUPERCLASS METHODS".IX Header "OVERRIDING SUPERCLASS METHODS"The following example demonstrates how to override a superclass method andthen call the overridden method. The \fB\s-1SUPER\s0\fR pseudo-class allows theprogrammer to call an overridden superclass method without actually knowingwhere that method is defined..PP.Vb 2\& package Buz;\& sub goo { print "here\*(Aqs the goo\en" }\&\& package Bar; @ISA = qw( Buz );\& sub google { print "google here\en" }\&\& package Baz;\& sub mumble { print "mumbling\en" }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -