Thank you!
I tried the SUPER->_init() and that took care of it. However, I donn't
want to force an inherited class to have to know how the parent's new()
works, so I tried this as well (and it worked) - I have the new() call
it's own _init explicitly:
# the new() from Logon.pm
sub new {
my $that = shift;
my $class = ref($that) || $that;
my $self = $class->SUPER::new();
$self->Logon::_init();
return $self;
}
# the new() from DBLogon.pm
sub new {
my $that = shift;
my $class = ref($that) || $that;
my $self = $class->SUPER::new();
$self->DBLogon::_init();
return $self;
}
Thanks again, I've been fighting this for quite a while.
-----Original Message-----
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 31, 2005 7:18 PM
To: [EMAIL PROTECTED]
Cc: [email protected]
Subject: Re: Attempting OO with Perl - New() method in subclass not
working
On Mar 31, [EMAIL PROTECTED] said:
> When I try to assign values to the DBLogon object's attributes, I get
> the following error: "Can't access 'USERID' field in object of class
> DBLogon at testdblogon.pl line 7". What am I missing?
The problem is that Logon's new() method is calling LogonDB's _init()
method. To get around that, you'll have to do:
package DBLogon;
use Logon;
@ISA = qw (Logon);
use Carp;
sub new {
my $that = shift;
my $class = ref($that) || $that;
my $self = $class->SUPER::new();
$self->SUPER::_init();
return $self;
}
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>