Rearrange some logic in get_combined_holdings()
authorDan Wells <dbw2@calvin.edu>
Tue, 2 Jul 2013 15:19:05 +0000 (11:19 -0400)
committerDan Wells <dbw2@calvin.edu>
Tue, 2 Jul 2013 15:52:12 +0000 (11:52 -0400)
The logic in get_combined_holdings() was a little sloppy and
repeated some steps unnecessarily.  This cleans things up.

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

index 82a02be..03975cf 100644 (file)
@@ -550,12 +550,20 @@ sub get_combined_holdings {
                 $combined_holdings[-1]->clone->compressed_to_last
                 : $combined_holdings[-1]->clone;
 
+            # next, get the end (or only) holding of the current
+            # holding being considered
+            my $holding_end;
+            if ($holding->is_compressed) {
+                $holding_end = $holding->is_open_ended ?
+                undef
+                : $holding->clone->compressed_to_last;
+            } else {
+                $holding_end = $holding;
+            }
+
             # next, make sure $holding isn't fully contained
-            my $holding_end = $holding->is_compressed ?
-                $holding->clone->compressed_to_last
-                : $holding;
-            # if $holding is fully contained, skip it
-            if ($holding_end le $last_holding_end) {
+            # if it is, skip it
+            if ($holding_end and $holding_end le $last_holding_end) {
                 next;
             }
 
@@ -564,16 +572,9 @@ sub get_combined_holdings {
                 $holding->clone->compressed_to_first
                 : $holding;
 
+            # see if they overlap
             if ($last_holding_end->increment ge $holding_start) {
                 # they overlap, combine them
-                my $holding_end;
-                if ($holding->is_compressed) {
-                    $holding_end = $holding->is_open_ended ?
-                    undef
-                    : $holding->compressed_to_last;
-                } else {
-                    $holding_end = $holding;
-                }
                 $combined_holdings[-1]->compressed_end($holding_end);
             } else {
                 # no overlap, start a new group