1 package SL::MoreCommon;
 
   6 @EXPORT = qw(save_form restore_form compare_numbers any cross);
 
  13   $main::lxdebug->enter_sub();
 
  15   my @dont_dump_keys = @_;
 
  16   my %not_dumped_values;
 
  18   foreach my $key (@dont_dump_keys) {
 
  19     $not_dumped_values{$key} = $main::form->{$key};
 
  20     delete $main::form->{$key};
 
  23   my $old_form = YAML::Dump($main::form);
 
  24   $old_form =~ s|!|!:|g;
 
  25   $old_form =~ s|\n|!n|g;
 
  26   $old_form =~ s|\r|!r|g;
 
  28   map { $main::form->{$_} = $not_dumped_values{$_} } keys %not_dumped_values;
 
  30   $main::lxdebug->leave_sub();
 
  36   $main::lxdebug->enter_sub();
 
  38   my ($old_form, $no_delete, @keep_vars) = @_;
 
  40   my $form          = $main::form;
 
  41   my %keep_vars_map = map { $_ => 1 } @keep_vars;
 
  43   map { delete $form->{$_} if (!$keep_vars_map{$_}); } keys %{$form} unless ($no_delete);
 
  45   $old_form =~ s|!r|\r|g;
 
  46   $old_form =~ s|!n|\n|g;
 
  47   $old_form =~ s|![!:]|!|g;
 
  49   my $new_form = YAML::Load($old_form);
 
  50   map { $form->{$_} = $new_form->{$_} if (!$keep_vars_map{$_}) } keys %{ $new_form };
 
  52   $main::lxdebug->leave_sub();
 
  56   $main::lxdebug->enter_sub();
 
  63   $main::all_units ||= AM->retrieve_units(\%main::myconfig, $main::form);
 
  64   my $units          = $main::all_units;
 
  66   if (!$units->{$a_unit} || !$units->{$b_unit} || ($units->{$a_unit}->{base_unit} ne $units->{$b_unit}->{base_unit})) {
 
  67     $main::lxdebug->leave_sub();
 
  71   $a *= $units->{$a_unit}->{factor};
 
  72   $b *= $units->{$b_unit}->{factor};
 
  74   $main::lxdebug->leave_sub();
 
  88 =item cross BLOCK ARRAY ARRAY
 
  90 Evaluates BLOCK for each combination of elements in ARRAY1 and ARRAY2
 
  91 and returns a new list consisting of BLOCK's return values.
 
  92 The two elements are set to $a and $b.
 
  93 Note that those two are aliases to the original value so changing them
 
  94 will modify the input arrays.
 
  99   @x = cross { "$a$b" } @a, @b;
 
 100   # returns a1, a2, a3, b1, b2, b3, c1, c2, c3
 
 102 As cross expects an array but returns a list it is not directly chainable
 
 103 at the moment. This will be corrected in the future.
 
 109   local (*A, *B) = @_;    # syms for caller's input arrays
 
 112   my ($caller_a, $caller_b) = do {
 
 115     \*{$pkg.'::a'}, \*{$pkg.'::b'};
 
 118   local(*$caller_a, *$caller_b);
 
 120   # This map expression is also the return value.
 
 121   map { my $a_index = $_;
 
 122     map { my $b_index = $_;
 
 123       # assign to $a, $b as refs to caller's array elements
 
 124       (*$caller_a, *$caller_b) = \($A[$a_index], $B[$b_index]);
 
 125       $op->();    # perform the transformation