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
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
405
cd6c6e61d442 Working on DI container
cin
parents: 278
diff changeset
5 use Carp qw(confess);
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 163
diff changeset
6 use parent qw(IMPL::Object::ArrayObject);
278
4ddb27ff4a0b core refactoring
cin
parents: 194
diff changeset
7 require IMPL::Exception;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
8
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
9 sub as_list {
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
10 return $_[0];
49
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
13 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
14 my ($this,$data) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
15
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
16 if ($data) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
17 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
18 @$this = @$data;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
22 sub Append {
405
cd6c6e61d442 Working on DI container
cin
parents: 278
diff changeset
23 confess "Appen method is obsolete use Push instead";
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
24 push @{$_[0]}, @_[1 .. $#_];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
25 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
26
405
cd6c6e61d442 Working on DI container
cin
parents: 278
diff changeset
27 sub Push {
cd6c6e61d442 Working on DI container
cin
parents: 278
diff changeset
28 push @{$_[0]}, @_[1 .. $#_];
cd6c6e61d442 Working on DI container
cin
parents: 278
diff changeset
29 }
cd6c6e61d442 Working on DI container
cin
parents: 278
diff changeset
30
163
6ce1f052b90a temp commit
wizard
parents: 151
diff changeset
31 sub AddLast {
405
cd6c6e61d442 Working on DI container
cin
parents: 278
diff changeset
32 confess "Appen method is obsolete use Push instead";
163
6ce1f052b90a temp commit
wizard
parents: 151
diff changeset
33 push @{$_[0]}, @_[1 .. $#_];
6ce1f052b90a temp commit
wizard
parents: 151
diff changeset
34 }
6ce1f052b90a temp commit
wizard
parents: 151
diff changeset
35
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
36 sub RemoveLast {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
37 return pop @{$_[0]};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
38 }
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 sub AddFirst {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
41 return unshift @{$_[0]}, $_[1];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
42 }
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 sub RemoveFirst {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
45 return shift @{$_[0]};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
46 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
47
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
48 sub Count {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
49 return scalar @{$_[0]};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
50 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
51
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 166
diff changeset
52 sub Item {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
53 return $_[0]->[$_[1]];
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 166
diff changeset
54 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 166
diff changeset
55
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
56 sub InsertAt {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
57 my ($this,$index,@val) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
58
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
59 splice @$this,($index||0),0,@val;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
60 }
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 sub RemoveAt {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
63 my ($this,$index,$count) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
64
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
65 $count ||= 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
66
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
67 return splice @$this,$index,$count;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
68 }
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 sub RemoveItem {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
71 my ($this,$item) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
72
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
73 @$this = grep $_ != $item, @$this;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
74
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
75 return $this;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
76 }
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 sub RemoveItemStr {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
79 my ($this,$item) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
80
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
81 @$this = grep $_ ne $item, @$this;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
82
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
83 return $this;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
84 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
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
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
87 my ($this,$item) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
88
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
89 for (my $i = 0; $i < @$this; $i++ ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
90 return $i if $this->[$i] == $item
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
91 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
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
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
96 my ($this,$item) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
97
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
98 for (my $i = 0; $i < @$this; $i++ ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
99 return $i if $this->[$i] eq $item
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
100 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
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
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
105 my ($this,$ctx) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
106
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
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
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
111 my ($class,$data,$surrogate) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
112
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
113 my $i = 0;
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
114
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
115 if ($surrogate) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
116 @$surrogate = grep { ($i++)%2 } @$data;
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
117 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
118 $surrogate = $class->new([grep { ($i++)%2 } @$data]);
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
119 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
120
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
121 return $surrogate;
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 49
diff changeset
122 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
123
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
124 1;