annotate Lib/IMPL/Object/List.pm @ 8:fffb153be599

DOM Schema
author Sergey
date Tue, 25 Aug 2009 17:36:37 +0400
parents e59f44f75f20
children 75980091813b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
78cd38551534 in develop
Sergey
parents:
diff changeset
1 package IMPL::Object::List;
78cd38551534 in develop
Sergey
parents:
diff changeset
2 use strict;
78cd38551534 in develop
Sergey
parents:
diff changeset
3 use warnings;
78cd38551534 in develop
Sergey
parents:
diff changeset
4
78cd38551534 in develop
Sergey
parents:
diff changeset
5 use base qw(IMPL::Object::ArrayObject);
3
2e546a5175dd in developing
Sergey
parents: 2
diff changeset
6 use IMPL::Exception;
2
78cd38551534 in develop
Sergey
parents:
diff changeset
7
78cd38551534 in develop
Sergey
parents:
diff changeset
8 sub as_list {
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
9 return wantarray ? @{$_[0]} : $_[0];
2
78cd38551534 in develop
Sergey
parents:
diff changeset
10 }
78cd38551534 in develop
Sergey
parents:
diff changeset
11
3
2e546a5175dd in developing
Sergey
parents: 2
diff changeset
12 sub CTOR {
2e546a5175dd in developing
Sergey
parents: 2
diff changeset
13 my ($this,$data) = @_;
2e546a5175dd in developing
Sergey
parents: 2
diff changeset
14
2e546a5175dd in developing
Sergey
parents: 2
diff changeset
15 if ($data) {
2e546a5175dd in developing
Sergey
parents: 2
diff changeset
16 die new IMPL::InvalidArgumentException("The parameter should be a reference to an array") unless UNIVERSAL::isa($data,"ARRAY");
2e546a5175dd in developing
Sergey
parents: 2
diff changeset
17 @$this = @$data;
2e546a5175dd in developing
Sergey
parents: 2
diff changeset
18 }
2e546a5175dd in developing
Sergey
parents: 2
diff changeset
19 }
2e546a5175dd in developing
Sergey
parents: 2
diff changeset
20
2
78cd38551534 in develop
Sergey
parents:
diff changeset
21 sub Append {
78cd38551534 in develop
Sergey
parents:
diff changeset
22 push @{$_[0]}, @_{1 .. @$_-1};
78cd38551534 in develop
Sergey
parents:
diff changeset
23 }
78cd38551534 in develop
Sergey
parents:
diff changeset
24
78cd38551534 in develop
Sergey
parents:
diff changeset
25 sub RemoveLast {
78cd38551534 in develop
Sergey
parents:
diff changeset
26 return pop @{$_[0]};
78cd38551534 in develop
Sergey
parents:
diff changeset
27 }
78cd38551534 in develop
Sergey
parents:
diff changeset
28
78cd38551534 in develop
Sergey
parents:
diff changeset
29 sub AddFirst {
78cd38551534 in develop
Sergey
parents:
diff changeset
30 return unshift @{$_[0]}, $_[1];
78cd38551534 in develop
Sergey
parents:
diff changeset
31 }
78cd38551534 in develop
Sergey
parents:
diff changeset
32
78cd38551534 in develop
Sergey
parents:
diff changeset
33 sub RemoveFirst {
78cd38551534 in develop
Sergey
parents:
diff changeset
34 return shift @{$_[0]};
78cd38551534 in develop
Sergey
parents:
diff changeset
35 }
78cd38551534 in develop
Sergey
parents:
diff changeset
36
78cd38551534 in develop
Sergey
parents:
diff changeset
37 sub Count {
78cd38551534 in develop
Sergey
parents:
diff changeset
38 return scalar @{$_[0]};
78cd38551534 in develop
Sergey
parents:
diff changeset
39 }
78cd38551534 in develop
Sergey
parents:
diff changeset
40
78cd38551534 in develop
Sergey
parents:
diff changeset
41 sub InsertAt {
78cd38551534 in develop
Sergey
parents:
diff changeset
42 my ($this,$index,@val) = @_;
78cd38551534 in develop
Sergey
parents:
diff changeset
43
78cd38551534 in develop
Sergey
parents:
diff changeset
44 splice @$this,$index,0,@val;
78cd38551534 in develop
Sergey
parents:
diff changeset
45 }
78cd38551534 in develop
Sergey
parents:
diff changeset
46
78cd38551534 in develop
Sergey
parents:
diff changeset
47 sub RemoveAt {
78cd38551534 in develop
Sergey
parents:
diff changeset
48 my ($this,$index,$count) = @_;
78cd38551534 in develop
Sergey
parents:
diff changeset
49
78cd38551534 in develop
Sergey
parents:
diff changeset
50 $count ||= 1;
78cd38551534 in develop
Sergey
parents:
diff changeset
51
78cd38551534 in develop
Sergey
parents:
diff changeset
52 return splice @$this,$index,$count;
78cd38551534 in develop
Sergey
parents:
diff changeset
53 }
78cd38551534 in develop
Sergey
parents:
diff changeset
54
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
55 sub RemoveItem {
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
56 my ($this,$item) = @_;
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
57
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
58 @$this = grep $_ != $item, @$this;
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
59
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
60 return $this;
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
61 }
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
62
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
63 sub RemoveItemStr {
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
64 my ($this,$item) = @_;
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
65
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
66 @$this = grep $_ ne $item, @$this;
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
67
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
68 return $this;
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
69 }
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
70
e59f44f75f20 DOM - в разработке
Sergey
parents: 3
diff changeset
71
2
78cd38551534 in develop
Sergey
parents:
diff changeset
72 1;