diff options
author | Patrick Spek <p.spek@tyil.nl> | 2017-04-26 08:05:14 +0200 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2017-04-26 08:05:14 +0200 |
commit | 632f695dc8726e3c63dac004a148aac7c95b1191 (patch) | |
tree | 046c0fd8fdb6a5f6a838f070ec2311c4bff30c2b /lib/Config.pm6 | |
parent | 5de74ad36feede030f0400c0231bf0eaa3c4ea3e (diff) |
Add a multi method has() that accepts an array param
Diffstat (limited to 'lib/Config.pm6')
-rw-r--r-- | lib/Config.pm6 | 27 |
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 |