summaryrefslogtreecommitdiff
path: root/pod/perlbot.pod
diff options
context:
space:
mode:
authorAndy Dougherty <doughera@lafcol.lafayette.edu>1995-06-05 02:03:44 +0000
committerAndy Dougherty <doughera@lafcol.lafayette.edu>1995-06-05 02:03:44 +0000
commitc296029969658ed2c8d9a223d4b09026463ca970 (patch)
treeaa1524c2a7ae100bfbfcb083cf37a7626aeab87b /pod/perlbot.pod
parent16d20bd98cd29be76029ebf04027a7edd34d817b (diff)
downloadperl-c296029969658ed2c8d9a223d4b09026463ca970.tar.gz
This is my patch patch.1j for perl5.001.
To apply, change to your perl directory and apply with patch -p1 -N < thispatch. After you apply this patch, I would recommend: rm config.sh sh Configure [whatever options you use] make depend make make test Here are the highlights: Linux fixes: Now correctly sets & uses stdio _ptr and _cnt tricks only when feasible (Configure, config_h.SH, config_H, doio.c, sv.c x2p/str.c) #!path-to-perl fixed to use $binexp instead of $bin. This should really be fixed to do the correct perl start-up stuff. Volunteers? (c2ph.SH, h2ph.SH, h2xs.SH, makeaperl.SH, perldoc.SH, pod/pod2*.SH, x2p/find2perl.SH, x2p/s2p.SH) hint updates: hints/apollo.sh, hints/linux.sh, hints/freebsd.sh, hints/sco_3.sh. xsubpp version 1.7. (includes CASE support) pod/perlbot updates. my lib/AutoLoader patch (to use @INC). [ON]DBM_File/Makefile.PL now have a few hint files. Other sundry small things. Patch and enjoy, Andy Dougherty doughera@lafcol.lafayette.edu Dept. of Physics Lafayette College Easton, PA 18042 Here's the file-by-file breakdown of what's included: Configure Checks if File_ptr(fp) and File_cnt(fp) can be assigned to. Fix typo: s/sytem/system/ MANIFEST Include new extension hint files. README Some clarifications, thanks to John Stoeffel. Tell users how to not use dynamic loading. c2ph.SH Use $binexp instead of $bin. config_H Updated to match config_h.SH. config_h.SH Include defines for whether File_ptr(fp) and File_cnt(fp) can be assigned to. doio.c Use defines for whether File_ptr(fp) and File_cnt(fp) can be assigned to. ext/DynaLoader/DynaLoader.pm Improve error messages and a little documentation. ext/NDBM_File/hints/solaris.pl New hint file. ext/ODBM_File/Makefile.PL Removed -ldbm.nfs, since it's now in the sco hint file. ext/ODBM_File/hints/sco.pl ext/ODBM_File/hints/solaris.pl ext/ODBM_File/hints/svr4.pl New hint files. h2ph.SH h2xs.SH Use $binexp instead of $bin. hints/apollo.sh hints/freebsd.sh hints/linux.sh hints/sco_3.sh Updated. lib/AutoLoader.pm Eliminate else clause in sub import. Handle case where @INC contains relative paths. lib/ExtUtils/xsubpp Update to version 1.7. This includes CASE support. lib/I18N/Collate.pm Updated documentation. lib/ftp.pl Look for socket.ph or sys/socket.ph lib/getcwd.pl Use defined(). makeaperl.SH Use $binexp instead of $bin. perl.c fputs("\tUnofficial patchlevel 1j.\n",stdout); perldoc.SH Use $binexp instead of $bin. Turn off debugging messages. pod/perlbot.pod Updated. pod/pod2html.SH pod/pod2latex.SH pod/pod2man.SH Use $binexp instead of $bin. sv.c Use defines for whether File_ptr(fp) and File_cnt(fp) can be assigned to. toke.c Fix spelling of ambiguous. x2p/find2perl.SH x2p/s2p.SH Use $binexp instead of $bin. x2p/str.c Use defines for whether File_ptr(fp) and File_cnt(fp) can be assigned to.
Diffstat (limited to 'pod/perlbot.pod')
-rw-r--r--pod/perlbot.pod152
1 files changed, 119 insertions, 33 deletions
diff --git a/pod/perlbot.pod b/pod/perlbot.pod
index fb94560948..de2207a961 100644
--- a/pod/perlbot.pod
+++ b/pod/perlbot.pod
@@ -1,6 +1,6 @@
=head1 NAME
-perlbot - Bag'o Object Tricks For Perl5 (the BOT)
+perlbot - Bag'o Object Tricks (the BOT)
=head1 INTRODUCTION
@@ -8,11 +8,72 @@ The following collection of tricks and hints is intended to whet curious
appetites about such things as the use of instance variables and the
mechanics of object and class relationships. The reader is encouraged to
consult relevant textbooks for discussion of Object Oriented definitions and
-methodology. This is not intended as a comprehensive guide to Perl5's
-object oriented features, nor should it be construed as a style guide.
+methodology. This is not intended as a tutorial for object-oriented
+programming or as a comprehensive guide to Perl's object oriented features,
+nor should it be construed as a style guide.
The Perl motto still holds: There's more than one way to do it.
+=head1 OO SCALING TIPS
+
+=over 5
+
+=item 1
+
+Do not attempt to verify the type of $self. That'll break if the class is
+inherited, when the type of $self is valid but its package isn't what you
+expect. See rule 5.
+
+=item 2
+
+If an object-oriented (OO) or indirect-object (IO) syntax was used, then the
+object is probably the correct type and there's no need to become paranoid
+about it. Perl isn't a paranoid language anyway. If people subvert the OO
+or IO syntax then they probably know what they're doing and you should let
+them do it. See rule 1.
+
+=item 3
+
+Use the two-argument form of bless(). Let a subclass use your constructor.
+See L<INHERITING A CONSTRUCTOR>.
+
+=item 4
+
+The subclass is allowed to know things about its immediate superclass, the
+superclass is allowed to know nothing about a subclass.
+
+=item 5
+
+Don't be trigger happy with inheritance. A "using", "containing", or
+"delegation" relationship (some sort of aggregation, at least) is often more
+appropriate. See L<OBJECT RELATIONSHIPS>, L<USING RELATIONSHIP WITH SDBM>,
+and L<"DELEGATION">.
+
+=item 6
+
+The object is the namespace. Make package globals accessible via the
+object. This will remove the guess work about the symbol's home package.
+See L<CLASS CONTEXT AND THE OBJECT>.
+
+=item 7
+
+IO syntax is certainly less noisy, but it is also prone to ambiguities which
+can cause difficult-to-find bugs. Allow people to use the sure-thing OO
+syntax, even if you don't like it.
+
+=item 8
+
+Do not use function-call syntax on a method. You're going to be bitten
+someday. Someone might move that method into a superclass and your code
+will be broken. On top of that you're feeding the paranoia in rule 2.
+
+=item 9
+
+Don't assume you know the home package of a method. You're making it
+difficult for someone to override that method. See L<THINKING OF CODE REUSE>.
+
+=back
+
=head1 INSTANCE VARIABLES
An anonymous array or anonymous hash can be used to hold instance
@@ -26,7 +87,7 @@ variables. Named parameters are also demonstrated.
my $self = {};
$self->{'High'} = $params{'High'};
$self->{'Low'} = $params{'Low'};
- bless $self;
+ bless $self, $type;
}
@@ -38,20 +99,19 @@ variables. Named parameters are also demonstrated.
my $self = [];
$self->[0] = $params{'Left'};
$self->[1] = $params{'Right'};
- bless $self;
+ bless $self, $type;
}
package main;
- $a = new Foo ( 'High' => 42, 'Low' => 11 );
+ $a = Foo->new( 'High' => 42, 'Low' => 11 );
print "High=$a->{'High'}\n";
print "Low=$a->{'Low'}\n";
- $b = new Bar ( 'Left' => 78, 'Right' => 40 );
+ $b = Bar->new( 'Left' => 78, 'Right' => 40 );
print "Left=$b->[0]\n";
print "Right=$b->[1]\n";
-
=head1 SCALAR INSTANCE VARIABLES
An anonymous scalar can be used when only one instance variable is needed.
@@ -62,12 +122,12 @@ An anonymous scalar can be used when only one instance variable is needed.
my $type = shift;
my $self;
$self = shift;
- bless \$self;
+ bless \$self, $type;
}
package main;
- $a = new Foo 42;
+ $a = Foo->new( 42 );
print "a=$$a\n";
@@ -81,23 +141,25 @@ object.
package Bar;
sub new {
+ my $type = shift;
my $self = {};
$self->{'buz'} = 42;
- bless $self;
+ bless $self, $type;
}
package Foo;
@ISA = qw( Bar );
sub new {
- my $self = new Bar;
+ my $type = shift;
+ my $self = Bar->new;
$self->{'biz'} = 11;
- bless $self;
+ bless $self, $type;
}
package main;
- $a = new Foo;
+ $a = Foo->new;
print "buz = ", $a->{'buz'}, "\n";
print "biz = ", $a->{'biz'}, "\n";
@@ -111,23 +173,25 @@ relationships between objects.
package Bar;
sub new {
+ my $type = shift;
my $self = {};
$self->{'buz'} = 42;
- bless $self;
+ bless $self, $type;
}
package Foo;
sub new {
+ my $type = shift;
my $self = {};
- $self->{'Bar'} = new Bar ();
+ $self->{'Bar'} = Bar->new;
$self->{'biz'} = 11;
- bless $self;
+ bless $self, $type;
}
package main;
- $a = new Foo;
+ $a = Foo->new;
print "buz = ", $a->{'Bar'}->{'buz'}, "\n";
print "biz = ", $a->{'biz'}, "\n";
@@ -154,7 +218,10 @@ method without actually knowing where that method is defined.
@ISA = qw( Bar Baz );
@Foo::Inherit::ISA = @ISA; # Access to overridden methods.
- sub new { bless [] }
+ sub new {
+ my $type = shift;
+ bless [], $type;
+ }
sub grr { print "grumble\n" }
sub goo {
my $self = shift;
@@ -171,27 +238,28 @@ method without actually knowing where that method is defined.
package main;
- $foo = new Foo;
+ $foo = Foo->new;
$foo->mumble;
$foo->grr;
$foo->goo;
$foo->google;
-=head1 USING RELATIONSHIP WITH SDBM
+=head1 USING RELATIONSHIP WITH SDBM
This example demonstrates an interface for the SDBM class. This creates a
"using" relationship between the SDBM class and the new class Mydbm.
- use SDBM_File;
- use POSIX;
-
package Mydbm;
+ require SDBM_File;
+ require TieHash;
+ @ISA = qw( TieHash );
+
sub TIEHASH {
- my $self = shift;
+ my $type = shift;
my $ref = SDBM_File->new(@_);
- bless {'dbm' => $ref};
+ bless {'dbm' => $ref}, $type;
}
sub FETCH {
my $self = shift;
@@ -209,6 +277,7 @@ This example demonstrates an interface for the SDBM class. This creates a
}
package main;
+ use Fcntl qw( O_RDWR O_CREAT );
tie %foo, Mydbm, "Sdbm", O_RDWR|O_CREAT, 0640;
$foo{'bar'} = 123;
@@ -230,7 +299,10 @@ that it is impossible to override the BAZ() method.
package FOO;
- sub new { bless {} }
+ sub new {
+ my $type = shift;
+ bless {}, $type;
+ }
sub bar {
my $self = shift;
$self->FOO::private::BAZ;
@@ -253,7 +325,10 @@ FOO::private::BAZ().
package FOO;
- sub new { bless {} }
+ sub new {
+ my $type = shift;
+ bless {}, $type;
+ }
sub bar {
my $self = shift;
$self->FOO::private::BAZ;
@@ -267,7 +342,10 @@ FOO::private::BAZ().
package GOOP;
@ISA = qw( FOO );
- sub new { bless {} }
+ sub new {
+ my $type = shift;
+ bless {}, $type;
+ }
sub BAZ {
print "in GOOP::BAZ\n";
@@ -284,7 +362,10 @@ method GOOP::BAZ() to be used in place of FOO::BAZ().
package FOO;
- sub new { bless {} }
+ sub new {
+ my $type = shift;
+ bless {}, $type;
+ }
sub bar {
my $self = shift;
$self->BAZ;
@@ -297,7 +378,10 @@ method GOOP::BAZ() to be used in place of FOO::BAZ().
package GOOP;
@ISA = qw( FOO );
- sub new { bless {} }
+ sub new {
+ my $type = shift;
+ bless {}, $type;
+ }
sub BAZ {
print "in GOOP::BAZ\n";
}
@@ -330,9 +414,10 @@ method where that data is located.
%fizzle = ( 'Password' => 'XYZZY' );
sub new {
+ my $type = shift;
my $self = {};
$self->{'fizzle'} = \%fizzle;
- bless $self;
+ bless $self, $type;
}
sub enter {
@@ -353,9 +438,10 @@ method where that data is located.
%fizzle = ( 'Password' => 'Rumple' );
sub new {
+ my $type = shift;
my $self = Bar->new;
$self->{'fizzle'} = \%fizzle;
- bless $self;
+ bless $self, $type;
}
package main;