in reply to Inheritance automation help
The passing of test to each one holds the class, it gets mashed together, altered slightly depending on what the Extend class is doing and passed back to $test with extra methods attached and altered class variables. The end result is that I needed to append classes to each other. So at any time I can call my base class and have new methods that were not there before, but were added because of calling its constructor named plugin that does a "cloneish" concept. Feel free to let me know if I'm off my rocker on doing something like this! Or there is a GOTCHA that I'm not thinking of that isn't obvious like accidental overwriting of methods and such. Also here is an example of what the Extend1 plugin constructor would look like in the Extend1 Package:use Top; my $test = new Top (Foo=>'Start Foo'); use Top::Extend1; $test = plugin Top::Extend1 ($test, %settingsScopedToExtend1); use Top::Extend2; $test = plugin Top::Extend2 ($test, %settingsScopedToExtend2);
sub plugin { my ($class, $other, %params) = @_; # # bless my new combined class # $other = bless $other, $class; # # set defaults scoped to Extend1 # $other->{"Extend1"}->{"someSetting"} = 'its value'; # # overwrite defaults # @{$other->{"Extend1"}}{keys %params} = values %params; # # update any $other data # $other->{'Foo'} .= ' Appended to it '; # # pass back our extended class # return $other; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Inheritance automation help
by GrandFather (Saint) on Apr 05, 2012 at 21:16 UTC | |
by natelewis (Novice) on Apr 17, 2012 at 19:14 UTC | |
by chromatic (Archbishop) on Apr 17, 2012 at 20:40 UTC | |
by natelewis (Novice) on Apr 11, 2012 at 22:41 UTC |