annotate Lib/IMPL/Object/List.pm @ 167:1f7a6d762394

SQL schema in progress
author sourcer
date Thu, 12 May 2011 08:57:19 +0400
parents 4267a2ac3d46
children 6148f89bb7bf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
1 package IMPL::Object::List;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
4
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 163
diff changeset
5 use parent qw(IMPL::Object::ArrayObject);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
6 use IMPL::Exception;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
7
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
8 sub as_list {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
9 return wantarray ? @{$_[0]} : $_[0];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
10 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
11
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
12 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
13 my ($this,$data) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
14
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
15 if ($data) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
16 die new IMPL::InvalidArgumentException("The parameter should be a reference to an array") unless UNIVERSAL::isa($data,"ARRAY");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
17 @$this = @$data;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
18 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
19 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
20
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
21 sub Append {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
22 push @{$_[0]}, @_[1 .. $#_];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
23 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
24
163
6ce1f052b90a temp commit
wizard
parents: 151
diff changeset
25 sub AddLast {
6ce1f052b90a temp commit
wizard
parents: 151
diff changeset
26 push @{$_[0]}, @_[1 .. $#_];
6ce1f052b90a temp commit
wizard
parents: 151
diff changeset
27 }
6ce1f052b90a temp commit
wizard
parents: 151
diff changeset
28
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
29 sub RemoveLast {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
30 return pop @{$_[0]};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
31 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
32
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
33 sub AddFirst {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
34 return unshift @{$_[0]}, $_[1];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
35 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
36
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
37 sub RemoveFirst {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
38 return shift @{$_[0]};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
39 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
40
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
41 sub Count {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
42 return scalar @{$_[0]};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
43 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
44
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 166
diff changeset
45 sub Item {
1f7a6d762394 SQL schema in progress
sourcer
parents: 166
diff changeset
46 return $_[0]->[$_[1]];
1f7a6d762394 SQL schema in progress
sourcer
parents: 166
diff changeset
47 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 166
diff changeset
48
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
49 sub InsertAt {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
50 my ($this,$index,@val) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
51
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
52 splice @$this,($index||0),0,@val;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
53 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
54
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
55 sub RemoveAt {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
56 my ($this,$index,$count) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
57
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
58 $count ||= 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
59
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
60 return splice @$this,$index,$count;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
61 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
62
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
63 sub RemoveItem {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
64 my ($this,$item) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
65
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
66 @$this = grep $_ != $item, @$this;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
67
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
68 return $this;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
69 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
70
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
71 sub RemoveItemStr {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
72 my ($this,$item) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
73
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
74 @$this = grep $_ ne $item, @$this;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
75
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
76 return $this;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
77 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
116
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
117 1;