From: short <> Date: Sat, 17 Sep 2005 12:02:07 +0000 (+0000) Subject: &new: Extended for passing arguments to the add-on &TIEHASH-es. X-Git-Url: http://git.jankratochvil.net/?p=MyWeb.git;a=commitdiff_plain;h=1c18d205aecccd477103e8c37e07f1a92f20bca6;ds=inline &new: Extended for passing arguments to the add-on &TIEHASH-es. --- diff --git a/Hash.pm b/Hash.pm index 69204e4..280c26b 100644 --- a/Hash.pm +++ b/Hash.pm @@ -29,20 +29,24 @@ use Carp qw(cluck confess); # 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__; + 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;