M
Matt Garrish
I'm faced with the problem of one module serving up data for 10
different applications, where the only difference is the data being
generated. Without going into the gory details, each year the data
structure (the database) can change for each application and the
applications have no relation to each other.
For this reason, I've set up 10 separate modules each defining the same
set of variables so that my generic class can access the configuration
information without needing to know which application it is dealing
with. Some of the data is the same between applications, so I keep that
in the base class and then the subclasses override the variables that
are specific to each of the children. As I'm sure the above must sound
like gibberish, take for example:
### DataBase.pm
package DataBase;
use Exporter;
@ISA = qw/Exporter/;
@EXPORT = qw/%appInfo %someOtherConfig/;
# this variable will get overriden by the child module
# but declaring it here means I can use it in the
# module and avoid problems with strictures
# not finding the variable before the child require
our %appInfo;
our %someOtherConfig = (test => 1);
### Child1.pm
package DataBase::Child1;
use base 'DataBase';
use Exporter;
@ISA = qw/Exporter/;
@EXPORT = qw/%appInfo/;
our %appInfo = (table1 => 'col1, col2, col3');
### application
use strict;
use warnings;
use DataBase;
my $test = 1;
if ($test == 1) {
require DataBase::Child1;
import DataBase::Child1;
}
print keys %appInfo;
#########
The above will print the correct 'table1' key, but my question is am I
setting myself up for disaster if I actually try and go this route? I'm
not saying it's the most elegant code, but since it's not a true object
that I want but more of a configuration file is there any danger in my
assumption that the require will properly result in the %appInfo being
the child version.
I currently have the data all in one big configuration file but it's
quickly becoming unwieldy and too large for the web application it's
designed to serve (plus causes other limitations I won't go into by
sharing so much of the same data), so I want to isolate and import only
as little data as necessary to get the job done.
Matt
different applications, where the only difference is the data being
generated. Without going into the gory details, each year the data
structure (the database) can change for each application and the
applications have no relation to each other.
For this reason, I've set up 10 separate modules each defining the same
set of variables so that my generic class can access the configuration
information without needing to know which application it is dealing
with. Some of the data is the same between applications, so I keep that
in the base class and then the subclasses override the variables that
are specific to each of the children. As I'm sure the above must sound
like gibberish, take for example:
### DataBase.pm
package DataBase;
use Exporter;
@ISA = qw/Exporter/;
@EXPORT = qw/%appInfo %someOtherConfig/;
# this variable will get overriden by the child module
# but declaring it here means I can use it in the
# module and avoid problems with strictures
# not finding the variable before the child require
our %appInfo;
our %someOtherConfig = (test => 1);
### Child1.pm
package DataBase::Child1;
use base 'DataBase';
use Exporter;
@ISA = qw/Exporter/;
@EXPORT = qw/%appInfo/;
our %appInfo = (table1 => 'col1, col2, col3');
### application
use strict;
use warnings;
use DataBase;
my $test = 1;
if ($test == 1) {
require DataBase::Child1;
import DataBase::Child1;
}
print keys %appInfo;
#########
The above will print the correct 'table1' key, but my question is am I
setting myself up for disaster if I actually try and go this route? I'm
not saying it's the most elegant code, but since it's not a true object
that I want but more of a configuration file is there any danger in my
assumption that the require will properly result in the %appInfo being
the child version.
I currently have the data all in one big configuration file but it's
quickly becoming unwieldy and too large for the web application it's
designed to serve (plus causes other limitations I won't go into by
sharing so much of the same data), so I want to isolate and import only
as little data as necessary to get the job done.
Matt