From 5dbb3e2ee6940f5f4fe2219368fd24b7cefbb4fe Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Fri, 13 Jan 2017 16:01:44 +0000 Subject: [PATCH] fhem.pl: add CallInstanceFn (Forum #64741) git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@13053 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem.pl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/fhem.pl b/fhem.pl index 4b7e99553..ae260b55a 100755 --- a/fhem.pl +++ b/fhem.pl @@ -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 = "" 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