in reply to Objects and Inheritance
Upon further reading, I wasn't specific enough, I suppose.
Perl gives me an error upon trying to create a new BaseClass::Log::Writer object
When I step through the code, I get a call to the Writer.pm module's new() sub with "BaseClass::Log::Writer" as the class. This is good.
I then call $class->SUPER::new which takes me into the Log.pm module's new sub. Here's where things are funky. I assume the class should now be "BaseClass::Log", but it's showing as "BaseClass::Log::Writer" which barfs when I call $class->SUPER::new.
Here are the various constructors.
BaseClass Constructor:
package BaseClass; sub new { my $class = shift @_; my $self = {}; $self = bless $self, $class; # Re-read the config file if it has changed... my $mtime = ( stat(CONFIG_FILE) )[9]; if ($mtime != $config_time) { ($config, $config_time) = &_read_config(CONFIG_FILE); } return $self; }
Log.pm Constructor:
package BaseClass::Log; @ISA = qw( BaseClass ); sub new { my $class = shift; my $self = $class->SUPER::new; my (%opt) = ( @_ ); $self->{opt} = \%opt; # Connect to the database. $self->{dbh} = $self->connect_db('hits') || return undef; return $self; }
Writer.pm Constructor
package BaseClass::Log::Writer; @ISA = qw( BaseClass::Log ); sub new { my $class = shift @_; my $self = $class->SUPER::new; my (%opt) = (@_); # Standard fields for the Log module go in this array. @self::_properties = qw( type_id class_id subclass_id severity process_id text_info program_name module_name unix_pid host_name purge_date ); # We can set up some defaults for process and such. $opt{unix_pid} = $$ unless $opt{unix_pid}; $opt{program_name} = $0 unless $opt{program_name}; $opt{hostname} = $ENV{HOSTNAME} unless $opt{hostname}; $opt{module_name} = caller || $opt{program_name} unless $opt{module_name}; $opt{purge_date} = POSIX::strftime("%Y-%m-%d", localtime(time)) unless $opt{purge_date}; $opt{type_id} = 'unknown' unless $opt{type_id}; $opt{class_id} = 'unknown' unless $opt{class_id}; $opt{subclass_id} = 'unknown' unless $opt{subclass_id}; $opt{severity} = 0 unless $opt{severity}; $self->{opt} = \%opt; return $self; }
I hope this makes it a little clearer.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Ovid) Re(3): Objects and Inheritance
by Ovid (Cardinal) on Nov 21, 2001 at 05:20 UTC | |
by Bobcat (Scribe) on Nov 21, 2001 at 05:32 UTC | |
|
Re: Re: Objects and Inheritance
by runrig (Abbot) on Nov 21, 2001 at 05:21 UTC |