File Coverage

lib/Kephra/Config/Interface.pm
Criterion Covered Total %
statement 6 57 10.5
branch 0 24 0.0
condition 0 14 0.0
subroutine 2 8 25.0
pod 0 3 0.0
total 8 106 7.5


line stmt bran cond sub pod time code
1             package Kephra::Config::Interface;
2             our $VERSION = '0.08';
3            
4 1     1   864 use strict;
  1         2  
  1         27  
5 1     1   4 use warnings;
  1         2  
  1         682  
6            
7             # handling config files under config/interface
8            
9 0     0     sub _config { Kephra::API::settings()->{app} }
10 0     0     sub _sub_dir { _config()->{app_data_sub_dir} }
11 0     0     sub _cache_sub_dir { File::Spec->catdir(_sub_dir(), _config()->{cache}{sub_dir})}
12            
13             sub load {
14 0     0 0   Kephra::CommandList::clear();
15 0           Kephra::Config::Localisation::refresh_index();
16 0           my $use_cache = _config()->{cache}{use}; # config allow to use the cache
17 0           my $load_cache = 0; # cache is successful loaded
18 0           my (%file,%old_index,%new_index);
19 0 0 0       if ($use_cache and 0) { # supend using cache
20 0           my $read = \&Kephra::Config::File::load;
21 0           my $path = \&Kephra::Config::filepath;
22 0           my $get_age = \&Kephra::File::IO::get_age;
23 0           my $cache_dir = _cache_sub_dir();
24 0           $file{index} = &$path( $cache_dir, 'index_cmd.yml');
25 0           $file{cmd_cache} = &$path( $cache_dir, 'cmd_main.yml' );
26 0           $file{l18n_cache}= &$path( $cache_dir, 'l18n_main.yml');
27 0           $file{cmd} = Kephra::CommandList::file();
28 0           $file{l18n} = Kephra::Config::Localisation::file();
29 0 0         %old_index = %{ &$read($file{index}) } if -e $file{index};
  0            
30 0           %new_index = (
31             'l18n' => {'file' => $file{cmd}, 'age' => &$get_age($file{cmd})},
32             'cmd' => {'file' => $file{l18n}, 'age' => &$get_age($file{l18n})},
33             );
34 0 0 0       if (-e $file{cmd} and -e $file{l18n}) {
35 0           YAML::Tiny::DumpFile( $file{index}, \%new_index );
36 0 0 0       if (-e $file{cmd_cache} and -e $file{l18n_cache} and
      0        
37             scalar keys %new_index == scalar keys %old_index) {
38 0           $load_cache = 1;
39 0           for (keys %new_index) {
40 0 0 0       $load_cache = 0
41             unless $new_index{$_}{age} == $old_index{$_}{age}
42             and $new_index{$_}{file}eq $old_index{$_}{file};
43             }
44             }
45 0 0         if ($load_cache) {
46 0           Kephra::CommandList::data( &$read( $file{cmd_cache} ) );
47 0           Kephra::Config::Localisation::_set_strings
48             ( &$read( $file{l18n_cache} ) );
49 0           Kephra::Config::Localisation::set_lang_by_file();
50             }
51             } else {
52 0 0         unlink $file{index} if -e $file{index};
53             }
54             }
55 0 0         unless ($load_cache) {
56 0           Kephra::Config::Localisation::load();
57 0           Kephra::CommandList::load();
58 0           del_temp_data();
59 0 0         if ($use_cache) {
60 0           my $write = \&YAML::Tiny::DumpFile;
61 0           &$write( $file{cmd_cache}, Kephra::CommandList::data() );
62 0           &$write( $file{l18n_cache}, Kephra::Config::Localisation::strings() );
63             }
64             }
65 0           Kephra::CommandList::eval_data();
66 0           Kephra::Config::Localisation::create_menus();
67 0           Kephra::App::EditPanel::create_mouse_binding();
68            
69             }
70            
71 0     0 0   sub del_temp_data { Kephra::CommandList::del_temp_data() }
72            
73             sub open_file {
74 0     0 0   my $item = shift;
75 0           my $config = _config();
76 0 0         return unless exists $config->{$item};
77 0           my $file = $config->{$item}{file};
78 0 0         $file = $config->{$item}{defaultfile} if $item eq 'contextmenu';
79 0 0         $file = $config->{$item}{file} if $item eq 'toolbar';
80 0           Kephra::Config::open_file( $file );
81             }
82            
83             1;