Add class_for_hint function to OpenILS::Utils::Fieldmapper.
authorJason Stephenson <jason@sigio.com>
Sun, 11 Dec 2011 01:28:48 +0000 (20:28 -0500)
committerBill Erickson <berick@esilibrary.com>
Fri, 16 Dec 2011 20:20:46 +0000 (15:20 -0500)
Use this function to find a Fieldmapper class from the JSON hint or
class id:

my $class = Fieldmapper::class_for_hint('au');
print("$class\n");

Will print:

Fieldmapper::actor::user

Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Utils/Fieldmapper.pm

index e1bebb7..df00277 100644 (file)
@@ -37,6 +37,15 @@ sub classes {
        return keys %$fieldmap;
 }
 
+# Find a Fieldmapper class given the json hint.
+sub class_for_hint {
+    my $hint = shift;
+    foreach (keys %$fieldmap) {
+        return $_ if ($fieldmap->{$_}->{hint} eq $hint);
+    }
+    return undef;
+}
+
 sub get_attribute {
        my $attr_list = shift;
        my $attr_name = shift;