in reply to Why can't I call SUPER from user code?

Basicaly thats is because your user should never be making such a decision. ;)

On the other hand you have some redundant code in there. put your new decleration in BAR and then the other inherit it. Also if your new class doesn't want to over right the parent class then it can just leave that sub undefined.

#!/usr/bin/perl use strict; package BAR; sub bang { print "BANG!\n"; } sub new { my $class = shift; return bless {}, $class; } package FOO; use base qw( BAR ); sub bang { print "* please be quiet *\n" } package BAZ; use base qw( BAR ); sub bang { my $self = shift; $self->SUPER::bang(); } package BAH; use base qw( BAR ); package main; my $foo1 = FOO->new(); my $foo2 = BAZ->new(); my $foo3 = BAH->new(); $foo1->bang(); $foo2->bang(); $foo3->bang();

For future reference instead of saying "Why won't perl let my user code call SUPER, as in $foo3->SUPER::bang? " tell us what the error was.It will make life much easier.


___________
Eric Hodges

Replies are listed 'Best First'.
Re^2: Why can't I call SUPER from user code?
by Anonymous Monk on Mar 30, 2006 at 23:41 UTC
    Thanks for the code pointers. It was just for illustrative purposes. It seems very un-perl like to keep you from doing this sort of thing if you want to.

      Overriding methods in the parent class lets child classes have the same interface but a different implementation. If you override the bang method, then it is normaly assumed that the changes you made are needed in order for that object to work correctly. I can't think of any case where it would be usefully to override this behaviour (of course that might just be lack of imagination on my part).


      ___________
      Eric Hodges