473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Inheriting classes

I have 3 simple classes:

clControlMaker that inherits from clFormMaker:
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2.  
  3. use clFormMaker;
  4. package clFormMaker::clControlMaker;
  5.  
  6. our @ISA = qw(clFormMaker);
  7.  
  8. sub new 
  9. {
  10.     #constructor
  11.     my ($class_name) = @_;
  12.     my ($self) = clFormMaker->new(@_);
  13.     bless ($self, $class_name);
  14.  
  15.     return $self;
  16. }
  17.  
clFormMaker that inherits from clValidate:
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use clValidate;
  3.  
  4. package clValidate::clFormMaker;
  5.  
  6. our @ISA = qw(clValidate);
  7.  
  8. sub new 
  9. {
  10.     #constructor
  11.     my ($class_name, $full_class_name, $name, $action, $method, $enctype, $ref) = @_;
  12.     my ($self) = clValidate->new(@_);    #THIS CAUSES PROBLEMS
  13.     bless ($self, $class_name);
  14.     .
  15.     .
  16.     .
  17.     return $self;
  18. }
  19.  
and finally clValidate:
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2.  
  3. package clValidate;
  4.  
  5. sub new 
  6. {
  7.     #constructor
  8.     my ($class_name) = @_;
  9.     my ($self) = {};
  10.     bless ($self, $class_name);
  11.  
  12.     #props
  13.  
  14.     return $self;
  15. }
  16.  
Implementing it:
Expand|Select|Wrap|Line Numbers
  1. my $control = clFormMaker::clControlMaker->new('formname', 'polymorphism.pl', 'POST', 
  2.                                                 'application/x-www-form-urlencoded', $ref); 
  3. $control->set('_issticky', 1);
  4. $control->makeform();
  5. print $control->maketextbox('text1', 'width: 200px;', 'number');
  6.  
I can call methods in clFormMaker with a clControlMaker object (eg $control->makeform is a clFormMaker method) without a problem. What I want to do is to implement a hierarchy. ie. clControlMaker inherits from clFormMaker which in turn inherits from clValidate.

The problem I'm having is that it doesn't work - when I use the same code to make clFormMaker inherit from clValidate as clControlMaker inherits from clFormMaker I get an error -
"Can't locate method 'new' via package clFormMaker".

I think I am on the right lines but as one class inherits another class that itself inherits, there's something I'm missing.

Phew. Hope that's clear enough. It's a bit frustrating to say the least. This is all a lot easier in php!

Cheers
Richard
Aug 30 '07 #1
1 1239
miller
1,089 Expert 1GB
I do not know if this is the source of your problem. However, the package declaration should always be the first line in your module. You currently have your use statements included above the package statement, and this means that you're not actually using those modules in the stated package.

My habit is to first include the package statement, then all use module statements, and finally use strict (almost as a queue to indicate the end of use statements).

See if that helps your problem.

- Miller
Sep 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: thechaosengine | last post by:
Hi all, I wanted to put some common security functions into a class that inherits from the Page class and then use the new class as the basis for all my pages. Unfortunately, if I try and...
29
by: shaun roe | last post by:
I want something which is very like a bitset<64> but with a couple of extra functions: set/get the two 32 bit words, and conversion to unsigned long long. I can do this easily by inheriting from...
1
by: john diss | last post by:
hello there everyone.. I have created a class called "ProcessLog" inheriting from XmlDocument and two classes ("UploadedItem", "ProcessError") inheriting from XmlElement. I then have two...
2
by: Peter Bates | last post by:
Hi, I'm just getting used to XSDObjectGen and i have the following question. Can i use a class inherited from a class generated by XSDObjectGen with XmlSerialize? Specifically, I have many...
11
by: Noah Coad [MVP .NET/C#] | last post by:
How do you make a member of a class mandatory to override with a _new_ definition? For example, when inheriting from System.Collections.CollectionBase, you are required to implement certain...
6
by: Russell Mangel | last post by:
Jeffery Richter makes the following statement in two books, the first was written in 2004, the latter in 2002. "You should not define new exception classes derived from ApplicationException; use...
24
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public...
7
by: Amu | last post by:
Hi i am stuck up in a part of project where i have to inherit the VC++ template classes into C#.net. Please provide me the solution for this .
5
by: jc | last post by:
RE: Two Classes with the same Data Structure.. saving code? Inheriting a structure? I have two classes. One in Inherits System.Collections.CollectionBase, the other does not, but they both have...
4
by: AalaarDB | last post by:
struct base { int x, y, z; base() {x = 0; y = 0; z = 0;}; base(int x1, int y1, int z1) {x = x1; y = y1; z = z1;}; }; struct intermediate1 : public virtual base {}; struct intermediate2 :...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.