RapidApp icon indicating copy to clipboard operation
RapidApp copied to clipboard

Unsafe use of global Hash::Merge behavior

Open ribasushi opened this issue 9 years ago • 0 comments

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.

ribasushi avatar Jul 06 '15 08:07 ribasushi