comparison Lib/Form/Item.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::Item;
2 use strict;
3 use Common;
4 our @ISA = qw(Object);
5
6 BEGIN {
7 DeclareProperty Parent => ACCESS_READ;
8 DeclareProperty Form => ACCESS_READ;
9 DeclareProperty Id => ACCESS_READ;
10 DeclareProperty Attributes => ACCESS_ALL;
11 }
12
13 sub CTOR {
14 my ($this,$id,$form,$parent,$attrib) = @_;
15
16 $this->{$Id} = $id or die new Exception('An Id i required for the form item');
17 $this->{$Form} = $form or die new Exception('A form is required for the form item');
18 $this->{$Parent} = $parent;
19 $this->{$Attributes} = $attrib || {};
20 }
21
22 sub Name {
23 my ($this) = @_;
24 return $this->{$Id}->Name;
25 }
26
27 sub Navigate {
28 my ($this,$ItemId) = @_;
29
30 $ItemId or die new Exception("An item id is undefined");
31
32 return $this->NavigatePath([$ItemId->ToNAVPath]);
33 }
34
35 sub Item {
36 my ($this,$strId) = @_;
37
38 return $this->Navigate($this->Form->MakeItemId($strId,$this));
39 }
40
41 sub NavigatePath {
42 my ($this,$refPath) = @_;
43
44 my $ItemId = shift @$refPath or die new Exception("An item id is undefined");
45 my $current;
46
47 if ($ItemId->isa('Form::ItemId::Prev')) {
48 $this->{$Parent} or die new Exception('Can\'t navigate to upper level');
49 $current = $this->{$Parent};
50 } elsif ($ItemId->isa('Form::ItemId::Root')) {
51 $current = $this->{$Form};
52 } else {
53 $current = $this->ResolveItem($ItemId);
54 }
55
56 if (@$refPath > 0) {
57 die new Exception('The item not found', $ItemId->Canonical) if not $current;
58 return $current->NavigatePath($refPath);
59 } else {
60 return $current;
61 }
62 }
63
64 sub ResolveItem {
65 my ($this,$ItemId) = @_;
66
67 die new Exception('Item not found',$ItemId->Name);
68 }
69
70 sub Dispose {
71 my ($this) = @_;
72
73 undef %$this;
74
75 $this->SUPER::Dispose;
76 }
77
78
79 1;