- add new helper function: return all second level config keys
authorAndreas Scherbaum <andreas@scherbaum.biz>
Mon, 16 Jan 2012 12:21:08 +0000 (13:21 +0100)
committerAndreas Scherbaum <andreas@scherbaum.biz>
Mon, 16 Jan 2012 12:21:08 +0000 (13:21 +0100)
- config_get_keys2()

config.pm

index a020c594c5905dcebb438559bb50df0208cd7460..3ebae7c0566f1c134cd1421ddef65f524eb4d012 100755 (executable)
--- a/config.pm
+++ b/config.pm
@@ -392,6 +392,50 @@ sub config_get_keys1 {
 }
 
 
+# config_get_keys2()
+#
+# return hash with all defined config keys
+#
+# parameter:
+#  - self
+#  - config key 1
+#  - config key 2
+# return:
+#  - hash with config keys
+sub config_get_keys2 {
+    my $self = shift;
+    my $key1 = shift;
+    my $key2 = shift;
+
+    if (!defined($self->{config}->{$key1})) {
+        return undef;
+    }
+
+    if (!defined($self->{config}->{$key1}->{$key2})) {
+        return undef;
+    }
+
+    if (ref($self->{config}->{$key1}->{$key2}) eq '') {
+      # return value
+      return $self->{config}->{$key1}->{$key2};
+    }
+
+    if (ref($self->{config}->{$key1}->{$key2}) eq 'HASH') {
+      # return sorted hash
+      my $config = $self->{config}->{$key1}->{$key2};
+      my %config = %$config;
+      # returns an array with the values
+      return sort(keys(%config));
+    }
+
+    if (ref($self->{config}->{$key1}->{$key2}) eq 'ARRAY') {
+      die("FIXME: not yet implemented - required?\n");
+    }
+
+    return undef;
+}
+
+
 # save_config()
 #
 # write the config to disk