Source

Kephra / lib / Kephra / API / Command.pm

Diff from to

File lib/Kephra/API/Command.pm

 use warnings;
 use Kephra::Log;
 
-package Kephra::API::Command;                             # callable by the user
-
+package Kephra::API::Command;                             # callable by the user (UI)
 my %list;     # by ID
 #my %keyproxy;# by keycode
 my %switchvar; #switchvar vor cmd definitions
-my $done_init = 0;
 
 
 sub      _raw_list { \%list }
 	my $api = 'Kephra::API';
 	my $caller = calling_module();
 	return Kephra::Log::error("only callable by $api", 1) if $caller ne $api;
-	return Kephra::Log::error("has to be called before init", 1)
-		if $done_init and not keys %switchvar;
 	#return Kephra::Log::error("call me just once", 1) if keys %switchvar;
 	return Kephra::Log::error("need a hashref", 1) unless ref $var_def eq 'HASH';
 	for my $var (keys %$var_def){
 		#delete $var_def->{$var} unless package_exists ( $var_def->{$var}{'class'} ); # class could be loaded later
 	}
 	%switchvar = %$var_def;
+	compile( keys %list );
 }
 
 sub register {
 		#for (qw/sub options state event label help keys icon/){} filter input later
 		$list{$ID}           = $cmd->{$ID};
 		$list{$ID}{'source'} = $caller;
-		compile($ID) if $done_init;
+		compile($ID) if %switchvar; #dont make sense without defined switch var
 	}
 }
 
-sub init {
-	compile( keys %list );
-	$done_init = 1;
-}
 
 sub compile {
 	for my $cmd_ID (@_) {