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