fhem.pl: add CallInstanceFn (Forum #64741)

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@13053 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2017-01-13 16:01:44 +00:00
parent 3bb60eb9f8
commit 5dbb3e2ee6

33
fhem.pl
View File

@ -3304,6 +3304,39 @@ CallFn(@)
}
}
#####################################
# Alternative to CallFn with optional functions in $defs, Forum #64741
sub
CallInstanceFn(@)
{
my $d = shift;
my $n = shift;
if(!$d || !$defs{$d}) {
$d = "<undefined>" if(!defined($d));
Log 0, "Strange call for nonexistent $d: $n";
return undef;
}
if(!$defs{$d}{TYPE}) {
Log 0, "Strange call for typeless $d: $n";
return undef;
}
my $fn = $defs{$d}{$n} ? $defs{$d}{$n} :
($defs{$d}{".$n"} ? $defs{$d}{".$n"} : $modules{$defs{$d}{TYPE}}{$n});
return "" if(!$fn);
if(wantarray) {
no strict "refs";
my @ret = &{$fn}(@_);
use strict "refs";
return @ret;
} else {
no strict "refs";
my $ret = &{$fn}(@_);
use strict "refs";
return $ret;
}
}
#####################################
# Used from perl oneliners inside of scripts
sub