line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################# |
2
|
|
|
|
|
|
|
## Name: Base.pm |
3
|
|
|
|
|
|
|
## Purpose: Base class for HPLOO classes. |
4
|
|
|
|
|
|
|
## Author: Graciliano M. P. |
5
|
|
|
|
|
|
|
## Modified by: |
6
|
|
|
|
|
|
|
## Created: 30/10/2004 |
7
|
|
|
|
|
|
|
## RCS-ID: |
8
|
|
|
|
|
|
|
## Copyright: (c) 2004 Graciliano M. P. |
9
|
|
|
|
|
|
|
## Licence: This program is free software; you can redistribute it and/or |
10
|
|
|
|
|
|
|
## modify it under the same terms as Perl itself |
11
|
|
|
|
|
|
|
############################################################################# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Class::HPLOO::Base ; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
31
|
use 5.006 ; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
16
|
1
|
|
|
1
|
|
5
|
use strict qw(vars) ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION $SYNTAX @ISA) ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1686
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$VERSION = '0.17'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
############ |
23
|
|
|
|
|
|
|
# EXPORTER # |
24
|
|
|
|
|
|
|
############ |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
require Exporter; |
27
|
|
|
|
|
|
|
@ISA = qw(Exporter UNIVERSAL) ; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our @EXPORT = qw(SUPER new GET_CLASS_HPLOO_HASH CLASS_HPLOO_TIE_KEYS ATTRS CLASS_HPLOO_ATTR CLASS_HPLOO_ATTR_TYPE) ; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our @EXPORT_OK = @EXPORT ; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
######################## |
34
|
|
|
|
|
|
|
# GET_CLASS_HPLOO_HASH # |
35
|
|
|
|
|
|
|
######################## |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub GET_CLASS_HPLOO_HASH { |
38
|
1
|
|
33
|
1
|
0
|
4
|
my $pack = ref($_[0]) || ($_[1] ? $_[1] : $_[0]) ; |
39
|
1
|
|
|
|
|
1
|
return \%{$pack . '::CLASS_HPLOO'} ; |
|
1
|
|
|
|
|
4
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
######### |
43
|
|
|
|
|
|
|
# SUPER # |
44
|
|
|
|
|
|
|
######### |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub SUPER { |
47
|
6
|
|
|
6
|
0
|
27
|
my ($prev_pack , undef , undef , $sub0) = caller(1) ; |
48
|
6
|
50
|
|
|
|
21
|
$prev_pack = undef if $prev_pack eq 'Class::HPLOO::Base' ; |
49
|
|
|
|
|
|
|
|
50
|
6
|
|
|
|
|
28
|
my ($pack,$sub) = ( $sub0 =~ /^(?:(.*?)::|)(\w+)$/ ); |
51
|
|
|
|
|
|
|
|
52
|
6
|
50
|
|
|
|
113
|
my $sub_is_new_hploo = $sub0 =~ /^(.*?(?:::)?$sub)\::$sub$/ ? 1 : undef ; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
##print "SUPER[$sub_is_new_hploo]>> @_ >> $pack,$sub >> $prev_pack\n" ; |
55
|
|
|
|
|
|
|
|
56
|
6
|
0
|
33
|
|
|
32
|
unshift(@_ , $prev_pack) if ( $sub_is_new_hploo && $prev_pack && ((!ref($_[0]) && $_[0] ne $prev_pack && !UNIVERSAL::isa($_[0] , $prev_pack)) || (ref($_[0]) && !UNIVERSAL::isa($_[0] , $prev_pack)) ) ) ; |
|
|
|
0
|
|
|
|
|
|
|
|
33
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
6
|
50
|
|
|
|
7
|
if ( defined @{"$pack\::ISA"} ) { |
|
6
|
|
|
|
|
24
|
|
59
|
6
|
50
|
|
|
|
19
|
my $isa_sub = ISA_FIND_NEW($pack, ($sub_is_new_hploo?'new':$sub) ,1) ; |
60
|
|
|
|
|
|
|
|
61
|
6
|
|
|
|
|
27
|
my ($sub_name) = ( $isa_sub =~ /(\w+)$/gi ); |
62
|
6
|
100
|
66
|
|
|
95
|
if ( $sub0 ne $isa_sub && !ref($_[0]) && $isa_sub =~ /^(.*?(?:::)?$sub_name)\::$sub_name$/ ) { |
|
|
|
66
|
|
|
|
|
63
|
3
|
|
|
|
|
18
|
@_ = ( bless({},$_[0]) , @_[1..$#_] ) ; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
6
|
50
|
33
|
|
|
17
|
if ( $sub0 eq $isa_sub && UNIVERSAL::isa($_[0] , $pack) ) { |
67
|
0
|
|
|
|
|
0
|
my @isa = Class::HPLOO::Base::FIND_SUPER_WALK( ref($_[0]) , $pack ) ; |
68
|
0
|
|
|
|
|
0
|
my $pk = $isa[-1] ; |
69
|
0
|
0
|
|
|
|
0
|
if ( $sub_is_new_hploo ) { |
70
|
0
|
0
|
|
|
|
0
|
if ( UNIVERSAL::isa($pk , 'Class::HPLOO::Base') ) { |
71
|
0
|
|
|
|
|
0
|
($sub) = ( $pk =~ /(\w+)$/gi ); |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
0
|
else { $sub = 'new' ;} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
my $isa_sub = $pk->can($sub) ; |
77
|
|
|
|
|
|
|
##print "SUPER WALK>> $pk , $sub >> $isa_sub\n" ; |
78
|
0
|
0
|
|
|
|
0
|
return &$isa_sub( ARGS_WRAPPER(@_) ) if $isa_sub ; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
##print "SUPER ISA>> $isa_sub >> $pack >> ". join(',',@{"$pack\::ISA"}) ."\n" ; |
82
|
6
|
50
|
33
|
|
|
57
|
return &$isa_sub(@_) if $isa_sub && defined &$isa_sub && $sub0 ne $isa_sub ; |
|
|
|
33
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
0
|
$sub = $sub_is_new_hploo ? 'new' : $sub ; |
86
|
|
|
|
|
|
|
##print "SUPER CALL>> $pack $sub >> @_\n" ; |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
0
|
die("Can't find SUPER method for $sub0!") if "$pack\::$sub" eq $sub0 ; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
return &{"$pack\::$sub"}(@_) ; |
|
0
|
|
|
|
|
0
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
################### |
94
|
|
|
|
|
|
|
# FIND_SUPER_WALK # |
95
|
|
|
|
|
|
|
################### |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub FIND_SUPER_WALK { |
98
|
0
|
|
|
0
|
0
|
0
|
my $class_main = shift ; |
99
|
0
|
|
|
|
|
0
|
my $class_end = shift ; |
100
|
0
|
|
|
|
|
0
|
my $only_stak = shift ; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
my (@stack) ; |
103
|
0
|
|
0
|
|
|
0
|
my $stack = $only_stak || {} ; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
##print "FIND>> $class_main , $class_end\n" ; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
my $found ; |
108
|
0
|
|
|
|
|
0
|
foreach my $isa_i ( @{"$class_main\::ISA"} ) { |
|
0
|
|
|
|
|
0
|
|
109
|
0
|
0
|
|
|
|
0
|
next if $$stack{$isa_i}++ ; |
110
|
0
|
0
|
|
|
|
0
|
$found = 1 if $isa_i eq $class_end ; |
111
|
0
|
|
|
|
|
0
|
push(@stack , $isa_i , FIND_SUPER_WALK($isa_i , $class_end , $stack) ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
0
|
return ($found ? @stack : ()) if $only_stak ; |
|
|
0
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
return @stack ; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
################ |
119
|
|
|
|
|
|
|
# ISA_FIND_NEW # |
120
|
|
|
|
|
|
|
################ |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub ISA_FIND_NEW { |
123
|
12
|
|
|
12
|
0
|
17
|
my $pack = shift ; |
124
|
12
|
|
|
|
|
13
|
my $sub = shift ; |
125
|
12
|
|
|
|
|
11
|
my $look_deep = shift ; |
126
|
12
|
|
|
|
|
13
|
my $count = shift ; |
127
|
12
|
50
|
|
|
|
28
|
return if $count > 100 ; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
##print "ISA_FIND_NEW>> $pack >> $sub\n" ; |
130
|
|
|
|
|
|
|
|
131
|
12
|
|
|
|
|
13
|
my ($sub_name) ; |
132
|
12
|
50
|
|
|
|
35
|
if ( UNIVERSAL::isa($pack , 'Class::HPLOO::Base') ) { |
133
|
12
|
50
|
|
|
|
51
|
($sub_name) = $sub eq 'new' ? ( $pack =~ /(\w+)$/ ) : ($sub) ; |
134
|
|
|
|
|
|
|
} |
135
|
0
|
|
|
|
|
0
|
else { $sub_name = $sub ;} |
136
|
|
|
|
|
|
|
|
137
|
12
|
|
|
|
|
32
|
my $isa_sub = "$pack\::$sub_name" ; |
138
|
|
|
|
|
|
|
|
139
|
12
|
100
|
66
|
|
|
76
|
if ( $look_deep || !defined &$isa_sub ) { |
140
|
6
|
|
|
|
|
5
|
foreach my $isa_i ( @{"$pack\::ISA"} ) { |
|
6
|
|
|
|
|
16
|
|
141
|
6
|
50
|
33
|
|
|
28
|
next if $isa_i eq $pack || $isa_i eq 'Class::HPLOO::Base' ; |
142
|
6
|
50
|
|
|
|
10
|
last if $isa_i eq 'UNIVERSAL' ; |
143
|
6
|
|
|
|
|
16
|
$isa_sub = ISA_FIND_NEW($isa_i , $sub , 0 , $count+1) ; |
144
|
6
|
50
|
|
|
|
14
|
last if $isa_sub ; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
12
|
50
|
|
|
|
30
|
$isa_sub = undef if !defined &$isa_sub ; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
##print "%%> $pack >> $isa_sub\n" ; |
151
|
12
|
|
|
|
|
23
|
return $isa_sub ; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
################## |
155
|
|
|
|
|
|
|
# NEW_CALL_BEGIN # |
156
|
|
|
|
|
|
|
################## |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub new_call_BEGIN { |
159
|
1
|
50
|
|
1
|
0
|
2
|
my $class = shift ; $class = ref($class) if ref($class) ; |
|
1
|
|
|
|
|
8
|
|
160
|
1
|
|
|
|
|
2
|
my $this = $class ; |
161
|
|
|
|
|
|
|
|
162
|
1
|
|
|
|
|
3
|
my @isas = \@{"$class\::ISA"} ; |
|
1
|
|
|
|
|
5
|
|
163
|
|
|
|
|
|
|
|
164
|
1
|
|
|
|
|
3
|
foreach my $isas_i ( @isas ) { |
165
|
2
|
|
|
|
|
5
|
foreach my $ISA_i ( @$isas_i ) { |
166
|
4
|
100
|
66
|
|
|
3
|
if ( defined @{"$ISA_i\::ISA"} && @{"$ISA_i\::ISA"} > 2 ) { |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
19
|
|
167
|
1
|
|
|
|
|
2
|
push(@isas , \@{"$ISA_i\::ISA"}) ; |
|
1
|
|
|
|
|
3
|
|
168
|
|
|
|
|
|
|
} |
169
|
4
|
100
|
|
|
|
13
|
last if $ISA_i eq 'Class::HPLOO::Base' ; |
170
|
2
|
|
|
|
|
2
|
my $ret ; |
171
|
2
|
|
|
|
|
7
|
my ($sub) = ( $ISA_i =~ /(\w+)$/ ); |
172
|
2
|
|
|
|
|
5
|
$sub = "$ISA_i\::$sub\_BEGIN" ; |
173
|
2
|
50
|
|
|
|
12
|
$ret = &$sub($this,@_) if defined &$sub ; |
174
|
2
|
50
|
33
|
|
|
8
|
$this = $ret if $ret && UNIVERSAL::isa($ret,$class) ; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
1
|
|
|
|
|
4
|
return $this ; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
################ |
182
|
|
|
|
|
|
|
# NEW_CALL_END # |
183
|
|
|
|
|
|
|
################ |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub new_call_END { |
186
|
1
|
50
|
|
1
|
0
|
2
|
my $class = shift ; $class = ref($class) if ref($class) ; |
|
1
|
|
|
|
|
6
|
|
187
|
|
|
|
|
|
|
|
188
|
1
|
|
|
|
|
1
|
my @isas = \@{"$class\::ISA"} ; |
|
1
|
|
|
|
|
4
|
|
189
|
|
|
|
|
|
|
|
190
|
1
|
|
|
|
|
2
|
foreach my $isas_i ( @isas ) { |
191
|
2
|
|
|
|
|
3
|
foreach my $ISA_i ( @$isas_i ) { |
192
|
4
|
100
|
66
|
|
|
3
|
if ( defined @{"$ISA_i\::ISA"} && @{"$ISA_i\::ISA"} > 2 ) { |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
16
|
|
193
|
1
|
|
|
|
|
2
|
push(@isas , \@{"$ISA_i\::ISA"}) ; |
|
1
|
|
|
|
|
4
|
|
194
|
|
|
|
|
|
|
} |
195
|
4
|
100
|
|
|
|
26
|
last if $ISA_i eq 'Class::HPLOO::Base' ; |
196
|
2
|
|
|
|
|
7
|
my ($sub) = ( $ISA_i =~ /(\w+)$/ ); |
197
|
2
|
|
|
|
|
4
|
$sub = "$ISA_i\::$sub\_END" ; |
198
|
2
|
50
|
|
|
|
11
|
&$sub(@_) if defined &$sub ; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
1
|
|
|
|
|
3
|
return ; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
####### |
206
|
|
|
|
|
|
|
# NEW # |
207
|
|
|
|
|
|
|
####### |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
my $NEW_REF = \&new ; |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub new { |
212
|
1
|
|
|
1
|
0
|
100
|
my $class = shift ; |
213
|
1
|
50
|
|
|
|
6
|
my $this = ref($class) ? $class : undef ; |
214
|
|
|
|
|
|
|
|
215
|
1
|
|
|
|
|
3
|
my $class_bless = $class ; |
216
|
1
|
50
|
|
|
|
6
|
($class,$class_bless,$this) = @$class if ref($class) eq 'ARRAY' ; |
217
|
|
|
|
|
|
|
|
218
|
1
|
50
|
|
|
|
4
|
$class = ref($class) if ref($class) ; |
219
|
1
|
50
|
|
|
|
5
|
$class_bless = ref($class_bless) if ref($class_bless) ; |
220
|
|
|
|
|
|
|
|
221
|
1
|
|
|
|
|
6
|
my ($class_end) = ( $class =~ /(\w+)$/ ); |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
##print "BASE NEW>> $class,$class_bless,$this >> $class_end >> @_ >> [". join(" ", @{"$class\::ISA"}) ."]\n" ; |
224
|
|
|
|
|
|
|
|
225
|
1
|
50
|
33
|
|
|
3
|
if ( !defined &{"$class\::$class_end"} && @{"$class\::ISA"} > 1 ) { |
|
1
|
|
|
|
|
9
|
|
|
0
|
|
|
|
|
0
|
|
226
|
0
|
|
|
|
|
0
|
foreach my $ISA_i ( @{"$class\::ISA"} ) { |
|
0
|
|
|
|
|
0
|
|
227
|
0
|
0
|
|
|
|
0
|
last if $ISA_i eq 'Class::HPLOO::Base' ; |
228
|
0
|
|
|
|
|
0
|
my $sub = "$ISA_i\::new" ; |
229
|
0
|
0
|
|
|
|
0
|
if ( defined &$sub ) { |
230
|
0
|
|
|
|
|
0
|
my $new_ref = \&$sub ; |
231
|
0
|
0
|
0
|
|
|
0
|
return &$sub([$ISA_i,$class,$this],@_) if $new_ref == $NEW_REF || (defined &{"$ISA_i\::__CLASS__"} && defined &{"$ISA_i\::SUPER"} && defined &{"$ISA_i\::new_call_END"} ) ; |
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
232
|
0
|
|
|
|
|
0
|
return &$sub($class,@_) ; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
1
|
|
33
|
|
|
7
|
$this ||= $class ; |
238
|
1
|
|
|
|
|
4
|
$this = new_call_BEGIN( $this , @_) ; |
239
|
1
|
50
|
33
|
|
|
7
|
$this = bless({} , $class_bless) if !ref($this) || !UNIVERSAL::isa($this,$class_bless) ; |
240
|
|
|
|
|
|
|
|
241
|
1
|
|
|
1
|
|
65
|
no warnings ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2978
|
|
242
|
|
|
|
|
|
|
|
243
|
1
|
|
|
|
|
2
|
my $undef = \'' ; |
244
|
0
|
|
|
0
|
0
|
|
sub UNDEF {$undef} ; |
245
|
|
|
|
|
|
|
|
246
|
1
|
|
|
|
|
3
|
my $CLASS_HPLOO = GET_CLASS_HPLOO_HASH($this) ; |
247
|
|
|
|
|
|
|
|
248
|
1
|
50
|
|
|
|
5
|
if ( $$CLASS_HPLOO{ATTR} ) { CLASS_HPLOO_TIE_KEYS($this) } |
|
0
|
|
|
|
|
0
|
|
249
|
|
|
|
|
|
|
|
250
|
1
|
50
|
|
|
|
2
|
my $ret_this = defined &{"$class\::$class_end"} ? $this->$class_end(@_) : undef ; |
|
1
|
|
|
|
|
8
|
|
251
|
|
|
|
|
|
|
|
252
|
1
|
50
|
33
|
|
|
11
|
if ( ref($ret_this) && UNIVERSAL::isa($ret_this,$class_bless) ) { |
|
|
0
|
|
|
|
|
|
253
|
1
|
|
|
|
|
1
|
$this = $ret_this ; |
254
|
1
|
50
|
33
|
|
|
4
|
if ( $$CLASS_HPLOO{ATTR} && UNIVERSAL::isa($this,'HASH') ) { CLASS_HPLOO_TIE_KEYS($this) } |
|
0
|
|
|
|
|
0
|
|
255
|
|
|
|
|
|
|
} |
256
|
0
|
|
|
|
|
0
|
elsif ( $ret_this == $undef ) { $this = undef } |
257
|
|
|
|
|
|
|
|
258
|
1
|
|
|
|
|
3
|
new_call_END($class,$this,@_) ; |
259
|
|
|
|
|
|
|
|
260
|
1
|
|
|
|
|
7
|
return $this ; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
######################## |
264
|
|
|
|
|
|
|
# CLASS_HPLOO_TIE_KEYS # |
265
|
|
|
|
|
|
|
######################## |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub CLASS_HPLOO_TIE_KEYS { |
268
|
0
|
|
|
0
|
0
|
|
my $this = shift ; |
269
|
0
|
|
|
|
|
|
my $CLASS_HPLOO = GET_CLASS_HPLOO_HASH($this) ; |
270
|
0
|
0
|
|
|
|
|
if ( $$CLASS_HPLOO{ATTR} ) { |
271
|
0
|
|
|
|
|
|
foreach my $Key ( keys %{$$CLASS_HPLOO{ATTR}} ) { |
|
0
|
|
|
|
|
|
|
272
|
0
|
0
|
|
|
|
|
tie( $this->{$Key} => 'Class::HPLOO::Base::HPLOO_TIESCALAR' , $this , $Key , $$CLASS_HPLOO{ATTR}{$Key}{tp} , $$CLASS_HPLOO{ATTR}{$Key}{pr} , \$this->{CLASS_HPLOO_ATTR}{$Key} , \$this->{CLASS_HPLOO_CHANGED} , ref($this) ) if !exists $this->{$Key} ; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
######### |
278
|
|
|
|
|
|
|
# ATTRS # |
279
|
|
|
|
|
|
|
######### |
280
|
|
|
|
|
|
|
|
281
|
0
|
|
|
0
|
0
|
|
sub ATTRS { return @{[@{ GET_CLASS_HPLOO_HASH($_[0] , scalar caller)->{ATTR_ORDER} }]} } ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
#################### |
284
|
|
|
|
|
|
|
# CLASS_HPLOO_ATTR # |
285
|
|
|
|
|
|
|
#################### |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
sub CLASS_HPLOO_ATTR { |
288
|
0
|
|
|
0
|
0
|
|
my $class = caller ; |
289
|
|
|
|
|
|
|
|
290
|
0
|
|
|
|
|
|
my @attrs = split(/\s*,\s*/ , $_[0]) ; |
291
|
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
|
my $CLASS_HPLOO = GET_CLASS_HPLOO_HASH( undef , $class ) ; |
293
|
|
|
|
|
|
|
|
294
|
0
|
|
|
|
|
|
foreach my $attrs_i ( @attrs ) { |
295
|
0
|
|
|
|
|
|
$attrs_i =~ s/^\s+//s ; |
296
|
0
|
|
|
|
|
|
$attrs_i =~ s/\s+$//s ; |
297
|
0
|
|
|
|
|
|
my ($name) = ( $attrs_i =~ /(\w+)$/gi ) ; |
298
|
0
|
|
|
|
|
|
my ($type) = ( $attrs_i =~ /^((?:\w+\s+)*?&?\w+|(?:\w+\s+)*?\w+(?:(?:::|\.)\w+)*)\s+\w+$/gi ) ; |
299
|
|
|
|
|
|
|
|
300
|
0
|
|
|
|
|
|
my $type0 = $type ; |
301
|
0
|
|
|
|
|
|
$type0 =~ s/\s+/ /gs ; |
302
|
|
|
|
|
|
|
|
303
|
0
|
|
|
|
|
|
$type = lc($type) ; |
304
|
0
|
|
|
|
|
|
$type =~ s/(?:^|\s*)bool$/boolean/gs ; |
305
|
0
|
|
|
|
|
|
$type =~ s/(?:^|\s*)int$/integer/gs ; |
306
|
0
|
|
|
|
|
|
$type =~ s/(?:^|\s*)float$/floating/gs ; |
307
|
0
|
|
|
|
|
|
$type =~ s/(?:^|\s*)str$/string/gs ; |
308
|
0
|
|
|
|
|
|
$type =~ s/(?:^|\s*)sub$/sub_$name/gs ; |
309
|
0
|
|
|
|
|
|
$type =~ s/\s//gs ; |
310
|
|
|
|
|
|
|
|
311
|
0
|
0
|
|
|
|
|
$type = 'any' if $type !~ /^(?:(?:ref)|(?:ref)?(?:array|hash)(?:boolean|integer|floating|string|sub_\w+|any|&\w+)|(?:ref)?(?:array|hash)|(?:array|hash)?(?:boolean|integer|floating|string|sub_\w+|any|&\w+))$/ ; |
312
|
|
|
|
|
|
|
|
313
|
0
|
0
|
0
|
|
|
|
if ( $type eq 'any' && $type0 =~ /^((?:ref\s*)?(?:array|hash) )?(\w+(?:(?:::|\.)\w+)*)$/ ) { |
314
|
0
|
|
|
|
|
|
my ($tp1 , $tp2) = ($1 , $2) ; |
315
|
0
|
|
|
|
|
|
$tp1 =~ s/\s+//gs ; |
316
|
0
|
0
|
|
|
|
|
$tp2 = 'UNIVERSAL' if $tp2 =~ /^(?:obj|object)$/i ; |
317
|
0
|
|
|
|
|
|
$tp2 =~ s/\.+/::/gs ; |
318
|
0
|
|
|
|
|
|
$type = "$tp1$tp2" ; |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
0
|
0
|
|
|
|
|
my $parse_ref = $type =~ /^(?:array|hash)/ ? 1 : 0 ; |
322
|
|
|
|
|
|
|
|
323
|
0
|
0
|
|
|
|
|
push(@{ $$CLASS_HPLOO{ATTR_ORDER} } , $name) if !$$CLASS_HPLOO{ATTR}{$name} ; |
|
0
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
|
325
|
0
|
|
|
|
|
|
$$CLASS_HPLOO{ATTR}{$name}{tp} = $type ; |
326
|
0
|
|
|
|
|
|
$$CLASS_HPLOO{ATTR}{$name}{pr} = $parse_ref ; |
327
|
|
|
|
|
|
|
|
328
|
0
|
|
|
|
|
|
my $return ; |
329
|
|
|
|
|
|
|
|
330
|
0
|
0
|
|
|
|
|
if ( $type =~ /^sub_(\w+)$/ ) { |
331
|
0
|
|
|
|
|
|
my $sub = $1 ; |
332
|
0
|
|
|
|
|
|
$return = qq~ |
333
|
|
|
|
|
|
|
return (&$sub(\$this,\@_))[0] if defined &$sub ; |
334
|
|
|
|
|
|
|
return undef ; |
335
|
|
|
|
|
|
|
~ ; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
else { |
338
|
0
|
0
|
|
|
|
|
$return = $parse_ref ? qq~ |
339
|
|
|
|
|
|
|
ref(\$this->{CLASS_HPLOO_ATTR}{$name}) eq 'ARRAY' ? \@{\$this->{CLASS_HPLOO_ATTR}{$name}} : |
340
|
|
|
|
|
|
|
ref(\$this->{CLASS_HPLOO_ATTR}{$name}) eq 'HASH' ? \%{\$this->{CLASS_HPLOO_ATTR}{$name}} : |
341
|
|
|
|
|
|
|
\$this->{CLASS_HPLOO_ATTR}{$name} |
342
|
|
|
|
|
|
|
~ : |
343
|
|
|
|
|
|
|
"\$this->{CLASS_HPLOO_ATTR}{$name}" ; |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
|
346
|
0
|
|
|
|
|
|
eval(qq~ |
347
|
|
|
|
|
|
|
package $class ; |
348
|
|
|
|
|
|
|
sub set_$name { |
349
|
|
|
|
|
|
|
my \$this = shift ; |
350
|
|
|
|
|
|
|
if ( !defined \$this->{$name} ) { |
351
|
|
|
|
|
|
|
tie( \$this->{$name} => 'Class::HPLOO::Base::HPLOO_TIESCALAR' , \$this , '$name' , '$type' , $parse_ref , \\\$this->{CLASS_HPLOO_ATTR}{$name} , \\\$this->{CLASS_HPLOO_CHANGED} , ref(\$this) ) ; |
352
|
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
\$this->{CLASS_HPLOO_CHANGED}{$name} = 1 ; |
355
|
|
|
|
|
|
|
\$this->{CLASS_HPLOO_ATTR}{$name} = CLASS_HPLOO_ATTR_TYPE( ref(\$this) , '$type',\@_) ; |
356
|
|
|
|
|
|
|
} |
357
|
0
|
0
|
|
|
|
|
~) if !defined &{"$class\::set_$name"} ; |
358
|
|
|
|
|
|
|
|
359
|
0
|
|
|
|
|
|
eval(qq~ |
360
|
|
|
|
|
|
|
package $class ; |
361
|
|
|
|
|
|
|
sub get_$name { |
362
|
|
|
|
|
|
|
my \$this = shift ; |
363
|
|
|
|
|
|
|
$return ; |
364
|
|
|
|
|
|
|
} |
365
|
0
|
0
|
|
|
|
|
~) if !defined &{"$class\::get_$name"} ; |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
} |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
######################### |
370
|
|
|
|
|
|
|
# CLASS_HPLOO_ATTR_TYPE # |
371
|
|
|
|
|
|
|
######################### |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
sub CLASS_HPLOO_ATTR_TYPE { |
374
|
0
|
|
|
0
|
0
|
|
my $class = shift ; |
375
|
0
|
|
|
|
|
|
my $type = shift ; |
376
|
|
|
|
|
|
|
|
377
|
0
|
0
|
|
|
|
|
if ($type eq 'any') { return $_[0] } |
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
378
|
|
|
|
|
|
|
elsif ($type eq 'string') { |
379
|
0
|
|
|
|
|
|
return "$_[0]" ; |
380
|
|
|
|
|
|
|
} |
381
|
|
|
|
|
|
|
elsif ($type eq 'boolean') { |
382
|
0
|
0
|
|
|
|
|
return if $_[0] =~ /^(?:false|null|undef)$/i ; |
383
|
0
|
0
|
|
|
|
|
return 1 if $_[0] ; |
384
|
0
|
|
|
|
|
|
return ; |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
elsif ($type eq 'integer') { |
387
|
0
|
|
|
|
|
|
my $val = $_[0] ; |
388
|
0
|
|
|
|
|
|
my ($sig) = ( $val =~ /^(-)/ ); |
389
|
0
|
|
|
|
|
|
$val =~ s/[^0-9]//gs ; |
390
|
0
|
|
|
|
|
|
$val = "$sig$val" ; |
391
|
0
|
|
|
|
|
|
return $val ; |
392
|
|
|
|
|
|
|
} |
393
|
|
|
|
|
|
|
elsif ($type eq 'floating') { |
394
|
0
|
|
|
|
|
|
my $val = $_[0] ; |
395
|
0
|
|
|
|
|
|
$val =~ s/[\s_]+//gs ; |
396
|
0
|
0
|
|
|
|
|
if ( $val !~ /^\d+\.\d+$/ ) { |
397
|
0
|
|
|
|
|
|
($val) = ( $val =~ /(\d+)/ ) ; |
398
|
0
|
|
|
|
|
|
$val .= '.0' ; |
399
|
|
|
|
|
|
|
} |
400
|
0
|
|
|
|
|
|
return $val ; |
401
|
|
|
|
|
|
|
} |
402
|
|
|
|
|
|
|
elsif ($type =~ /^sub_(\w+)$/) { |
403
|
0
|
|
|
|
|
|
my $sub = $1 ; |
404
|
0
|
0
|
|
|
|
|
return (&$sub(@_))[0] if defined &$sub ; |
405
|
|
|
|
|
|
|
} |
406
|
|
|
|
|
|
|
elsif ($type =~ /^&(\w+)$/) { |
407
|
0
|
|
|
|
|
|
my $sub = $1 ; |
408
|
0
|
0
|
|
|
|
|
return (&$sub(@_))[0] if defined &$sub ; |
409
|
|
|
|
|
|
|
} |
410
|
|
|
|
|
|
|
elsif ($type eq 'ref') { |
411
|
0
|
|
|
|
|
|
my $val = $_[0] ; |
412
|
0
|
0
|
|
|
|
|
return $val if ref($val) ; |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
elsif ($type eq 'array') { |
415
|
0
|
|
|
|
|
|
my @val = @_ ; |
416
|
0
|
|
|
|
|
|
return \@val ; |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
elsif ($type eq 'hash') { |
419
|
0
|
|
|
|
|
|
my %val = @_ ; |
420
|
0
|
|
|
|
|
|
return \%val ; |
421
|
|
|
|
|
|
|
} |
422
|
|
|
|
|
|
|
elsif ($type eq 'refarray') { |
423
|
0
|
|
|
|
|
|
my $val = $_[0] ; |
424
|
0
|
0
|
|
|
|
|
return $val if ref($val) eq 'ARRAY' ; |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
elsif ($type eq 'refhash') { |
427
|
0
|
|
|
|
|
|
my $val = $_[0] ; |
428
|
0
|
0
|
|
|
|
|
return $val if ref($val) eq 'HASH' ; |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
elsif ($type =~ /^array(&?[\w:]+)/ ) { |
431
|
0
|
|
|
|
|
|
my $tp = $1 ; |
432
|
0
|
|
|
|
|
|
my @val = @_ ; |
433
|
0
|
0
|
|
|
|
|
my $accept_undef = $tp =~ /^(?:any|string|boolean|integer|floating|sub_\w+|&\w+)$/ ? 1 : undef ; |
434
|
0
|
0
|
|
|
|
|
if ( $accept_undef ) { |
435
|
0
|
|
|
|
|
|
return [map { CLASS_HPLOO_ATTR_TYPE($class , $tp , $_) } @val] ; |
|
0
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
} |
437
|
|
|
|
|
|
|
else { |
438
|
0
|
0
|
|
|
|
|
return [map { CLASS_HPLOO_ATTR_TYPE($class , $tp , $_) || () } @val] ; |
|
0
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
} |
440
|
|
|
|
|
|
|
} |
441
|
|
|
|
|
|
|
elsif ($type =~ /^hash(&?[\w:]+)/ ) { |
442
|
0
|
|
|
|
|
|
my $tp = $1 ; |
443
|
0
|
|
|
|
|
|
my %val = @_ ; |
444
|
0
|
|
|
|
|
|
foreach my $Key ( keys %val ) { |
445
|
0
|
|
|
|
|
|
$val{$Key} = CLASS_HPLOO_ATTR_TYPE($class , $tp , $val{$Key}) ; |
446
|
|
|
|
|
|
|
} |
447
|
0
|
|
|
|
|
|
return \%val ; |
448
|
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
|
elsif ($type =~ /^refarray(&?[\w:]+)/ ) { |
450
|
0
|
|
|
|
|
|
my $tp = $1 ; |
451
|
0
|
0
|
|
|
|
|
return undef if ref($_[0]) ne 'ARRAY' ; |
452
|
0
|
|
|
|
|
|
my $ref = CLASS_HPLOO_ATTR_TYPE($class , "array$tp" , @{$_[0]}) ; |
|
0
|
|
|
|
|
|
|
453
|
0
|
|
|
|
|
|
@{$_[0]} = @{$ref} ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
454
|
0
|
|
|
|
|
|
return $_[0] ; |
455
|
|
|
|
|
|
|
} |
456
|
|
|
|
|
|
|
elsif ($type =~ /^refhash(&?[\w:]+)/ ) { |
457
|
0
|
|
|
|
|
|
my $tp = $1 ; |
458
|
0
|
0
|
|
|
|
|
return undef if ref($_[0]) ne 'HASH' ; |
459
|
0
|
|
|
|
|
|
my $ref = CLASS_HPLOO_ATTR_TYPE($class , "hash$tp" , %{$_[0]}) ; |
|
0
|
|
|
|
|
|
|
460
|
0
|
|
|
|
|
|
%{$_[0]} = %{$ref} ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
461
|
0
|
|
|
|
|
|
return $_[0] ; |
462
|
|
|
|
|
|
|
} |
463
|
|
|
|
|
|
|
elsif ($type =~ /^\w+(?:::\w+)*$/ ) { |
464
|
0
|
0
|
|
|
|
|
return( UNIVERSAL::isa($_[0] , $type) ? $_[0] : undef ) ; |
465
|
|
|
|
|
|
|
} |
466
|
0
|
|
|
|
|
|
return undef ; |
467
|
|
|
|
|
|
|
} |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
####################################### |
470
|
|
|
|
|
|
|
# CLASS::HPLOO::BASE::HPLOO_TIESCALAR # |
471
|
|
|
|
|
|
|
####################################### |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
package Class::HPLOO::Base::HPLOO_TIESCALAR ; |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
sub TIESCALAR { |
476
|
0
|
|
|
0
|
|
|
shift ; |
477
|
0
|
|
|
|
|
|
my $obj = shift ; |
478
|
0
|
|
0
|
|
|
|
my $this = bless( { nm => $_[0] , tp => $_[1] , pr => $_[2] , rf => $_[3] , rfcg => $_[4] , pk => ($_[5] || scalar caller) } , __PACKAGE__ ) ; |
479
|
|
|
|
|
|
|
|
480
|
0
|
0
|
|
|
|
|
if ( $this->{tp} =~ /^sub_(\w+)$/ ) { |
481
|
0
|
|
|
|
|
|
my $CLASS_HPLOO = Class::HPLOO::Base::GET_CLASS_HPLOO_HASH( undef , $this->{pk} ) ; |
482
|
|
|
|
|
|
|
|
483
|
0
|
0
|
|
|
|
|
if ( !ref($$CLASS_HPLOO{OBJ_TBL}) ) { |
484
|
0
|
|
|
|
|
|
eval { require Hash::NoRef } ; |
|
0
|
|
|
|
|
|
|
485
|
0
|
0
|
|
|
|
|
if ( !$@ ) { |
486
|
0
|
|
|
|
|
|
$$CLASS_HPLOO{OBJ_TBL} = {} ; |
487
|
0
|
|
|
|
|
|
tie( %{$$CLASS_HPLOO{OBJ_TBL}} , 'Hash::NoRef') ; |
|
0
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
} |
489
|
0
|
|
|
|
|
|
else { $@ = undef } |
490
|
|
|
|
|
|
|
} |
491
|
|
|
|
|
|
|
|
492
|
0
|
|
|
|
|
|
$$CLASS_HPLOO{OBJ_TBL}{ ++$$CLASS_HPLOO{OBJ_TBL}{x} } = $obj ; |
493
|
0
|
|
|
|
|
|
$this->{oid} = $$CLASS_HPLOO{OBJ_TBL}{x} ; |
494
|
|
|
|
|
|
|
} |
495
|
|
|
|
|
|
|
|
496
|
0
|
|
|
|
|
|
return $this ; |
497
|
|
|
|
|
|
|
} |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
sub STORE { |
500
|
0
|
|
|
0
|
|
|
my $this = shift ; |
501
|
0
|
|
|
|
|
|
my $ref = $this->{rf} ; |
502
|
0
|
|
|
|
|
|
my $ref_changed = $this->{rfcg} ; |
503
|
|
|
|
|
|
|
|
504
|
0
|
0
|
|
|
|
|
if ( $ref_changed ) { |
505
|
0
|
0
|
|
|
|
|
if ( ref $$ref_changed ne 'HASH' ) { $$ref_changed = {} } |
|
0
|
|
|
|
|
|
|
506
|
0
|
|
|
|
|
|
$$ref_changed->{$this->{nm}} = 1 ; |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
|
509
|
0
|
0
|
|
|
|
|
if ( $this->{pr} ) { |
510
|
0
|
0
|
|
|
|
|
my $tp = $this->{tp} =~ /^ref/ ? $this->{tp} : 'ref' . $this->{tp} ; |
511
|
0
|
|
|
|
|
|
$$ref = &{"$this->{pk}::CLASS_HPLOO_ATTR_TYPE"}($this->{pk} , $tp , @_) ; |
|
0
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
else { |
514
|
0
|
|
|
|
|
|
$$ref = &{"$this->{pk}::CLASS_HPLOO_ATTR_TYPE"}($this->{pk} , $this->{tp} , @_) ; |
|
0
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
} |
516
|
|
|
|
|
|
|
} |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
sub FETCH { |
519
|
0
|
|
|
0
|
|
|
my $this = shift ; |
520
|
0
|
|
|
|
|
|
my $ref = $this->{rf} ; |
521
|
|
|
|
|
|
|
|
522
|
0
|
0
|
|
|
|
|
if ( $this->{tp} =~ /^sub_(\w+)$/ ) { |
523
|
0
|
|
|
|
|
|
my $CLASS_HPLOO = Class::HPLOO::Base::GET_CLASS_HPLOO_HASH( undef , $this->{pk} ) ; |
524
|
0
|
|
|
|
|
|
my $sub = $this->{pk} . '::' . $1 ; |
525
|
0
|
|
|
|
|
|
my $obj = $$CLASS_HPLOO{OBJ_TBL}{ $this->{oid} } ; |
526
|
0
|
0
|
|
|
|
|
return (&$sub($obj,@_))[0] if defined &$sub ; |
527
|
|
|
|
|
|
|
} |
528
|
|
|
|
|
|
|
else { |
529
|
0
|
0
|
|
|
|
|
if ( $this->{tp} =~ /^(?:ref)?(?:array|hash)/ ) { |
530
|
0
|
|
|
|
|
|
my $ref_changed = $this->{rfcg} ; |
531
|
0
|
0
|
|
|
|
|
if ( $ref_changed ) { |
532
|
0
|
0
|
|
|
|
|
if ( ref $$ref_changed ne 'HASH' ) { $$ref_changed = {} } |
|
0
|
|
|
|
|
|
|
533
|
0
|
|
|
|
|
|
$$ref_changed->{$this->{nm}} = 1 ; |
534
|
|
|
|
|
|
|
} |
535
|
|
|
|
|
|
|
} |
536
|
0
|
|
|
|
|
|
return $$ref ; |
537
|
|
|
|
|
|
|
} |
538
|
|
|
|
|
|
|
} |
539
|
|
|
|
|
|
|
|
540
|
0
|
|
|
0
|
|
|
sub UNTIE {} |
541
|
0
|
|
|
0
|
|
|
sub DESTROY {} |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
####### |
545
|
|
|
|
|
|
|
# END # |
546
|
|
|
|
|
|
|
####### |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
1; |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
|