annotate Lib/Form/Item.pm @ 4:e59f44f75f20

DOM - в разработке Testing - по мелочи Property - изменен механизм выбора имплементора
author Sergey
date Wed, 12 Aug 2009 17:36:07 +0400
parents 03e58a454b20
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 package Form::Item;
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 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 DeclareProperty Parent => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 DeclareProperty Form => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 DeclareProperty Id => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 DeclareProperty Attributes => ACCESS_ALL;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13 sub CTOR {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 my ($this,$id,$form,$parent,$attrib) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16 $this->{$Id} = $id or die new Exception('An Id i required for the form item');
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17 $this->{$Form} = $form or die new Exception('A form is required for the form item');
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18 $this->{$Parent} = $parent;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19 $this->{$Attributes} = $attrib || {};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22 sub Name {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24 return $this->{$Id}->Name;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27 sub Navigate {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28 my ($this,$ItemId) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 $ItemId or die new Exception("An item id is undefined");
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 return $this->NavigatePath([$ItemId->ToNAVPath]);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35 sub Item {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36 my ($this,$strId) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38 return $this->Navigate($this->Form->MakeItemId($strId,$this));
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41 sub NavigatePath {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42 my ($this,$refPath) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44 my $ItemId = shift @$refPath or die new Exception("An item id is undefined");
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45 my $current;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
46
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47 if ($ItemId->isa('Form::ItemId::Prev')) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48 $this->{$Parent} or die new Exception('Can\'t navigate to upper level');
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
49 $current = $this->{$Parent};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
50 } elsif ($ItemId->isa('Form::ItemId::Root')) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
51 $current = $this->{$Form};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
52 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
53 $current = $this->ResolveItem($ItemId);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
54 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
55
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
56 if (@$refPath > 0) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
57 die new Exception('The item not found', $ItemId->Canonical) if not $current;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
58 return $current->NavigatePath($refPath);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
59 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
60 return $current;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
61 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
62 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
63
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
64 sub ResolveItem {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
65 my ($this,$ItemId) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
66
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
67 die new Exception('Item not found',$ItemId->Name);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
68 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
69
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
70 sub Dispose {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
71 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
72
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
73 undef %$this;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
74
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
75 $this->SUPER::Dispose;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
76 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
77
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
78
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
79 1;