Skip to content

Unsafe use of global Hash::Merge behavior #155

@ribasushi

Description

@ribasushi

As said elsewhere Hash::Merge... has design shortcomings. In your case the problem is apparent from the following oneliner:

perl -Ilib -e '
  use RapidApp::Util "merge";
  use Devel::Dwarn;
  my $something_far_far_away = sub { Hash::Merge::set_behavior("LEFT_PRECEDENT") };
  for (0, 1) {
    $something_far_far_away->() if $_;
    Dwarn [ merge( { foo => 1 }, { foo => 2 } ) ]
  }
'

You must use an object with separate state as shown here (which fwiw can be cached). Sorry for not sending a PR - much yakshaving ahead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions