Mercurial > pub > Impl
annotate Lib/IMPL/Object/List.pm @ 183:2184fa28b49e
IMPL::Web::View::TTLoader tests
author | cin |
---|---|
date | Wed, 28 Mar 2012 17:28:51 +0400 |
parents | 6148f89bb7bf |
children | 4d0e1962161c |
rev | line source |
---|---|
49 | 1 package IMPL::Object::List; |
2 use strict; | |
3 use warnings; | |
4 | |
166 | 5 use parent qw(IMPL::Object::ArrayObject); |
49 | 6 use IMPL::Exception; |
7 | |
8 sub as_list { | |
168 | 9 return $_[0]; |
49 | 10 } |
11 | |
12 sub CTOR { | |
13 my ($this,$data) = @_; | |
14 | |
15 if ($data) { | |
16 die new IMPL::InvalidArgumentException("The parameter should be a reference to an array") unless UNIVERSAL::isa($data,"ARRAY"); | |
17 @$this = @$data; | |
18 } | |
19 } | |
20 | |
21 sub Append { | |
22 push @{$_[0]}, @_[1 .. $#_]; | |
23 } | |
24 | |
163 | 25 sub AddLast { |
26 push @{$_[0]}, @_[1 .. $#_]; | |
27 } | |
28 | |
49 | 29 sub RemoveLast { |
30 return pop @{$_[0]}; | |
31 } | |
32 | |
33 sub AddFirst { | |
34 return unshift @{$_[0]}, $_[1]; | |
35 } | |
36 | |
37 sub RemoveFirst { | |
38 return shift @{$_[0]}; | |
39 } | |
40 | |
41 sub Count { | |
42 return scalar @{$_[0]}; | |
43 } | |
44 | |
167 | 45 sub Item { |
46 return $_[0]->[$_[1]]; | |
47 } | |
48 | |
49 | 49 sub InsertAt { |
50 my ($this,$index,@val) = @_; | |
51 | |
52 splice @$this,($index||0),0,@val; | |
53 } | |
54 | |
55 sub RemoveAt { | |
56 my ($this,$index,$count) = @_; | |
57 | |
58 $count ||= 1; | |
59 | |
60 return splice @$this,$index,$count; | |
61 } | |
62 | |
63 sub RemoveItem { | |
64 my ($this,$item) = @_; | |
65 | |
66 @$this = grep $_ != $item, @$this; | |
67 | |
68 return $this; | |
69 } | |
70 | |
71 sub RemoveItemStr { | |
72 my ($this,$item) = @_; | |
73 | |
74 @$this = grep $_ ne $item, @$this; | |
75 | |
76 return $this; | |
77 } | |
78 | |
151
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
79 sub FindItem { |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
80 my ($this,$item) = @_; |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
81 |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
82 for (my $i = 0; $i < @$this; $i++ ) { |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
83 return $i if $this->[$i] == $item |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
84 } |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
85 return undef; |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
86 } |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
87 |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
88 sub FindItemStr { |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
89 my ($this,$item) = @_; |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
90 |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
91 for (my $i = 0; $i < @$this; $i++ ) { |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
92 return $i if $this->[$i] eq $item |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
93 } |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
94 return undef; |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
95 } |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
96 |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
97 sub save { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
98 my ($this,$ctx) = @_; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
99 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
100 $ctx->AddVar( item => $_ ) foreach @$this; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
101 } |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
102 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
103 sub restore { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
104 my ($class,$data,$surrogate) = @_; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
105 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
106 my $i = 0; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
107 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
108 if ($surrogate) { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
109 @$surrogate = grep { ($i++)%2 } @$data; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
110 } else { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
111 $surrogate = $class->new([grep { ($i++)%2 } @$data]); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
112 } |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
113 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
114 return $surrogate; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
115 } |
49 | 116 |
117 1; |