• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

Object Inheritance in 5.003


Hello, does anyone know how to get object inheritence working under 5.003 version of Perl?

Normally, you would do:

package My::Package;
our @ISA = qw(My::Parent);

But 5.003 doesn't support "our" as far as I can see ('use of "our" is deprecated' error).

So I tried:

package My::Package;
use base qw(My::Parent);

And got the same error.

So I tried:

use vars qw(@ISA);
package My::Package;
@ISA = use base qw(My::Parent);

But it doesn't look in My::Parent for any methods not present in My::Package.

Any ideas?
0
muff
Asked:
muff
  • 4
  • 2
  • 2
  • +1
1 Solution
 
rj2Commented:
Try to install newer version of Perl?
0
 
muffAuthor Commented:

I don't see how installing a newer version of Perl will help me get inheritance working under 5.003.

0
 
rj2Commented:
Why do you need to use 5.003?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
SapaCommented:
right syntax is:

package My::Package;
use vars qw(@ISA);
@ISA = qw(My::Parent);

or:

package My::Package;
@My::Package::ISA = qw(My::Parent);


--
Andrey
0
 
jmcgOwnerCommented:
The way we did this before we had "our" was simply

package My::Package;
@ISA = qw(My::Parent);
 .
 .
 .


Somewhere, on one of my machines, I think I have a Perl as old as 5.003 that I can try things on if this doesn't work for you.
0
 
muffAuthor Commented:


Thanks Sapa, I'll give it a go.  You think this will work with 5.003 ok?

rj2...  I'm not sure this is particularly on topic, but I'll humor you ;)

Not everyone has complete control over the version of Perl they are running under.  I am one of those people.  My dev system has 5.6 on it, but production is hosted by another company and has 5.003.

I have two options: Get my stuff compatible with 5.003 so I can run it, or to find a host that runs at 5.6 (or host production myself).  I am exploring both options, and my question is me exploring option 1: to see if I can compatibalise my stuff with 5.003 without doing too much damage.

Hope this satisfies your curiosity...

muff
0
 
muffAuthor Commented:

Darn.  Actually Sapa,

use vars qw(@ISA);
package My::Package;
@ISA = use base qw(My::Parent);

is nonsense.  It wasn't what I tried at all.  This is my syntax:

use vars qw(@ISA);
package My::Package;
@ISA = qw(My::Parent);

This matches what you said, and also jmcg, if you take into account I am using strict, so I have to have the @ISA var defined somehow.  

But I guess we are all saying that 5.003 does understand @ISA, and will search the packages it finds in it for unknown methods?

Thanks all

muff
0
 
jmcgOwnerCommented:
Putting the vars statement before the package statement creates @ISA in the wrong namespace, doesn't it? It's not that there is a global @ISA that all the packages use together -- there's a separate @ISA in each namespace. Sapa's fully qualified naming should have worked for you, even if you are using strict.
0
 
muffAuthor Commented:

Heh, yeah, of course it does.  This was another typo on my part.

This all only seems to work if you "use" the inheritable package as well as doing the @ISA thing.

Does that make sense?
0
 
SapaCommented:
> This all only seems to work if you "use" the inheritable package as well as doing the @ISA thing.

Sure. Inheritable class should be loaded. @ISA contains package names, but interpreter does not know how to load it (although often class names and module names are the same, you can put more than one package into one module file...).

--
Andrey
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now