aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2017-04-23 21:44:40 +0200
committerPatrick Spek <p.spek@tyil.nl>2023-07-25 02:16:02 +0200
commit4686af7aeb17a62fe0a384fa5b49211716aeaf58 (patch)
treeff9730b497d7f4225b87f5a080b53eb2a1628512 /lib
parentbdde8957370dde4cc35ab2a7d24a568f05c948d2 (diff)
Add multi get() to accept arrays
Diffstat (limited to 'lib')
-rw-r--r--lib/Config.pm615
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/Config.pm6 b/lib/Config.pm6
index 729ccba..abf2b44 100644
--- a/lib/Config.pm6
+++ b/lib/Config.pm6
@@ -44,7 +44,7 @@ class Config is export
return ::($parser).write($path, $!content);
}
- method get(Str $key, Any :$default = Nil)
+ multi method get(Str $key, Any $default = Nil)
{
my $index = $!content;
@@ -57,6 +57,19 @@ class Config is export
$index;
}
+ multi method get(@keyparts, Any $default? = Nil)
+ {
+ my $index = $!content;
+
+ for @keyparts -> $part {
+ return $default unless defined($index{$part});
+
+ $index = $index{$part};
+ }
+
+ $index;
+ }
+
method has(Str $key) {
my $index = $!content;