vanstyn / RapidApp

Turnkey ajaxy webapps
http://rapi.io
Other
48 stars 15 forks source link

Unsafe use of global Hash::Merge behavior #155

Open ribasushi opened 9 years ago

ribasushi commented 9 years ago

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.