From a913899f0ce3394501ee721b7e8c30f68a1cb133 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Sat, 29 Jul 2017 02:09:03 +0200
Subject: Initial draft for associative indexing
---
lib/Config.pm6 | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/lib/Config.pm6 b/lib/Config.pm6
index f0a75c3..63a5e7a 100644
--- a/lib/Config.pm6
+++ b/lib/Config.pm6
@@ -8,7 +8,7 @@ use Config::Exception::MissingParserException;
use Config::Exception::FileNotFoundException;
use Config::Parser;
-class Config is export
+class Config is Associative is export
{
has Hash $!content = {};
has Str $!path = "";
@@ -209,4 +209,29 @@ class Config is export
require ::($chosen-parser);
return ::($chosen-parser).write($path, $!content);
}
+
+ multi method AT-KEY(::?CLASS:D: $key)
+ {
+ $self.get($key);
+ }
+
+ multi method EXISTS-KEY(::?CLASS:D: $key)
+ {
+ $self.has($key);
+ }
+
+ multi method DELETE-KEY(::?CLASS:D: $key)
+ {
+ $self.unset($key);
+ }
+
+ multi method ASSIGN-KEY(::?CLASS:D: $key, $new)
+ {
+ $self.set($key, $new);
+ }
+
+ multi method BIND-KEY(::?CLASS:D: $key, \new)
+ {
+ $self.set($key, new);
+ }
}
--
cgit v1.1