Fix logic in get_compressed_holdings()
authorDan Wells <dbw2@calvin.edu>
Wed, 8 May 2013 19:09:41 +0000 (15:09 -0400)
committerDan Wells <dbw2@calvin.edu>
Tue, 2 Jul 2013 15:11:20 +0000 (11:11 -0400)
This commit rearranges some of the logic branches to protect
against an unusual case of having two holding statements with
the same start value, but one being open-ended and one not.

See the test case in the previous commit for more clarity.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm

index dff0066..82a02be 100644 (file)
@@ -390,10 +390,8 @@ sub get_compressed_holdings {
         if ($runner eq $holding) {
             $curr_holding->extend;
             $runner->increment;
-        } elsif ($runner gt $holding) { # should not happen unless holding is not in series
-            carp("Found unexpected holding, skipping");
         } elsif ($holding->is_open_ended) { # special case, as it will always be the last
-            if ($runner eq $holding->clone->compressed_to_first) {
+            if ($runner ge $holding->clone->compressed_to_first) {
                 $curr_holding->compressed_end();
             } else {
                 push(@comp_holdings, $curr_holding);
@@ -402,6 +400,8 @@ sub get_compressed_holdings {
                 $curr_holding->seqno($seqno);
             }
             last;
+        } elsif ($runner gt $holding) { # should not happen unless holding is not in series
+            carp("Found unexpected holding, skipping");
         } else {
             push(@comp_holdings, $curr_holding);