# OK, this is just @ISA 'runtime' reimplementation using: ->{"parent"}
# Creating classes each time is too complicated in Perl.
# Maybe the best would be run-time generation of the classes using: @ISA
-# This way the feature implementations could use SUPER::... instead of: pass(...)
+# This way the feature implementations could use SUPER.pm calls instead of: pass(...)
+# My::Hash::KIND->new($parent,@optional_KIND_arguments);
+# My::Hash->new($parent,"My::Hash::KIND_OUTER",["My::Hash::KIND_INNER",@optional_KIND_INNER_arguments]);
sub new($$;@)
{
my($class,$parent,@classes)=@_;
- unshift @classes,$class if $class ne __PACKAGE__;
- for my $pkg (reverse @classes) {
+ @classes=[$class,@classes] if $class ne __PACKAGE__ || !@classes;
+ for my $item (reverse @classes) {
+ my $pkg=(!ref($item) ? $item : $item->[0]);
+ my @args=@{$item}[1..$#$item] if ref $item;
local $_=$pkg.".pm";
s{::}{/}g;
require $_;
my %hash;
- tie %hash,$pkg,$parent;
+ tie %hash,$pkg,$parent,@args;
$parent=\%hash;
}
return $parent;
{
my($self,$funcname,@funcargs)=@_;
- local $_=ref(tied(%{$self->{"parent"}}))."::".$funcname;
- return if /^(?:Tie::StdHash)?::(?:DESTROY|UNTIE)$/;
- tied(%{$self->{"parent"}})->$_(@funcargs);
+ local $@=undef();
+ my $parent_tied=tied(%{$self->{"parent"}});
+ my $destroy=1 if $funcname eq "DESTROY" || $funcname eq "UNTIE";
+ return if !defined($parent_tied) && $destroy;
+ my $r=eval {
+ $parent_tied->$funcname(@funcargs);
+ };
+ return $r if !$@ || ($destroy && $@=~/^Can't locate object method "$funcname" via package ".*" at /);
+ confess $@;
}
our $AUTOLOAD;