The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

RappidApp::Util::Hash::Merge - Merges arbitrarily deep hashes into a single hash

SYNOPSIS

    use RappidApp::Util:Hash::Merge qw( merge );
    my %a = ( 
		'foo'    => 1,
	    'bar'    => [ qw( a b e ) ],
	    'querty' => { 'bob' => 'alice' },
	);
    my %b = ( 
		'foo'     => 2, 
		'bar'    => [ qw(c d) ],
		'querty' => { 'ted' => 'margeret' }, 
	);

    my %c = %{ merge( \%a, \%b ) };

    RappidApp::Util:Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' );

    # This is the same as above

	RappidApp::Util:Hash::Merge::specify_behavior(
	    {
			'SCALAR' => {
				'SCALAR' => sub { $_[1] },
				'ARRAY'  => sub { [ $_[0], @{$_[1]} ] },
				'HASH'   => sub { $_[1] },
			},
			'ARRAY => {
				'SCALAR' => sub { $_[1] },
				'ARRAY'  => sub { [ @{$_[0]}, @{$_[1]} ] },
				'HASH'   => sub { $_[1] }, 
			},
			'HASH' => {
				'SCALAR' => sub { $_[1] },
				'ARRAY'  => sub { [ values %{$_[0]}, @{$_[1]} ] },
				'HASH'   => sub { RappidApp::Util:Hash::Merge::_merge_hashes( $_[0], $_[1] ) }, 
			},
		}, 
		'My Behavior', 
	);
	
	# Also there is OO interface.
	
	my $merge = RappidApp::Util:Hash::Merge->new( 'LEFT_PRECEDENT' );
	my %c = %{ $merge->merge( \%a, \%b ) };
	
	# All behavioral changes (e.g. $merge->set_behavior(...)), called on an object remain specific to that object
	# The legacy "Global Setting" behavior is respected only when new called as a non-OO function.

DESCRIPTION

This is a copy of Hash::Merge at version 2.00.

See https://metacpan.org/pod/release/REHSACK/Hash-Merge-0.200/lib/Hash/Merge.pm

Please don't use this as it may be removed at any time.

AUTHOR

Original author Michael K. Neylon <mneylon-pm@masemware.com>

Trivial modifications by Henry Van Styn for RapidApp

See https://github.com/vanstyn/RapidApp/issues/177 for why this copy was created.

COPYRIGHT

Copyright (c) 2001,2002 Michael K. Neylon. All rights reserved.

This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.