Improve readability by moving code out of unnecessary blocks
Invert conditions and move out unnecessary blocks to reduce indentation and make it easier to see control flow.
This commit is contained in:
parent
160344514f
commit
5c38af2ed5
1 changed files with 55 additions and 59 deletions
32
ddclient.in
32
ddclient.in
|
@ -1577,14 +1577,13 @@ sub read_cache {
|
|||
%opt = %saved;
|
||||
|
||||
for my $h (keys %cache) {
|
||||
if (exists $config->{$h}) {
|
||||
next if !exists($config->{$h});
|
||||
for (qw(atime mtime wtime ip status)) {
|
||||
$config->{$h}{$_} = $cache{$h}{$_} if exists $cache{$h}{$_};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
######################################################################
|
||||
## parse_assignments(string) return (rest, %variables)
|
||||
## parse_assignment(string) return (name, value, rest)
|
||||
|
@ -1764,43 +1763,43 @@ sub _read_config {
|
|||
# Handle '_env' keyword suffix
|
||||
if ($k =~ /(.*)_env$/) {
|
||||
debug("Loading value for $1 from environment variable $locals{$k}.");
|
||||
if (exists($ENV{$locals{$k}})) {
|
||||
# Set the value to the value of the environment variable
|
||||
$locals{$1} = $ENV{$locals{$k}};
|
||||
# Remove the '_env' suffix from the key
|
||||
$k = $1;
|
||||
} else {
|
||||
if (!exists($ENV{$locals{$k}})) {
|
||||
warning("Environment variable '$locals{$k}' not set for keyword '$k' (ignored)");
|
||||
delete $locals{$k};
|
||||
next;
|
||||
}
|
||||
# Set the value to the value of the environment variable
|
||||
$locals{$1} = $ENV{$locals{$k}};
|
||||
# Remove the '_env' suffix from the key
|
||||
$k = $1;
|
||||
}
|
||||
|
||||
$locals{$k} = $passwords{$k} if defined $passwords{$k};
|
||||
if (!exists $variables{'merged'}{$k}) {
|
||||
warning("unrecognized keyword '%s' (ignored)", $k);
|
||||
delete $locals{$k};
|
||||
} else {
|
||||
next;
|
||||
}
|
||||
my $def = $variables{'merged'}{$k};
|
||||
my $value = check_value($locals{$k}, $def);
|
||||
if (!defined($value)) {
|
||||
warning("Invalid Value for keyword '%s' = '%s'", $k, $locals{$k});
|
||||
delete $locals{$k};
|
||||
} else {
|
||||
next;
|
||||
}
|
||||
$locals{$k} = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
%passwords = ();
|
||||
if (exists($locals{'host'})) {
|
||||
$args[0] = @args ? "$args[0],$locals{host}" : "$locals{host}";
|
||||
}
|
||||
## accumulate globals
|
||||
if ($#args < 0) {
|
||||
map { $globals{$_} = $locals{$_} } keys %locals;
|
||||
next;
|
||||
}
|
||||
|
||||
## process this host definition
|
||||
if (@args) {
|
||||
my ($host, $login, $password) = @args;
|
||||
|
||||
## add in any globals..
|
||||
|
@ -1822,8 +1821,6 @@ sub _read_config {
|
|||
}
|
||||
}
|
||||
}
|
||||
%passwords = ();
|
||||
}
|
||||
close(FD);
|
||||
|
||||
warning("file ends while expecting a continuation line.")
|
||||
|
@ -1978,8 +1975,9 @@ sub init_config {
|
|||
if (!exists($services{$proto})) {
|
||||
warning("skipping host: %s: unrecognized protocol '%s'", $h, $proto);
|
||||
delete $config{$h};
|
||||
next;
|
||||
}
|
||||
|
||||
} else {
|
||||
my $svars = $services{$proto}{'variables'};
|
||||
my $conf = {'protocol' => $proto};
|
||||
|
||||
|
@ -1996,13 +1994,11 @@ sub init_config {
|
|||
next HOST;
|
||||
}
|
||||
$conf->{$k} = $value;
|
||||
|
||||
}
|
||||
$config{$h} = $conf;
|
||||
$config{$h}{'cacheable'} = [ @{$services{$proto}{'cacheable'}} ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
######################################################################
|
||||
## process_args -
|
||||
|
|
Loading…
Reference in a new issue