From 4686af7aeb17a62fe0a384fa5b49211716aeaf58 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Sun, 23 Apr 2017 21:44:40 +0200
Subject: Add multi get() to accept arrays
---
lib/Config.pm6 | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
(limited to 'lib')
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;
--
cgit v1.1