2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

fhem.pl: add CallInstanceFn (Forum #64741)

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

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