Help language development. Donate to The Perl Foundation

Hash::Merge cpan:TYIL last updated on 2020-11-15

README.rakudoc
=begin pod

=NAME    Hash::Merge
=VERSION 2.0.0
=AUTHOR  Patrick Spek <[email protected]>

=head1 Description

A module for the Raku programming language to easily deep-merge two hashes.

=head2 Usage

Base usage requires you to C<use> the module, and pass two C<Hash>es to the
imported function, C<merge-hash>.

=begin code
use Hash::Merge;

my %alpha =
	a => 'b',
	c => {
		d => 'e',
		f => 'g',
	},
;

my %beta =
	z => 'y',
	c => {
		x => 'w',
	},
;

my %merged = merge-hash(%alpha, %beta);
=end code

There are two potential options to pass to C<merge-hash>:

=defn C<Bool:D :$deep = True>
When set to C<False>, this will not deep merge the C<Hash>es. This means that
the second C<Hash> that is passed, will I<overwrite> C<Hash> elements in the
first C<Hash>, instead of combining them.

=defn C<Bool:D :$positional-append = True>
When set to C<False>, this will not append C<Positional> elements. This means
that any C<Positional> elements in the second C<Hash> will I<overwrite>
C<Positional> elements in the first C<Hash>.

There is also a C<use> in this module that allows you to call C<.merge> on
existing C<Hash> objects. This requires C<Hash::Merge::Augment>. While this is
a fancy way to work, it will break pre-compilation of whatever module is using
it.

=begin code
use Hash::Merge::Augment

my %alpha =
	a => 'b',
	c => {
		d => 'e',
		f => 'g',
	},
;

%alpha.merge({
	z => 'y',
	c => {
		x => 'w',
	},
});
=end code

=head2 Contributing

The module's source code is available at the following locations:

=item L<https://git.sr.ht/~tyil/raku-hash-merge>
=item L<https://gitlab.com/tyil/raku-hash-merge>
=item L<https://github.com/scriptkitties/p6-Hash-Merge>

If you have a change you would like to include, please send a patch to
L<mailto:~tyil/[email protected]>.

=head2 License

This module is distributed under the terms of the Artistic License 2.0. For
more information, consult the LICENSE file in the module's source code
repository.

=end pod