It's useful when you have multiple-inheritance, to say which of your parent classes to start searching.

Ah, of course, that make a lot of sense.

It's also useful when SUPER:: would be wrong... like a flyweight class.

I'm still scratching my head about this one. This is partly because I have not yet fully grokked Class::Prototyped (but I'm getting there :-) ), but partly because for the longest time I thougth that by "wrong" you meant bad OO design (and for the life of me I couldn't, and still can't, think of any scenario in which it would be OK design-wise to use $me->Dad::hello() but at the same time not OK to use $me->SUPER::hello()). Then it finally hit me that (maybe!) by "wrong" you meant "semantically wrong", as when the code in package main contains the expression $me->SUPER::hello() intending to access the hello method of $me's parent class. With "package-less classes" as those created with Class::Prototyped, there would not be any scope in which the SUPER pseudo-class had the desired meaning.

So at least that explains (maybe) why SUPER is particularly problematic with classes/prototypes created with Class::Protoyped. But what I still can't understand is how the fact that Perl allows the $object->ParentClass::method() form can be of any help if such a class wanted to invoke a method in a parent class. For example (adapted from the Class::Prototyped docs):

use strict; use Class::Prototyped ':EZACCESS'; my $Dad = Class::Prototyped->new( hello => sub { print "Hiya from $Dad!\n" } ); my $Me = Class::Prototyped::new( 'parent*' => $Dad hello => sub { # ??? print "I'm just a WILD AND CRAZY GUY!\n"; } );
How can anything having the form $object->ParentClass::method() be used the definition of $Me's hello?

the lowliest monk


In reply to Re^4: Skipping the middle man & the SUPER gotcha by tlm
in thread Skipping the middle man & the SUPER gotcha by tlm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.