diff Lib/Form/Filter/Mandatory.pm @ 0:03e58a454b20

Создан репозитарий
author Sergey
date Tue, 14 Jul 2009 12:54:37 +0400
parents
children 16ada169ca75
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/Form/Filter/Mandatory.pm	Tue Jul 14 12:54:37 2009 +0400
@@ -0,0 +1,34 @@
+package Form::Filter::Mandatory;
+use strict;
+use Common;
+use base qw(Form::Filter);
+
+sub SUPPORTED_CONTEXT { Form::Filter::CTX_SINGLE | Form::Filter::CTX_SET }
+
+sub Invoke {
+    my ($this,$target,$context,$schemaTarget,$parent) = @_;
+    
+    my @list;
+    if ($context & Form::Filter::CTX_SET) {
+        @list = @{$target || []};
+    } elsif ($context & (Form::Filter::CTX_SINGLE | Form::Filter::CTX_EXISTENT)) {
+        @list = ($target);
+    }
+    
+    foreach my $object (@list) {
+        if (defined $object and not $object->isEmpty) {
+            return Form::FilterResult->new(
+                State => Form::FilterResult::STATE_SUCCESS_STAY
+            );
+        }
+    }
+    
+    return Form::FilterResult->new(
+        State => Form::FilterResult::STATE_ERROR,
+        Message => $this->FormatMessage($schemaTarget),
+        Target => $schemaTarget,
+        Container => $parent
+    );
+}
+
+1;
\ No newline at end of file