line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# vim:ts=4 sw=4 |
2
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
# Name : Class::STL::Element.pm |
4
|
|
|
|
|
|
|
# Created : 22 February 2006 |
5
|
|
|
|
|
|
|
# Author : Mario Gaffiero (gaffie) |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright 2006-2007 Mario Gaffiero. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# This file is part of Class::STL::Containers(TM). |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Class::STL::Containers is free software; you can redistribute it and/or modify |
12
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
13
|
|
|
|
|
|
|
# the Free Software Foundation; version 2 of the License. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# Class::STL::Containers is distributed in the hope that it will be useful, |
16
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
|
|
|
|
# GNU General Public License for more details. |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
21
|
|
|
|
|
|
|
# along with Class::STL::Containers; if not, write to the Free Software |
22
|
|
|
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
23
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
# Modification History |
25
|
|
|
|
|
|
|
# When Version Who What |
26
|
|
|
|
|
|
|
# 14/03/2006 0.02 mg Fixed Class::STL::Element->new() function. |
27
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
28
|
|
|
|
|
|
|
# TO DO: |
29
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
30
|
|
|
|
|
|
|
require 5.005_62; |
31
|
7
|
|
|
7
|
|
45
|
use strict; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
234
|
|
32
|
7
|
|
|
7
|
|
36
|
use warnings; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
196
|
|
33
|
7
|
|
|
7
|
|
324
|
use vars qw($VERSION $BUILD); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
400
|
|
34
|
7
|
|
|
7
|
|
4961
|
use Class::STL::ClassMembers::DataMember; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
342
|
|
35
|
7
|
|
|
7
|
|
5077
|
use Class::STL::ClassMembers::FunctionMember; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
97
|
|
36
|
|
|
|
|
|
|
$VERSION = '0.19'; |
37
|
|
|
|
|
|
|
$BUILD = 'Saturday May 6 17:08:34 GMT 2006'; |
38
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
39
|
|
|
|
|
|
|
{ |
40
|
|
|
|
|
|
|
package Class::STL::Element; |
41
|
7
|
|
|
7
|
|
417
|
use UNIVERSAL qw(isa can); |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
41
|
|
42
|
7
|
|
|
7
|
|
4309
|
use Carp qw(confess); |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
679
|
|
43
|
7
|
|
|
|
|
41
|
use Class::STL::ClassMembers qw( data ), |
44
|
|
|
|
|
|
|
Class::STL::ClassMembers::DataMember->new(name => 'data_type', default => 'string', |
45
|
7
|
|
|
7
|
|
42
|
validate => '^(string|array|numeric|ref)$'); |
|
7
|
|
|
|
|
13
|
|
46
|
7
|
|
|
7
|
|
5553
|
use Class::STL::ClassMembers::Constructor; |
|
7
|
|
|
|
|
24
|
|
|
7
|
|
|
|
|
61
|
|
47
|
|
|
|
|
|
|
sub new_extra # static function |
48
|
|
|
|
|
|
|
{ |
49
|
13
|
|
|
13
|
0
|
24
|
my $self = shift; |
50
|
13
|
|
|
|
|
39
|
while (@_) |
51
|
|
|
|
|
|
|
{ |
52
|
25
|
|
|
|
|
35
|
my $p = shift; |
53
|
25
|
50
|
33
|
|
|
68
|
if (!ref($p) && exists(${$self->members()}{$p})) |
|
25
|
0
|
0
|
|
|
1039
|
|
54
|
|
|
|
|
|
|
{ |
55
|
25
|
|
|
|
|
152
|
shift; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif (!ref($p) && scalar @_ != 0) { |
58
|
0
|
|
|
|
|
0
|
shift; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
0
|
|
|
|
|
0
|
$self->data($p); # new() called. |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
13
|
|
|
|
|
1044
|
return $self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
sub eq # (element) |
67
|
|
|
|
|
|
|
{ |
68
|
8
|
|
|
8
|
0
|
21
|
my $self = shift; |
69
|
8
|
|
|
|
|
20
|
my $other = shift; |
70
|
8
|
100
|
33
|
|
|
273
|
return defined($self->data()) && ref($self->data()) && $self->data()->can('eq') |
|
|
50
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
71
|
|
|
|
|
|
|
? $self->data()->eq($other) |
72
|
|
|
|
|
|
|
: $self->data_type() eq 'string' |
73
|
|
|
|
|
|
|
? defined($self->data()) && defined($other->data()) && $self->data() eq $other->data() |
74
|
|
|
|
|
|
|
: defined($self->data()) && defined($other->data()) && $self->data() == $other->data(); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
sub ne # (element) |
77
|
|
|
|
|
|
|
{ |
78
|
2
|
|
|
2
|
0
|
6
|
my $self = shift; |
79
|
2
|
|
|
|
|
7
|
return !$self->eq(shift); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
sub gt # (element) |
82
|
|
|
|
|
|
|
{ |
83
|
1
|
|
|
1
|
0
|
4
|
my $self = shift; |
84
|
1
|
|
|
|
|
3
|
my $other = shift; |
85
|
1
|
50
|
33
|
|
|
39
|
return defined($self->data()) && ref($self->data()) && $self->data()->can('gt') |
|
|
50
|
0
|
|
|
|
|
|
|
|
33
|
|
|
|
|
86
|
|
|
|
|
|
|
? $self->data()->gt($other) |
87
|
|
|
|
|
|
|
: $self->data_type() eq 'string' |
88
|
|
|
|
|
|
|
? defined($self->data()) && defined($other->data()) && $self->data() gt $other->data() |
89
|
|
|
|
|
|
|
: defined($self->data()) && defined($other->data()) && $self->data() > $other->data(); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
sub lt # (element) |
92
|
|
|
|
|
|
|
{ |
93
|
3
|
|
|
3
|
0
|
5
|
my $self = shift; |
94
|
3
|
|
|
|
|
4
|
my $other = shift; |
95
|
3
|
50
|
33
|
|
|
95
|
return defined($self->data()) && ref($self->data()) && $self->data()->can('lt') |
|
|
50
|
0
|
|
|
|
|
|
|
|
66
|
|
|
|
|
96
|
|
|
|
|
|
|
? $self->data()->lt($other) |
97
|
|
|
|
|
|
|
: $self->data_type() eq 'string' |
98
|
|
|
|
|
|
|
? defined($self->data()) && defined($other->data()) && $self->data() lt $other->data() |
99
|
|
|
|
|
|
|
: defined($self->data()) && defined($other->data()) && $self->data() < $other->data(); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
sub ge # (element) |
102
|
|
|
|
|
|
|
{ |
103
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
104
|
1
|
|
|
|
|
2
|
my $other = shift; |
105
|
1
|
50
|
33
|
|
|
36
|
return defined($self->data()) && ref($self->data()) && $self->data()->can('ge') |
|
|
50
|
0
|
|
|
|
|
|
|
|
33
|
|
|
|
|
106
|
|
|
|
|
|
|
? $self->data()->ge($other) |
107
|
|
|
|
|
|
|
: $self->data_type() eq 'string' |
108
|
|
|
|
|
|
|
? defined($self->data()) && defined($other->data()) && $self->data() ge $other->data() |
109
|
|
|
|
|
|
|
: defined($self->data()) && defined($other->data()) && $self->data() >= $other->data(); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
sub le # (element) |
112
|
|
|
|
|
|
|
{ |
113
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
114
|
1
|
|
|
|
|
3
|
my $other = shift; |
115
|
1
|
50
|
33
|
|
|
38
|
return defined($self->data()) && ref($self->data()) && $self->data()->can('le') |
|
|
50
|
0
|
|
|
|
|
|
|
|
33
|
|
|
|
|
116
|
|
|
|
|
|
|
? $self->data()->le($other) |
117
|
|
|
|
|
|
|
: $self->data_type() eq 'string' |
118
|
|
|
|
|
|
|
? defined($self->data()) && defined($other->data()) && $self->data() le $other->data() |
119
|
|
|
|
|
|
|
: defined($self->data()) && defined($other->data()) && $self->data() <= $other->data(); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
sub cmp # (element) |
122
|
|
|
|
|
|
|
{ |
123
|
3
|
|
|
3
|
0
|
6
|
my $self = shift; |
124
|
3
|
|
|
|
|
5
|
my $other = shift; |
125
|
3
|
100
|
|
|
|
8
|
return $self->eq($other) ? 0 : $self->lt($other) ? -1 : 1; |
|
|
100
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
sub mod # (element) |
128
|
|
|
|
|
|
|
{ |
129
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
130
|
0
|
|
|
|
|
|
my $other = shift; |
131
|
0
|
0
|
0
|
|
|
|
return ref($self->data()) && $self->data()->can('mod') |
132
|
|
|
|
|
|
|
? $self->data()->mod($other) |
133
|
|
|
|
|
|
|
: $self->data($self->data() % $other->data()); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
sub add # (element) |
136
|
|
|
|
|
|
|
{ |
137
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
138
|
0
|
|
|
|
|
|
my $other = shift; |
139
|
0
|
0
|
0
|
|
|
|
return ref($self->data()) && $self->data()->can('add') |
140
|
|
|
|
|
|
|
? $self->data()->add($other) |
141
|
|
|
|
|
|
|
: $self->data($self->data() + $other->data()); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
sub subtract # (element) |
144
|
|
|
|
|
|
|
{ |
145
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
146
|
0
|
|
|
|
|
|
my $other = shift; |
147
|
0
|
0
|
0
|
|
|
|
return ref($self->data()) && $self->data()->can('subtract') |
148
|
|
|
|
|
|
|
? $self->data()->subtract($other) |
149
|
|
|
|
|
|
|
: $self->data($self->data() - $other->data()); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
sub mult # (element) |
152
|
|
|
|
|
|
|
{ |
153
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
154
|
0
|
|
|
|
|
|
my $other = shift; |
155
|
0
|
0
|
0
|
|
|
|
return ref($self->data()) && $self->data()->can('mult') |
156
|
|
|
|
|
|
|
? $self->data()->mult($other) |
157
|
|
|
|
|
|
|
: $self->data($self->data() * $other->data()); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
sub div # (element) |
160
|
|
|
|
|
|
|
{ |
161
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
162
|
0
|
|
|
|
|
|
my $other = shift; |
163
|
0
|
0
|
0
|
|
|
|
return ref($self->data()) && $self->data()->can('div') |
164
|
|
|
|
|
|
|
? $self->data()->div($other) |
165
|
|
|
|
|
|
|
: $self->data($self->data() / $other->data()); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
sub and # (element) |
168
|
|
|
|
|
|
|
{ |
169
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
170
|
0
|
|
|
|
|
|
my $other = shift; |
171
|
0
|
0
|
0
|
|
|
|
return ref($self->data()) && $self->data()->can('and') |
|
|
|
0
|
|
|
|
|
172
|
|
|
|
|
|
|
? $self->data()->and($other) |
173
|
|
|
|
|
|
|
: $self->data() && $other->data(); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
sub or # (element) |
176
|
|
|
|
|
|
|
{ |
177
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
178
|
0
|
|
|
|
|
|
my $other = shift; |
179
|
0
|
0
|
0
|
|
|
|
return ref($self->data()) && $self->data()->can('or') |
|
|
|
0
|
|
|
|
|
180
|
|
|
|
|
|
|
? $self->data()->or($other) |
181
|
|
|
|
|
|
|
: $self->data() || $other->data(); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
sub match # (element) |
184
|
|
|
|
|
|
|
{ |
185
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
186
|
0
|
|
|
|
|
|
my $other = shift; |
187
|
0
|
0
|
0
|
|
|
|
return ref($self->data()) && $self->data()->can('match') |
188
|
|
|
|
|
|
|
? $self->data()->match($other) |
189
|
0
|
|
|
|
|
|
: $self->data() =~ /@{[ $other->data() ]}/; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
sub match_ic # (element) |
192
|
|
|
|
|
|
|
{ |
193
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
194
|
0
|
|
|
|
|
|
my $other = shift; |
195
|
0
|
0
|
0
|
|
|
|
return ref($self->data()) && $self->data()->can('match_ic') |
196
|
|
|
|
|
|
|
? $self->data()->match_ic($other) |
197
|
0
|
|
|
|
|
|
: $self->data() =~ /@{[ $other->data() ]}/i; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
sub neg # (void) |
200
|
|
|
|
|
|
|
{ |
201
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
202
|
0
|
0
|
0
|
|
|
|
return ref($self->data()) && $self->data()->can('neg') |
203
|
|
|
|
|
|
|
? $self->data()->neg() |
204
|
|
|
|
|
|
|
: $self->data(-($self->data())); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
sub print # (void) |
207
|
|
|
|
|
|
|
{ |
208
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
209
|
0
|
0
|
0
|
|
|
|
return ref($self->data()) && $self->data()->can('print') |
210
|
|
|
|
|
|
|
? $self->data()->print() |
211
|
|
|
|
|
|
|
: $self->data(); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
215
|
|
|
|
|
|
|
1; |