add class/instance methods for checking required-ness and validity of an object field...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 2 Jun 2010 14:55:23 +0000 (14:55 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 2 Jun 2010 14:55:23 +0000 (14:55 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@16556 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm

index 77a1080..b8e5693 100644 (file)
@@ -93,7 +93,7 @@ sub load_fields {
                                  position => $array_position,
                                };
 
-                       $$fieldmap{$fm}{fields}{ $name }{validate} = qr/$valudate/ if (defined($validate));
+                       $$fieldmap{$fm}{fields}{ $name }{validate} = qr/$validate/ if (defined($validate));
 
                        # The selector attribute, if present at all, attaches to only one
                        # of the fields in a given class.  So if we see it, we store it at
@@ -312,6 +312,21 @@ sub Controller {
        return $$fieldmap{$self->class_name}{controller};
 }
 
+sub RequiredField {
+       my $self = shift;
+       my $f = shift;
+    return undef unless ($f);
+       return $$fieldmap{$self->class_name}{fields}{$f}{required};
+}
+
+sub ValidateField {
+       my $self = shift;
+       my $f = shift;
+    return undef unless ($f);
+       return 1 if (!exists($$fieldmap{$self->class_name}{fields}{$f}{validate}));
+       return $self->$f =~ $$fieldmap{$self->class_name}{fields}{$f}{validate};
+}
+
 sub class_name {
        my $class_name = shift;
        return ref($class_name) || $class_name;