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

Data::PrefixMerge::Config - Data::PrefixMerge configuration

VERSION

version 0.12

SYNOPSIS

    # getting configuration
    if ($merger->config->allow_extra_hash_keys) { ... }

    # setting configuration
    $merger->config->max_warnings(100);

DESCRIPTION

Configuration variables for Data::PrefixMerge.

ATTRIBUTES

recurse_hash => BOOL

Whether to recursively merge hash. Default is 1.

With recurse_hash set to 1, hashes will be recursively merged:

 prefix_merge({h=>{a=>1}}, {h=>{b=>1}}); # {h=>{a=>1, b=>1}}

With recurse_hash set to 0, hashes on the left side will just be replaced with hashes on the right side:

 prefix_merge({h=>{a=>1}}, {h=>{b=>1}}); # {h=>{b=>1}}

recurse_array => BOOL

Whether to recursively merge hash. Default is 0.

With recurse_array set to 1, arrays will be recursively merged:

 prefix_merge([1, 1], [2]); # [2, 1]

With recurse_array set to 0, array on the left side will just be replaced with array on the right side:

 prefix_merge([1, 1], [2]); # [2]

parse_hash_key_prefix => BOOL

Whether to parse merge prefix for in hash keys. Default is 1. If you set this to 0, merging behaviour is similar to most other nested merge modules.

With parse_hash_key_prefix set to 1:

 prefix_merge({a=>1}, {"+a"=>2}); # {a=>3}

With parse_hash_key_prefix set to 0:

 prefix_merge({a=>1}, {"+a"=>2}); # {a=>1, "+a"=>2}

wanted_path => ARRAYREF

Default is undef. If you set this, merging is only done to the specified "branch". Useful to save time/storage when merging large hash "trees" while you only want a certain branch of the trees (e.g. resolving just a config variable from several config hashes).

Example:

 prefix_merge(
   {
    user => {
      steven => { quota => 100, admin => 1 },
      tommie => { quota =>  50, admin => 0 },
      jimmy  => { quota => 150, admin => 0 },
    },
    groups => [qw/admin staff/],
   },
   {
    user => {
      steven => { quota => 1000 },
    }
   }
 );

With wanted_path unset, the result would be:

   {
    user => {
      steven => { quota => 1000, admin => 1 },
      tommie => { quota =>   50, admin => 0 },
      jimmy  => { quota =>  150, admin => 0 },
    }
    groups => [qw/admin staff/],
   }

With wanted_path set to ["user", "steven", "quota"] (in other words, you're saying that you'll be disregarding other branches), the result would be:

   {
    user => {
      steven => { quota => 1000, admin => undef },
      tommie => undef,
      jimmy  => undef,
    }
    groups => undef,
   }

default_merge_mode => 'NORMAL' | 'ADD' | 'CONCAT' | 'SUBTRACT' | 'DELETE' | 'KEEP'

Default is 'NORMAL'.

Example:

When setting default_merge_mode to NORMAL (DEFAULT):

 prefix_merge(3, 4); # 4

When setting default_merge_mode to ADD:

 prefix_merge(3, 4); # 7

preserve_keep_prefix => 0|1

Default it 0.

If set to 1, then key KEEP merge prefixes on hash keys (^) will be preserved. This is useful if we want to do another merge on the result.

Example:

 prefix_merge({'^a'=>1}, {a=>2}); # {a=>1}
 prefix_merge({'a'=>1}, {a=>2}, {preserve_keep_prefix=>1}); # {'^a'=>1}
 prefix_merge({'a'=>1}, {'^a'=>2}, {preserve_keep_prefix=>1}); # {'^a'=>1}

hash_options_key => STR

Default is unset. If set, then hash key with the specified name will become the special options key and can regulate/fine-tune merging behaviour on a per-hash level. After merging, that special options key itself will be removed.

Example:

 prefix_merge({'^a' => 1},
              {a => 2},
              {preserve_keep_prefix=>1});
 # {'^a' => 1}

 prefix_merge({'^a' => 1, 'MERGE_OPTS'=>{remove_keep_prefixes=>1}},
              {a => 2},
              {preserve_keep_prefix=>1, hash_options_key => 'MERGE_OPTS'});
 # {'a' => 1}

The value of the options key is a hash with these known keys (or option):

remove_keep_prefixes => BOOL

Default is false. Whether to remove keep prefixes.

remove_keep_max_depth => INT

Default is -1 (unlimited). Maximum depth levels of keep prefixes removal.

AUTHOR

  Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2009 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.