]> git.proxmox.com Git - pmg-api.git/commitdiff
config: refactor getter
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 21 Feb 2024 16:04:08 +0000 (17:04 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 21 Feb 2024 16:25:10 +0000 (17:25 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PMG/Config.pm

index 70e182197289364dc5f7659f1ba0687b4e3e1e80..7348c00772a5b2e1695a3ab71820de6b4399f085 100644 (file)
@@ -893,19 +893,18 @@ sub get {
     my ($self, $section, $key, $nodefault) = @_;
 
     my $pdata = PMG::Config::Base->private();
-    my $pdesc = $pdata->{propertyList}->{$key};
+    my $schema = $pdata->{propertyList}->{$key} // die "no schema for property '$section/$key'\n";
+    my $options = $pdata->{options}->{$section} // die "no options for section '$section/$key'\n";
+
     die "no such property '$section/$key'\n"
-       if !(defined($pdesc) && defined($pdata->{options}->{$section}) &&
-            defined($pdata->{options}->{$section}->{$key}));
+       if !(defined($schema) && defined($options) && defined($options->{$key}));
 
-    if (defined($self->{ids}->{$section}) &&
-       defined(my $value = $self->{ids}->{$section}->{$key})) {
-       return $value;
-    }
+    my $values = $self->{ids}->{$section};
+    return $values->{$key} if defined($values) && defined($values->{$key});
 
     return undef if $nodefault;
 
-    return $pdesc->{default};
+    return $schema->{default};
 }
 
 # get a whole section with default value