Hello all Monks

I've been banging my head for a few hours now and I really need some input from others..

For this example, say I have 3 classes.

CLASS_A

CLASS_B

CLASS_C

I want the inheritance to look like this.

CLASS_C ISA CLASS_B ISA CLASS_A

So that if I want to access a method in CLASS_A I want to be able to do.

my $instanceC = CLASS_C->new(); $instanceC->method_from_class_A();

So,, this is where i'm stuck..

I start from the bottom...

Code for CLASS_C

package CLASS_C; use CLASS_B; @ISA = ('CLASS_B'); use strict; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; $self->{attribut} = 1; $self = $class->SUPER::new(self => $self); return $self; } 1;

Code for CLASS_B

package CLASS_B; use CLASS_A; @ISA = ('CLASS_A'); use strict; sub new { my $proto = shift; my (%params) = @_; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(); foreach my $attr (keys %{$params{'self'}}) { $self->{$attr} = $params{'self'}->{$attr}; } return $self; } 1;

Code for CLASS_A

package CLASS_A; use strict; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; bless($self,$class); return $self; } 1;

What I know:

Everything fails into a endless loop because of the call to SUPER::new inside CLASS_B definition calls itself... But how should I write it?

Regards

Joakim

UPDATE: I had a call inside CLASS_B::new which called a 'CLASS_C::new' which in turn called CLASS_B::new again .. forever..

Apperently I were to tired yesterday when trying this..

But I guess it's not a waste, hopefully this post will help someone in the future =)


In reply to Inheritance - parent of parent (solved) by jockel

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.