aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2017-04-26 08:05:14 +0200
committerPatrick Spek <p.spek@tyil.nl>2023-07-25 02:16:11 +0200
commit3d085c1e08c8eb5997bf4fb5c82a91d8e30525c6 (patch)
tree046c0fd8fdb6a5f6a838f070ec2311c4bff30c2b /lib
parent5242e04854d037d2787d059627e9f2bc12af6787 (diff)
Add a multi method has() that accepts an array param
Diffstat (limited to 'lib')
-rw-r--r--lib/Config.pm627
1 files changed, 12 insertions, 15 deletions
diff --git a/lib/Config.pm6 b/lib/Config.pm6
index 97d708c..2369b6f 100644
--- a/lib/Config.pm6
+++ b/lib/Config.pm6
@@ -28,24 +28,16 @@ class Config is export
#| key, use a . to descent a level.
multi method get(Str $key, Any $default = Nil)
{
- my $index = $!content;
-
- for $key.split(".") -> $part {
- return $default unless defined($index{$part});
-
- $index = $index{$part};
- }
-
- $index;
+ self.get($key.split("."), $default);
}
#| Get a value from the config object using an array
#| to indicate the nested key to get.
- multi method get(@keyparts, Any $default = Nil)
+ multi method get(Array $keyparts, Any $default = Nil)
{
my $index = $!content;
- for @keyparts -> $part {
+ for $keyparts -> $part {
return $default unless defined($index{$part});
$index = $index{$part};
@@ -92,16 +84,21 @@ class Config is export
}
#| Check wether a given key exists.
- method has(Str $key) {
+ multi method has(Str $key) {
+ self.has($key.split("."));
+ }
+
+ #| Check wether a given key exists using an array to supply
+ #| the nested key to check.
+ multi method has(Array $keyparts)
+ {
my $index = $!content;
- for $key.split(".") -> $part {
+ for $keyparts -> $part {
return False unless defined($index{$part});
$index = $index{$part};
}
-
- True;
}
#| Reload the configuration. Requires the configuration to