comparison Lib/Form/Filter.pm @ 0:03e58a454b20

Создан репозитарий
author Sergey
date Tue, 14 Jul 2009 12:54:37 +0400
parents
children 16ada169ca75
comparison
equal deleted inserted replaced
-1:000000000000 0:03e58a454b20
1 package Form::Filter;
2 use strict;
3 use Common;
4 our @ISA = qw(Object);
5
6 use constant {
7 CTX_SINGLE => 1, # çíà÷åíèå ïîëÿ
8 CTX_SET => 2, # ìíîæåñòâî çíà÷åíèé
9 CTX_EXISTENT => 4 # òîëüêî ñóùåñòâóþùèå çíà÷åíèÿ
10 };
11
12 BEGIN {
13 DeclareProperty Name => ACCESS_READ;
14 DeclareProperty Message => ACCESS_READ;
15 }
16
17 sub CTOR {
18 my ($this,$name,$message) = @_;
19 $this->{$Name} = $name or die new Exception('A filter name is required');
20 $this->{$Message} = $message;
21 }
22
23 sub FormatMessage {
24 my ($this,$object) = @_;
25
26 (my $message = $object->Attributes->{$this->{$Name}} || $this->{$Message} || ($Common::Debug ? "$this->{$Name}: %name%" : '')) =~ s{%(\w+(?:\.\w+)*)%}{
27 my $value = $object->Attributes->{$1} || ($Common::Debug ? $object->Name.'.'.$1 : '');
28 }ge;
29
30 return $message;
31 }
32
33 package Form::FilterResult;
34 use Common;
35 our @ISA = qw(Object);
36
37 use constant {
38 STATE_ERROR => 0, # îøèáî÷íîå çíà÷åíèå
39 STATE_SUCCESS => 1, # çíà÷åíèå êîððåêòíîå, ìîæíî ïðîäîëæàòü âûïîëíåíèå
40 STATE_SUCCESS_STOP => 2, # çíà÷åíèå êîððåêòíîå, âûïîëíåíèå îñòàëüíûõ ôèëüòðîâ íå òðåáóåòñÿ
41 STATE_SUCCESS_STAY => 3 # çíà÷åíèå êîððåêòíîå, âûïîëíåíèå äàííîãî ôèëüòðà áîëåå íå òðåáóåòñÿ
42 };
43
44 BEGIN {
45 DeclareProperty State => ACCESS_READ;
46 DeclareProperty Message => ACCESS_READ;
47 DeclareProperty Target => ACCESS_READ;
48 DeclareProperty Container => ACCESS_READ;
49 }
50
51 sub CTOR {
52 my $this = shift;
53 $this->SUPER::CTOR(@_);
54
55 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;
56 }
57
58 sub Item {
59 my $this = shift;
60
61 return ref $this->{$Target} ?
62 ($this->{$Target}->isa('Form::Item') ? $this->{$Target} : $this->{$Container}->Item( $this->{$Target}->isMulti ? $this->{$Target}->Name . '0' : $this->{$Target}->Name ) )
63 :
64 ($this->{$Target});
65 }
66
67 1;