From e3089098b4b27022597f7514af44108d4b3f5021 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Mon, 19 Mar 2012 18:35:52 -0400 Subject: [PATCH] Teach Fieldmapper (Perl) to record and expose field datatype We record most everything from the IDL, but until now we skipped datatype because it's generally not useful in perl. But, there might be uses. So now we record it, and expose it through the class and instance FieldDatatype method. Also added is a more general FieldInfo method, which returns a hash containing field attributes, including but not limited to: * virtual [1|0] * required [1|0] * position [array position for internal implementation] * datatype [bool|float|id|int|interval|link|money|number|org_unit|text|timestamp] * validate [regexp] Signed-off-by: Mike Rylander Signed-off-by: Dan Wells --- .../perlmods/lib/OpenILS/Utils/Fieldmapper.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/Fieldmapper.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/Fieldmapper.pm index 0a898248d8..4cd02a2537 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/Fieldmapper.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/Fieldmapper.pm @@ -82,11 +82,13 @@ sub load_fields { $virtual = "false"; } my $selector = get_attribute( $attribute_list, 'reporter:selector' ); + my $datatype = get_attribute( $attribute_list, 'reporter:datatype' ); $$fieldmap{$fm}{fields}{ $name } = { virtual => ( $virtual eq 'true' ) ? 1 : 0, required => ( $required eq 'true' ) ? 1 : 0, position => $array_position, + datatype => $datatype, }; $$fieldmap{$fm}{fields}{ $name }{validate} = qr/$validate/ if (defined($validate)); @@ -378,6 +380,22 @@ sub ValidateField { return $self->$f =~ $$fieldmap{$self->class_name}{fields}{$f}{validate}; } +sub FieldInfo { + my $self = shift; + my $field = shift; + my $class_name = $self->class_name; + return undef unless ($field && $$fieldmap{$class_name}{fields}{$field}); + return $$fieldmap{$class_name}{fields}{$field}; +} + +sub FieldDatatype { + my $self = shift; + my $field = shift; + my $class_name = $self->class_name; + return undef unless ($field && $$fieldmap{$class_name}{fields}{$field}); + return $$fieldmap{$class_name}{fields}{$field}{datatype}; +} + sub class_name { my $class_name = shift; return ref($class_name) || $class_name; -- 2.43.2