A little defensive programming parsing oils_ncip.xml.
authorJason Stephenson <jason@sigio.com>
Mon, 30 Mar 2015 00:19:16 +0000 (20:19 -0400)
committerJason Stephenson <jason@sigio.com>
Mon, 30 Mar 2015 00:19:16 +0000 (20:19 -0400)
If one leaves the <patrons> block alone, one gets the following Perl
error:

Can't use string as a HASH ref while "strict refs" in use at
/home/opensrf/NCIPServer/lib/NCIP/ILS/Evergreen.pm line 2626.

This commit attempts to avoid that.

Signed-off-by: Jason Stephenson <jason@sigio.com>
lib/NCIP/ILS/Evergreen.pm

index b65490a..d1c957b 100644 (file)
@@ -2623,24 +2623,27 @@ sub _init {
     # Load the barred groups as pgt objects into a blocked_profiles
     # list.
     $self->{blocked_profiles} = [];
-    foreach (@{$self->{config}->{patrons}->{block_profile}}) {
-        my $pgt;
-        if (ref $_) {
-            $pgt = $U->simplereq(
-                'open-ils.pcrud',
-                'open-ils.pcrud.retrieve.pgt',
-                $self->{session}->{authtoken},
-                $_->{grp}
-            );
-        } else {
-            $pgt = $U->simplereq(
-                'open-ils.pcrud',
-                'open-ils.pcrud.search.pgt',
-                $self->{session}->{authtoken},
-                {name => $_}
-            );
+    if (ref($self->{config}->{patrons}) eq 'HASH') {
+        foreach (@{$self->{config}->{patrons}->{block_profile}}) {
+            my $pgt;
+            if (ref $_) {
+                $pgt = $U->simplereq(
+                    'open-ils.pcrud',
+                    'open-ils.pcrud.retrieve.pgt',
+                    $self->{session}->{authtoken},
+                    $_->{grp}
+                );
+            } else {
+                $pgt = $U->simplereq(
+                    'open-ils.pcrud',
+                    'open-ils.pcrud.search.pgt',
+                    $self->{session}->{authtoken},
+                    {
+                        name => $_}
+                );
+            }
+            push(@{$self->{blocked_profiles}}, $pgt) if ($pgt);
         }
-        push(@{$self->{blocked_profiles}}, $pgt) if ($pgt);
     }
 
     # Load the bib source if we're not using precats.