in reply to can('SUPER::defaults')

The problem is, when I run 'test.pl', I get this:
$ ./test.pl score: 0 vx: -1 symbol: _
And this is a problem why? What were you expecting? :-) Perhaps you wanted to see this:
shown: 1 score: 0 x: 0 vx: -1 y: 0 vy: 0 symbol: _
If it is then I can explain whats going on. As the Anonymous Monk stated SUPER has special meaning inside the class it is used. It is irrelevant what the actual class of the object it is being called against (yes this was an implication that suprised me a little). I dont really see why you are attempting to merge the hashes in init() and not in defaults(). Anyway here is the code I have (minor mods to your stuff, you'll need to uncomment the use() clauses if you dont put it all into one file like I did.

#!/usr/local/bin/perl package Object; use strict; sub new { my ($proto, %args) = @_; my $class = ref $proto || $proto; my $self = bless {}, $class; $self->init(\%args); return $self; } sub init { my ($self, $args) = @_; my $defaults=$self->defaults; if (ref($defaults)) { # This is technically Ok because you are getting # defualts from yourself and accordingly the key=>values # should be correct @{$self}{keys %$defaults}=@{$defaults}{keys %$defaults}; } # If %args are given to new(), use those instead # Unfortunately this is technically bad practice, as the # key=>values will not be coming from yourself (in an abstract sen +se) # accordingly you really should implement code to determine if # the passed keys are in the set of allowed keys. # one way to do this is to make method calls for all legal attribu +tes # and then use the keyname as the methodname. If the arg is not le +gal # perl will throw a runtime error that the method is not found # leaving it as is is asking for hard to identify bugs. # something like this might be in order: # $self->$_($args->{$_}) foreach keys %$args; @{$self}{keys %$args}=@{$args}{keys %$args}; return $self; } 1; package Mover; #use Object; our @ISA = qw(Object); use strict; sub defaults { my $self=shift; my $defaults = { 'symbol' => '?', # override this in subclasses 'x' => 0, # x-coordinate 'y' => 0, # y-coordinate 'vx' => 0, # velocity in x-direction 'vy' => 0, # velocity in y-direction 'shown' => 1, # still alive? } } 1; package Player; #use Mover; use strict; our @ISA = qw(Mover); sub defaults { my $self=shift; my $defaults =$self->SUPER::defaults(); @{$defaults}{'symbol','score'}=('_',0); return $defaults; } 1; use strict; use warnings; #use Player; my $player = Player->new('vx' => -1); for (keys %$player) { print "$_: ", $player->{$_}, $/; } 1;
A few additional points. If you post this type of thing again please post it int the order I have given. Base class first, with the heirarchy going down (remember a class heirarchy is a tree, and computer geeks draw trees upside down, with the root at the top :-). I also made a point about error checking, for more info please review the posts about this subject in the thread passing subroutine arguments directly into a hash especially the comments inRe: passing subroutine arguments directly into a hash and Re (tilly) 2: passing subroutine arguments directly into a hash. If you have more questions on the subject no doubt Tilly knows of a few more posts on the subject. :-)

HTH

Yves
--
You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)