package _Inheritable; use strict; use warnings; BEGIN { use Exporter; our ( $VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS ); $VERSION = sprintf "%d.%03d", q$Revision: 1.3 $ =~ /(\d+)/g; @ISA = qw( Exporter ); @EXPORT = qw(); %EXPORT_TAGS = (); #eg: TAG => [ qw!name1 name2! ]; @EXPORT_OK = qw(); } ## end BEGIN ######################################################################### use Class::MethodMaker 1.12; our @DEFAULT_ARGS = (); use Class::MethodMaker new_with_init => 'new', new_hash_init => 'hash_init', get_set => [qw/ -java -static InitDebug /]; ######################################################################### { my %cache; my %defaultCache; sub init { my $self = shift; my $class = ref($self) || $self; my $package = __PACKAGE__; return $self if $self->{__init}{$package}++; $defaultCache{$class} = $self->_getDefaultArgs unless $defaultCache{$class}; $self->hash_init( @{$defaultCache{$class}}, @_ ); $cache{$class} = [grep { defined *{$_ . "::_init"} } reverse( $class, $self->getParents )] unless exists $cache{$class}; no strict 'refs'; for ( @{$cache{$class}} ) { print "_Init($_)\n" if $self->getInitDebug; &{$_ . "::_init"}($self); } return $self; } ## end sub init } { sub _getParents { my $self = shift; my $class = ref($self) || $self; no strict 'refs'; my @parents = @{$class . "::ISA"}; my @acc; push @acc, @parents; for (@parents) { push @acc, _getParents($_); } return @acc; } ## end sub _getParents } { my %cache; sub getParents { my $self = shift; my $class = ref($self) || $self; my %seen; $cache{$class} = [grep { !$seen{$_}++ } _getParents($class)] unless exists $cache{$class}; return @{$cache{$class}}; } ## end sub getParents } { my %cache; sub _getDefaultArgs { my $self = shift; my $class = ref($self) || $self; return @{$cache{$class}} if exists $cache{$class}; my @args; no strict 'refs'; for ( $class, $self->getParents ) { next if /^Exporter$/; push @args, @{$_ . "::DEFAULT_ARGS"}; } $cache{$class} = \@args; return \@args; } ## end sub _getDefaultArgs } 1;