jck000 has asked for the wisdom of the Perl Monks concerning the following question:
How can I subclass 2 separate instances of 2 modules that inherit and use the same base. Similar to a factory class but separate instances for each call. I'm looking at using this approach for a module in mod_perl, fcgi, cgi and pl environments.
I've written out a basic outline of what I'd like to do below.
Thank you in advance for your thoughts, suggestions and help.
Jack
package BasicX; sub new { ... } sub someMethod1 { ... } sub someMethod2 { ... } 1; # --------------------------- package BasicX::AAA1; use BasicX; sub new { my $class = shift; my $args = shift; my $newclass = BasicX->new( { DEBUG => $args->{DEBUG}, SETTTING1 => $args->{SETTING1}, } ); return $newclass; } 1; # --------------------------- package BasicX::BBB1; use BasicX; sub new { my $class = shift; my $args = shift; my $newclass = BasicX->new( { DEBUG => $args->{DEBUG}, SETTTING1 => $args->{SETTING1}, } ); return $newclass; } 1; # ------------------------------- script.pl ---------- #!/usr/bin/perl use BasicX::AAA1; use BasicX::BBB1; my $ObjAAA = BasicX::AAA1->new( { DEBUG => 1, SETTING1 => "this is it" + } ); my $ObjBBB = BasicX::BBB1->new( { SETTING1 => "separate value" } ); $ObjAAA->someMethod(); ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple instances of the same base class
by Riales (Hermit) on Feb 10, 2012 at 22:33 UTC | |
|
Re: Multiple instances of the same base class
by kennethk (Abbot) on Feb 10, 2012 at 22:34 UTC | |
|
Re: Multiple instances of the same base class
by pemungkah (Priest) on Feb 12, 2012 at 06:19 UTC |