From: Dave Mitchell Date: Thu, 1 Jan 2004 22:23:11 +0000 (+0000) Subject: Document the quirks of SUPER, especially the fact that it it X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=029f3b4481eb14b016dea8aa8fb43279a710daa3;p=p5sagit%2Fp5-mst-13.2.git Document the quirks of SUPER, especially the fact that it it relative to the current package and not to the invoking object. p4raw-id: //depot/perl@22036 --- diff --git a/pod/perlboot.pod b/pod/perlboot.pod index 8eaac86..927777d 100644 --- a/pod/perlboot.pod +++ b/pod/perlboot.pod @@ -382,7 +382,8 @@ listed in C<@ISA>) automatically: } So, C means look in the current package's C<@ISA> for -C, invoking the first one found. +C, invoking the first one found. Note that it does I look in +the C<@ISA> of C<$class>. =head2 Where we're at so far... diff --git a/pod/perlbot.pod b/pod/perlbot.pod index dc632ea..4507d4f 100644 --- a/pod/perlbot.pod +++ b/pod/perlbot.pod @@ -243,6 +243,9 @@ where that method is defined. $foo->goo; $foo->google; +Note that C refers to the superclass of the current package +(C), not to the superclass of C<$self>. + =head1 USING RELATIONSHIP WITH SDBM diff --git a/pod/perlobj.pod b/pod/perlobj.pod index 73b67de..16013fc 100644 --- a/pod/perlobj.pod +++ b/pod/perlobj.pod @@ -275,6 +275,16 @@ current class's C<@ISA> list. $self->SUPER::display("Name", @args); } +It is important to note that C refers to the superclass of the +I and not to the superclass 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: diff --git a/pod/perltoot.pod b/pod/perltoot.pod index 03372c7..2497063 100644 --- a/pod/perltoot.pod +++ b/pod/perltoot.pod @@ -940,7 +940,8 @@ comes to the rescue here. This way it starts looking in my class's @ISA. This only makes sense from I a method call, though. Don't try to access anything in SUPER:: from anywhere else, because it doesn't exist outside -an overridden method call. +an overridden method call. Note that C refers to the superclass of +the current package, I to the superclass of C<$self>. Things are getting a bit complicated here. Have we done anything we shouldn't? As before, one way to test whether we're designing