Mercurial > pub > Impl
annotate Lib/IMPL/Object/List.pm @ 166:4267a2ac3d46
Added Class::Template,
Rewritten SQL::Schema
'use parent' directive instead of 'use base'
author | wizard |
---|---|
date | Sat, 23 Apr 2011 23:12:06 +0400 |
parents | 6ce1f052b90a |
children | 1f7a6d762394 |
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 { | |
9 return wantarray ? @{$_[0]} : $_[0]; | |
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 | |
45 sub InsertAt { | |
46 my ($this,$index,@val) = @_; | |
47 | |
48 splice @$this,($index||0),0,@val; | |
49 } | |
50 | |
51 sub RemoveAt { | |
52 my ($this,$index,$count) = @_; | |
53 | |
54 $count ||= 1; | |
55 | |
56 return splice @$this,$index,$count; | |
57 } | |
58 | |
59 sub RemoveItem { | |
60 my ($this,$item) = @_; | |
61 | |
62 @$this = grep $_ != $item, @$this; | |
63 | |
64 return $this; | |
65 } | |
66 | |
67 sub RemoveItemStr { | |
68 my ($this,$item) = @_; | |
69 | |
70 @$this = grep $_ ne $item, @$this; | |
71 | |
72 return $this; | |
73 } | |
74 | |
151
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
75 sub FindItem { |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
76 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
|
77 |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
78 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
|
79 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
|
80 } |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
81 return undef; |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
82 } |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
83 |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
84 sub FindItemStr { |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
85 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
|
86 |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
87 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
|
88 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
|
89 } |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
90 return undef; |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
91 } |
e36ffd8c29db
Fixed major bug in conversion from a POST request to the DOM document (when instanceId == 0)
wizard
parents:
63
diff
changeset
|
92 |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
93 sub save { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
94 my ($this,$ctx) = @_; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
95 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
96 $ctx->AddVar( item => $_ ) foreach @$this; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
97 } |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
98 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
99 sub restore { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
100 my ($class,$data,$surrogate) = @_; |
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 my $i = 0; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
103 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
104 if ($surrogate) { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
105 @$surrogate = grep { ($i++)%2 } @$data; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
106 } else { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
107 $surrogate = $class->new([grep { ($i++)%2 } @$data]); |
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 return $surrogate; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
111 } |
49 | 112 |
113 1; |