Commits

Herbert Breunung committed 3ec88c7

moving init commands to the api module

  • Participants
  • Parent commits 95c7b31

Comments (0)

Files changed (3)

lib/Kephra/API.pm

  '$doc'    => { switch => 'document',    class => 'Kephra::Document' },
  '$ed'     => { switch => 'editor',      class => 'Kephra::App::Editor' },
 });
+Kephra::API::Command::init();
+Kephra::Config::init();
 
 Kephra::API::Command::register_switch_var({
 	'$app'    => 'app',
 sub available_plugins {}
 sub unregister_plugin {}
 
-# if you want to know more, read Kephra::Internals.pod
 
 
-1;
+1; # if you want to know more, please read Kephra::Internals.pod
 

lib/Kephra/API/Command.pm

 sub calling_module { ( caller(1) )[0] }
 
 
-# can only be called once, by Kephra::API and before the init
 sub switch_variables {
 	my ($var_def) = shift;
 	my $api = 'Kephra::API';
 	%switchvar = %$var_def;
 }
 
-# register means: to be called before Command::init() - module body execution time
 sub register_switch_var {
 	my $var = shift;
 	return Kephra::Log::error("need at least one var => sub relation (hash)", 1)
 
 sub register {
 	my $cmd = shift;
-	return Kephra::Log::error( '"$cmd" has to be a hash ref', 1) unless ref $cmd eq 'HASH';
-	my $calling_module = (caller)[0];
+	return Kephra::Log::error("cmd def have to be in a hash ref, not $cmd", 1)
+		unless ref $cmd eq 'HASH';
+	my $caller = calling_module();
 	for my $ID (keys %$cmd) {
 		Kephra::Log::warning( 
 			"$cmd already registered to do ". property($ID, 'sub')." by ".
 			property($ID, 'source')  ), next if registered( $ID );
 		#for (qw/sub options state event label help keys icon/){} filter input later
 		$list{$ID}           = $cmd->{$ID};
-		$list{$ID}{'source'} = $calling_module;
+		$list{$ID}{'source'} = $caller;
 		compile($ID) if $done_init;
 	}
 }

lib/Kephra/App.pm

 
 sub OnInit {
 	$_ref = shift;
-	Kephra::Config::init();
-	Kephra::API::Command::init();
 
 	my $win = Kephra::App::Window->new(__PACKAGE__);