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

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