Skip to content
Snippets Groups Projects
Verified Commit 64861fcf authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- refactoring, splitted BEGIN-block

parent ce1402e3
No related branches found
No related tags found
No related merge requests found
...@@ -24,9 +24,13 @@ BEGIN { ...@@ -24,9 +24,13 @@ BEGIN {
my $rx_psep = qr{[/\\]}; my $rx_psep = qr{[/\\]};
my $rx_abs = qr{[A-Z]:}; my $rx_abs = qr{[A-Z]:};
my $rx_sub = qr{([[:print:]]+)}; my $rx_sub = qr{([[:print:]]+)};
$ENV{'HOME'} =~ m{^(($rx_abs)?($rx_psep$rx_sub)+)$}m; if ($ENV{'HOME'} =~ m{^(($rx_abs)?($rx_psep$rx_sub)+)$}m) {
# untaint $homestr load_config_if_possible($1);
my $homestr = $1; load_cache_if_possible($1);
}
}
sub load_config_if_possible ($homestr) {
my $home = path($homestr); my $home = path($homestr);
if ($home->is_dir() && !$home->is_rootdir) { if ($home->is_dir() && !$home->is_rootdir) {
my $config_path = $home->child('.config')->child('ta-tool.rc'); my $config_path = $home->child('.config')->child('ta-tool.rc');
...@@ -39,12 +43,22 @@ BEGIN { ...@@ -39,12 +43,22 @@ BEGIN {
%config = %{$config_ref}; %config = %{$config_ref};
$config{elasticsearch_protocol} = $config{http_only} ? 'http' : 'https'; $config{elasticsearch_protocol} = $config{http_only} ? 'http' : 'https';
} }
}
return 1;
}
sub load_cache_if_possible ($homestr) {
my $home = path($homestr);
if ($home->is_dir() && !$home->is_rootdir) {
$cache_path = $home->child('.cache')->child('ta-tool.cache'); $cache_path = $home->child('.cache')->child('ta-tool.cache');
if ($cache_path->is_file and -s $cache_path < 8192 * 1024) { # if size > 8MB, write new at end, see END{}-block if ($cache_path->is_file and -s $cache_path < 8192 * 1024) {
# if size > 8MB, write new at end, see END{}-block
my $cache_ref = YAML::LoadFile($cache_path); my $cache_ref = YAML::LoadFile($cache_path);
%cache = %{$cache_ref}; %cache = %{$cache_ref};
} }
} }
return 1;
} }
sub common_global_validate ($self, $opt, $args) { sub common_global_validate ($self, $opt, $args) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment