For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > September 2006 > Tricky subclassing problem: Parent class method uses static value from child class









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Tricky subclassing problem: Parent class method uses static value from child class
don.hosek@gmail.com

2006-09-26, 4:00 am

I want to be able to do something along the lines of:

package A;
@ISA = ('B');
use Class::Std;

my $foo='this';

package C;
@ISA = ('B');
use Class::Std;

my $foo='this';

package B;
use Class::Std;

sub method {
do something with $foo
}

(obviously, there's a bit more to this, but I'm trying to abstract
things as much as possible).

But I can't seem to find anyway to make $bar->method(); see the
appropriate value of $foo depending on whether $bar is an object of
type A or C. Am I going to have to have a method (or AUTOMETHOD) to
copy $foo into the B namespace when method is called? Or is there a
more elegant way of handling this? [As a note, in actuality, I'm
dealing with a %foo rather than a $foo].

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com