SPUG: Class::Multimethods and superclass

James Moore james at banshee.com
Sun May 22 07:32:51 PDT 2005


Anyone out there using Class::Multimethods?  I'm confused about what to do
with the objects returned by superclass().  In particular, in this example,
something like the lines:

$self = $$self
      if (ref $self) =~ /Class::Multimethods::SUPERCLASS_OF/;

in print_me() seem to be necessary, but this is such a cludge I have trouble
believing that it's what's intended.

It seems as if superclass() doesn't return an object that's suitable for
passing values to a method; the object is only useful for making sure the
right method is called.

It's early on a Sunday morning though and I'm hoping I'm just missing
something obvious.

 - James
---------------------------------

package Base;
use Class::Multimethods;

sub blarg {
  return 3;
}

multimethod print_me => (Base) => sub
  {       
    my ($self) = @_;
    $self = $$self
      if (ref $self) =~ /Class::Multimethods::SUPERCLASS_OF/;
    print "Base stuff " . $self->blarg . "\n";
  };

package Derived;
use Class::Multimethods;
use base 'Base';
# @ISA = qw(Base);

multimethod print_me => (Derived) => sub
  {
    my ($self) = @_;
    my $sc = superclass ($self);
    print_me( superclass($self) ); # START LOOKING IN ANCESTORS
    print "Derived stuff\n";
  };

use Class::ISA;

print_me (bless {}, 'Base');
print_me (bless {}, 'Derived');



More information about the spug-list mailing list