From: miker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4> Date: Wed, 2 Jun 2010 14:55:23 +0000 (+0000) Subject: add class/instance methods for checking required-ness and validity of an object field... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e6b1d819877d2f88f6565201182b284e5e7fbd9f;p=contrib%2FConifer.git add class/instance methods for checking required-ness and validity of an object field in perl FM implementation; also fixing typo git-svn-id: svn://svn.open-ils.org/ILS/trunk@16556 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm b/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm index 77a1080b6c..b8e5693ecd 100644 --- a/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm @@ -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;