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.


In reply to Re: Objects and Inheritance by Bobcat
in thread Objects and Inheritance by Bobcat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.