From 11dcaa03fe07fb880fe9f29a7cfaec91043dad81 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Wed, 22 Nov 2017 13:34:16 +0100
Subject: Implement .keys method
---
lib/Config.pm6 | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
(limited to 'lib')
diff --git a/lib/Config.pm6 b/lib/Config.pm6
index d0c1d93..ad9be8a 100644
--- a/lib/Config.pm6
+++ b/lib/Config.pm6
@@ -110,6 +110,31 @@ class Config is Associative is export
defined($index);
}
+ method keys()
+ {
+ my @keys;
+
+ for $!content.keys -> $key {
+ @keys.append: self.extract-keys($key);
+ }
+
+ @keys.sort;
+ }
+
+ submethod extract-keys($key)
+ {
+ my $value = self.get($key);
+ return $key if $value !~~ Iterable;
+
+ my @keys;
+
+ for $value.keys -> $nested-key {
+ @keys.append: self.extract-keys("{$key}.{$nested-key}");
+ }
+
+ return @keys;
+ }
+
#| Reload the configuration. Requires the configuration to
#| have been loaded from a file.
multi method read()
--
cgit v1.1