llancet has asked for the wisdom of the Perl Monks concerning the following question:
I want to recursively access class variable in a series of classes, like this:
use strict; package Base; our %types = qw/BASE_TYPE Some::Class/; sub get_type {} package Foo; our @ISA = qw/Base/; our %types = qw/FOO_TYPE Another::Class/; package Bar; our @ISA = qw/Base/; our %types = qw/BAR_TYPE Yet::Another::Class/; # what I want: # get: BASE_TYPE => Some::Class, # FOO_TYPE => Another::Class my %foo_type = Foo->get_type(); # get: BASE_TYPE => Some::Class, # BAR_TYPE => Yet::Another::Class my %bar_type = Bar->get_type();
What I actually want is to simulate the sugar in actionscript's EventDispatcher, which can register type string with classes of event object, and derived dispatcher own all registered things from its parents recursively.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to implement such kind of magic?
by BrowserUk (Patriarch) on Dec 02, 2009 at 10:02 UTC | |
|
Re: How to implement such kind of magic?
by moritz (Cardinal) on Dec 02, 2009 at 10:05 UTC | |
by llancet (Friar) on Dec 03, 2009 at 00:52 UTC |