comparison Lib/IMPL/Object/List.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents 6148f89bb7bf
children 4ddb27ff4a0b
comparison
equal deleted inserted replaced
193:8e8401c0aea4 194:4d0e1962161c
41 sub Count { 41 sub Count {
42 return scalar @{$_[0]}; 42 return scalar @{$_[0]};
43 } 43 }
44 44
45 sub Item { 45 sub Item {
46 return $_[0]->[$_[1]]; 46 return $_[0]->[$_[1]];
47 } 47 }
48 48
49 sub InsertAt { 49 sub InsertAt {
50 my ($this,$index,@val) = @_; 50 my ($this,$index,@val) = @_;
51 51
75 75
76 return $this; 76 return $this;
77 } 77 }
78 78
79 sub FindItem { 79 sub FindItem {
80 my ($this,$item) = @_; 80 my ($this,$item) = @_;
81 81
82 for (my $i = 0; $i < @$this; $i++ ) { 82 for (my $i = 0; $i < @$this; $i++ ) {
83 return $i if $this->[$i] == $item 83 return $i if $this->[$i] == $item
84 } 84 }
85 return undef; 85 return undef;
86 } 86 }
87 87
88 sub FindItemStr { 88 sub FindItemStr {
89 my ($this,$item) = @_; 89 my ($this,$item) = @_;
90 90
91 for (my $i = 0; $i < @$this; $i++ ) { 91 for (my $i = 0; $i < @$this; $i++ ) {
92 return $i if $this->[$i] eq $item 92 return $i if $this->[$i] eq $item
93 } 93 }
94 return undef; 94 return undef;
95 } 95 }
96 96
97 sub save { 97 sub save {
98 my ($this,$ctx) = @_; 98 my ($this,$ctx) = @_;
99 99
100 $ctx->AddVar( item => $_ ) foreach @$this; 100 $ctx->AddVar( item => $_ ) foreach @$this;
101 } 101 }
102 102
103 sub restore { 103 sub restore {
104 my ($class,$data,$surrogate) = @_; 104 my ($class,$data,$surrogate) = @_;
105 105
106 my $i = 0; 106 my $i = 0;
107 107
108 if ($surrogate) { 108 if ($surrogate) {
109 @$surrogate = grep { ($i++)%2 } @$data; 109 @$surrogate = grep { ($i++)%2 } @$data;
110 } else { 110 } else {
111 $surrogate = $class->new([grep { ($i++)%2 } @$data]); 111 $surrogate = $class->new([grep { ($i++)%2 } @$data]);
112 } 112 }
113 113
114 return $surrogate; 114 return $surrogate;
115 } 115 }
116 116
117 1; 117 1;