X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlobj.pod;h=891ebe37f257111eb1ce52acacea377d4633ff86;hb=7b667b5fb1c41f31aff1e46b9f74e36eb063010e;hp=73b67dee9adaf24810b30468cd43466c9f36d64a;hpb=890a53b979262c647cff6eff22d9cf68bc23d720;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlobj.pod b/pod/perlobj.pod index 73b67de..891ebe3 100644 --- a/pod/perlobj.pod +++ b/pod/perlobj.pod @@ -97,9 +97,11 @@ so that your constructors may be inherited: } Or if you expect people to call not just C<< CLASS->new() >> but also -C<< $obj->new() >>, then use something like this. The initialize() -method used will be of whatever $class we blessed the -object into: +C<< $obj->new() >>, then use something like the following. (Note that using +this to call new() on an instance does not automatically perform any +copying. If you want a shallow or deep copy of an object, you'll have to +specifically allow for that.) The initialize() method used will be of +whatever $class we blessed the object into: sub new { my $this = shift; @@ -275,6 +277,16 @@ current class's C<@ISA> list. $self->SUPER::display("Name", @args); } +It is important to note that C refers to the superclass(es) of the +I and not to the superclass(es) of the object. Also, the +C pseudo-class can only currently be used as a modifier to a method +name, but not in any of the other ways that class names are normally used, +eg: + + something->SUPER::method(...); # OK + SUPER::method(...); # WRONG + SUPER->method(...); # WRONG + Instead of a class name or an object reference, you can also use any expression that returns either of those on the left side of the arrow. So the following statement is valid: @@ -475,9 +487,8 @@ if you don't care to leak. For example, here's a self-referential node such as one might use in a sophisticated tree structure: sub new_node { - my $self = shift; - my $class = ref($self) || $self; - my $node = {}; + my $class = shift; + my $node = {}; $node->{LEFT} = $node->{RIGHT} = $node; $node->{DATA} = [ @_ ]; return bless $node => $class; @@ -525,15 +536,15 @@ two-phased garbage collection: warn "time to die..."; exit; -When run as F, the following output is produced: +When run as F, the following output is produced: - starting program at /tmp/test line 18. - CREATING SCALAR(0x8e5b8) at /tmp/test line 7. - CREATING SCALAR(0x8e57c) at /tmp/test line 7. - leaving block at /tmp/test line 23. - DESTROYING Subtle=SCALAR(0x8e5b8) at /tmp/test line 13. - just exited block at /tmp/test line 26. - time to die... at /tmp/test line 27. + starting program at /foo/test line 18. + CREATING SCALAR(0x8e5b8) at /foo/test line 7. + CREATING SCALAR(0x8e57c) at /foo/test line 7. + leaving block at /foo/test line 23. + DESTROYING Subtle=SCALAR(0x8e5b8) at /foo/test line 13. + just exited block at /foo/test line 26. + time to die... at /foo/test line 27. DESTROYING Subtle=SCALAR(0x8e57c) during global destruction. Notice that "global destruction" bit there? That's the thread