BMaximus has asked for the wisdom of the Perl Monks concerning the following question:
As you can see. There isn't much to the derived package. All the methods are inherited. However the variables $table $primarykey %dates and %enums are all defined and initialized here and need to be available to BaseData. Here's how its done now.# to use it you need to create a package named Tables package Tables; use strict qw(var subs); use vars qw(@ISA $table %dates %enums $primarykey); # after this you put the tables here like so package <TABLE NAME IN ALL CAPS>; @ISA = qw(BaseData); $table = "<TABLE NAME IN ALL CAPS>"; $primarykey = "<PRIMARY KEY>"; %dates = (); # list fields with dates here %enums = (); # list fields of type enum here
Any better way of doing the above formentioned so as to let strict do its job in totality or have it not be so hackish?# I'll use the insert sub as an example sub insert { my $class = shift; my ($table,$seq_query,$primary_key); # grab the variable defined from the derived class # this is hacky $table = ${$class . "::table"}; $primary = ${$class . "::primarykey"};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl OOP variables
by chromatic (Archbishop) on May 31, 2001 at 09:42 UTC | |
by BMaximus (Chaplain) on May 31, 2001 at 09:53 UTC | |
by Brovnik (Hermit) on May 31, 2001 at 10:24 UTC |