sometimes I'd like to treat the classes like objects created in compile time, with their constructors and initializers which can be inherited, modified by traits, etc... What I'm looking for is some support or methodology for such treatment.
Imagine hierarchy of classes (Class::DBI like) where each class keeps the array of columns. The columns are accessible via columns method, and modifyable via add_column. The array of columns is not modified after the class is loaded.
package MyPackage; use base qw(MyPackage::Base); __PACKAGE__->add_column('name'); __PACKAGE__->add_column('address'); 1;
Before the first call of add_column I wish to initialize the columns (with the list of cloned superclass's columns). After the last call of add_column I want to check all supplied columns and eventually add some default ones.
In other words I would probably like to silently perform something like:
my $class_body = sub { package MyPackage; use base qw(MyPackage::Base); sub initialize_class { my ($this) = @_; $this->add_column('name'); $this->add_column('address'); } 1; } __PACKAGE__->build_class($class_body);
where build_class would be inherited from MyPackage::Base.
I know that this particular case could (Class::DBI is the example) be easily solved by sophisticated columns method. Nevertheless I wonder if there is a methodology or design pattern for such class building. I appreciate any clue and apologize If I was not particularly clear about my intention.
Thanks for advice,
RomanIn reply to Treating classes as objects by roman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |