diff Lib/Form/Filter.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.pm	Tue Jul 14 12:54:37 2009 +0400
@@ -0,0 +1,67 @@
+package Form::Filter;
+use strict;
+use Common;
+our @ISA = qw(Object);
+
+use constant {
+    CTX_SINGLE      => 1,   # çíà÷åíèå ïîëÿ
+    CTX_SET         => 2,   # ìíîæåñòâî çíà÷åíèé
+    CTX_EXISTENT    => 4    # òîëüêî ñóùåñòâóþùèå çíà÷åíèÿ
+};
+
+BEGIN {
+    DeclareProperty Name => ACCESS_READ;
+    DeclareProperty Message => ACCESS_READ;
+}
+
+sub CTOR {
+    my ($this,$name,$message) = @_;
+    $this->{$Name} = $name or die new Exception('A filter name is required');
+    $this->{$Message} = $message;
+}
+
+sub FormatMessage {
+    my ($this,$object) = @_;
+    
+    (my $message = $object->Attributes->{$this->{$Name}} || $this->{$Message} || ($Common::Debug ? "$this->{$Name}: %name%" : '')) =~ s{%(\w+(?:\.\w+)*)%}{
+        my $value = $object->Attributes->{$1} || ($Common::Debug ? $object->Name.'.'.$1 : '');
+    }ge;
+    
+    return $message;
+}
+
+package Form::FilterResult;
+use Common;
+our @ISA = qw(Object);
+
+use constant {
+    STATE_ERROR => 0,           # îøèáî÷íîå çíà÷åíèå
+    STATE_SUCCESS => 1,         # çíà÷åíèå êîððåêòíîå, ìîæíî ïðîäîëæàòü âûïîëíåíèå
+    STATE_SUCCESS_STOP => 2,    # çíà÷åíèå êîððåêòíîå, âûïîëíåíèå îñòàëüíûõ ôèëüòðîâ íå òðåáóåòñÿ
+    STATE_SUCCESS_STAY => 3     # çíà÷åíèå êîððåêòíîå, âûïîëíåíèå äàííîãî ôèëüòðà áîëåå íå òðåáóåòñÿ
+};
+
+BEGIN {
+    DeclareProperty State => ACCESS_READ;
+    DeclareProperty Message => ACCESS_READ;
+    DeclareProperty Target => ACCESS_READ;
+    DeclareProperty Container => ACCESS_READ;
+}
+
+sub CTOR {
+    my $this = shift;
+    $this->SUPER::CTOR(@_);
+    
+    UNIVERSAL::isa($this->{$Target},'Form::Item') or UNIVERSAL::isa($this->{$Container},'Form::Container') or die new Exception("Invalid Target or Container property") if $this->{$State} == STATE_ERROR;
+}
+
+sub Item {
+    my $this = shift;
+    
+    return ref $this->{$Target} ?
+        ($this->{$Target}->isa('Form::Item') ? $this->{$Target} : $this->{$Container}->Item( $this->{$Target}->isMulti ? $this->{$Target}->Name . '0' : $this->{$Target}->Name ) )
+        :
+        ($this->{$Target});
+}
+
+1;