aboutsummaryrefslogtreecommitdiff
path: root/lib/Hash/Merge
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Hash/Merge')
-rw-r--r--lib/Hash/Merge/Augment.pm663
-rw-r--r--lib/Hash/Merge/Augment.rakumod33
2 files changed, 33 insertions, 63 deletions
diff --git a/lib/Hash/Merge/Augment.pm6 b/lib/Hash/Merge/Augment.pm6
deleted file mode 100644
index 8de7542..0000000
--- a/lib/Hash/Merge/Augment.pm6
+++ /dev/null
@@ -1,63 +0,0 @@
-#! /usr/bin/env false
-
-use v6.c;
-use MONKEY-TYPING;
-
-# Don't use precompilation in order to not conflict with other MONKEY-TYPING
-# modules.
-no precompilation;
-
-augment class Hash
-{
- #| Merges a second hash into the hash the method is called on. Hash given as
- #| the argument is not modified.
- #| Traverses the full tree, replacing items in the original hash with the
- #| hash given in the argument. Does not replace positional elements by default,
- #| and instead appends the items from the supplied hash's array to the original
- #| hash's array. The object type of positionals is not retained and instead
- #| becomes an Array type.
- #| Use :no-append-array to replace arrays and positionals instead, which will
- #| also retain the original type and not convert to an Array
- multi method merge (Hash:U: %b, Bool:D :$no-append-array = False)
- {
- return %b;
- }
-
- multi method merge (Hash:D: %b, Bool:D :$no-append-array = False)
- {
- hashmerge self, %b, :$no-append-array;
- }
-
- sub hashmerge (%merge-into, %merge-source, Bool:D :$no-append-array)
- {
- for %merge-source.keys -> $key {
- if %merge-into{$key}:exists {
- given %merge-source{$key} {
- when Hash {
- hashmerge %merge-into{$key},
- %merge-source{$key},
- :$no-append-array;
- }
- when Positional {
- %merge-into{$key} = $no-append-array
- ?? %merge-source{$key}
- !!
- do {
- my @a;
- @a.push: $_ for %merge-into{$key}.list;
- @a.push: $_ for %merge-source{$key}.list;
- @a;
- }
- }
- # Non-positionals, so strings or Bools or whatever
- default { %merge-into{$key} = %merge-source{$key} }
- }
- } else {
- %merge-into{$key} = %merge-source{$key};
- }
- }
- %merge-into;
- }
-}
-
-# vim: ft=perl6 ts=4 sw=4 et
diff --git a/lib/Hash/Merge/Augment.rakumod b/lib/Hash/Merge/Augment.rakumod
new file mode 100644
index 0000000..e719dc1
--- /dev/null
+++ b/lib/Hash/Merge/Augment.rakumod
@@ -0,0 +1,33 @@
+#! /usr/bin/env false
+
+use v6.d;
+use MONKEY-TYPING;
+
+use Hash::Merge;
+
+# Don't use precompilation in order to not conflict with other MONKEY-TYPING
+# modules.
+no precompilation;
+
+augment class Hash {
+ method merge (
+ Hash:D:
+
+ #| The Hash to merge into this one.
+ %hash,
+
+ #| Boolean to set whether Associative objects should be merged on their
+ #| own. When set to False, Associative objects in %second will
+ #| overwrite those from %first.
+ Bool:D :$deep = True,
+
+ #| Boolean to set whether Positional objects should be appended. When
+ #| set to False, Positional objects in %second will overwrite those
+ #| from %first.
+ Bool:D :$positional-append = True,
+ ) {
+ self = merge-hash(self, %hash, :$deep, :$positional-append);
+ }
+}
+
+# vim: ft=raku ts=4 sw=4 et