line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# [[[ HEADER ]]] |
2
|
|
|
|
|
|
|
package RPerl::CompileUnit::Module::Class; |
3
|
9
|
|
|
9
|
|
67
|
use strict; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
312
|
|
4
|
9
|
|
|
9
|
|
55
|
use warnings; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
258
|
|
5
|
9
|
|
|
9
|
|
3931
|
use RPerl::Config; # get @ARG, Dumper, Carp, English without 'use RPerl;' |
|
9
|
|
|
|
|
38
|
|
|
9
|
|
|
|
|
1975
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.042_000; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# [[[ OO INHERITANCE ]]] |
9
|
|
|
|
|
|
|
# BASE CLASS HAS NO INHERITANCE |
10
|
|
|
|
|
|
|
# "The Buck Stops Here" |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# [[[ CRITICS ]]] |
13
|
|
|
|
|
|
|
## no critic qw(ProhibitStringyEval) # SYSTEM DEFAULT 1: allow eval() |
14
|
|
|
|
|
|
|
## no critic qw(ProhibitAutoloading RequireArgUnpacking) # SYSTEM SPECIAL 2: allow Autoload & read-only @ARG |
15
|
|
|
|
|
|
|
## no critic qw(ProhibitExcessComplexity) # SYSTEM SPECIAL 5: allow complex code inside subroutines, must be after line 1 |
16
|
|
|
|
|
|
|
## no critic qw(ProhibitDeepNests) # SYSTEM SPECIAL 7: allow deeply-nested code |
17
|
|
|
|
|
|
|
## no critic qw(ProhibitNoStrict) # SYSTEM SPECIAL 8: allow no strict |
18
|
|
|
|
|
|
|
## no critic qw(RequireBriefOpen) # SYSTEM SPECIAL 10: allow complex processing with open filehandle |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# [[[ INCLUDES ]]] |
21
|
9
|
|
|
9
|
|
91
|
use File::Basename; |
|
9
|
|
|
|
|
135
|
|
|
9
|
|
|
|
|
834
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# [[[ OO PROPERTIES ]]] |
24
|
|
|
|
|
|
|
# BASE CLASS HAS NO PROPERTIES |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# [[[ SUBROUTINES & OO METHODS ]]] |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# RPerl object constructor, SHORT FORM |
29
|
|
|
|
|
|
|
sub new { |
30
|
9
|
|
|
9
|
|
164
|
no strict; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
1057
|
|
31
|
0
|
0
|
|
0
|
|
|
if ( not defined ${ $_[0] . '::properties' } ) { |
|
0
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
croak 'ERROR ECOOOCO00, SOURCE CODE, OO OBJECT CONSTRUCTOR: Undefined hashref $properties for class ' . $_[0] . ', croaking' . "\n"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
# return bless { %{ ${ $_[0] . '::properties' } } }, $_[0]; # DOES NOT INHERIT DATA MEMBERS FROM PARENT CLASSES |
35
|
|
|
|
|
|
|
# return bless { %{ ${ $_[0] . '::properties' } }, %{ properties_inherited($_[0]) } }, $_[0]; |
36
|
0
|
|
|
|
|
|
return bless { %{ properties_inherited($_[0]) } }, $_[0]; |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub properties_inherited { |
40
|
|
|
|
|
|
|
# print {*STDERR} 'in Class::properties_inherited(), top of subroutine, received $ARG[0] = ', $ARG[0], "\n"; |
41
|
9
|
|
|
9
|
|
55
|
no strict; |
|
9
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
1259
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# always keep self class' $properties |
44
|
0
|
|
|
0
|
|
|
my $properties = { %{ ${ $ARG[0] . '::properties' } } }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# inherit parent & (great*)grandparent class' $properties |
47
|
0
|
|
|
|
|
|
foreach my $parent_package_name (@{ $ARG[0] . '::ISA' }) { |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# print {*STDERR} 'in Class::properties_inherited(), top of foreach() loop, have $parent_package_name = ', $parent_package_name, "\n"; |
49
|
|
|
|
|
|
|
# RPerl base class & Eyapp classes have no $properties, skip |
50
|
0
|
0
|
0
|
|
|
|
if (($parent_package_name eq 'RPerl::CompileUnit::Module::Class') or |
51
|
|
|
|
|
|
|
($parent_package_name eq 'Parse::Eyapp::Node')) { |
52
|
0
|
|
|
|
|
|
next; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# recurse to get inherited $properties |
56
|
0
|
|
|
|
|
|
my $parent_and_grandparent_properties = properties_inherited($parent_package_name); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# self class' $properties override inherited $properties, same as C++ |
59
|
0
|
|
|
|
|
|
foreach my $parent_property_key (keys %{ $parent_and_grandparent_properties }) { |
|
0
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
if (not exists $properties->{$parent_property_key}) { |
61
|
0
|
|
|
|
|
|
$properties->{$parent_property_key} = $parent_and_grandparent_properties->{$parent_property_key}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
return $properties; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub parent_and_grandparent_package_names { |
69
|
|
|
|
|
|
|
# print {*STDERR} 'in Class::parent_and_grandparent_package_names(), top of subroutine, received $ARG[0] = ', $ARG[0], "\n"; |
70
|
9
|
|
|
9
|
|
56
|
no strict; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
2052
|
|
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
0
|
|
|
RPerl::eval_use($ARG[0]); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $arg0_isa_string = $ARG[0] . '::ISA'; |
75
|
|
|
|
|
|
|
# print {*STDERR} 'in Class::parent_and_grandparent_package_names(), have $arg0_isa_string = ', $arg0_isa_string, "\n"; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my @arg0_isa = @{$arg0_isa_string}; |
|
0
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# print {*STDERR} 'in Class::parent_and_grandparent_package_names(), have @arg0_isa = ', Dumper(\@arg0_isa), "\n"; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $package_names = []; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
foreach my $parent_package_name (@{ $ARG[0] . '::ISA' }) { |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# print {*STDERR} 'in Class::parent_and_grandparent_package_names(), top of foreach() loop, have $parent_package_name = ', $parent_package_name, "\n"; |
84
|
|
|
|
|
|
|
# RPerl base class & Eyapp classes have no $properties, skip |
85
|
0
|
0
|
0
|
|
|
|
if (($parent_package_name eq 'RPerl::CompileUnit::Module::Class') or |
86
|
|
|
|
|
|
|
($parent_package_name eq 'Parse::Eyapp::Node')) { |
87
|
0
|
|
|
|
|
|
next; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# get parent's package name |
91
|
0
|
|
|
|
|
|
push @{$package_names}, $parent_package_name; |
|
0
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# recurse to get (great*)grandparents' package names |
94
|
0
|
|
|
|
|
|
my $grandparent_package_names = parent_and_grandparent_package_names($parent_package_name); |
95
|
0
|
|
|
|
|
|
$package_names = [@{$package_names}, @{$grandparent_package_names}]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# print {*STDERR} 'in Class::parent_and_grandparent_package_names(), inside foreach() loop, have $grandparent_package_names = ', Dumper($grandparent_package_names), "\n"; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
# print {*STDERR} 'in Class::parent_and_grandparent_package_names(), bottom of subroutine, returning $package_names = ', Dumper($package_names), "\n"; |
99
|
0
|
|
|
|
|
|
return $package_names; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# RPerl object destructor |
103
|
|
|
|
|
|
|
# NEED ADDRESS: do we ever need to actually deconstruct anything to free resources? |
104
|
|
|
|
0
|
|
|
sub DESTROY { } |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# [[[ SUBROUTINES ]]] |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# suppress deprecated feature warning |
109
|
|
|
|
|
|
|
local $SIG{__WARN__} = sub { |
110
|
|
|
|
|
|
|
return if $_[0] =~ /^Use of inherited AUTOLOAD for non-method /xms; |
111
|
|
|
|
|
|
|
carp @ARG; |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
BEGIN { |
115
|
|
|
|
|
|
|
#RPerl::diag('in Class.pm BEGIN block, about to use data types...' . "\n"); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# DEV NOTE, CORRELATION #rp012: type system includes, hard-copies in rperltypes.pm & rperltypesconv.pm & Class.pm |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# [[[ DATA TYPES ]]] |
120
|
9
|
|
|
9
|
|
4791
|
use RPerl::DataType::Void; |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
215
|
|
121
|
9
|
|
|
9
|
|
2938
|
use RPerl::DataType::Boolean; |
|
9
|
|
|
|
|
31
|
|
|
9
|
|
|
|
|
789
|
|
122
|
9
|
|
|
9
|
|
3399
|
use RPerl::DataType::UnsignedInteger; |
|
9
|
|
|
|
|
28
|
|
|
9
|
|
|
|
|
931
|
|
123
|
9
|
|
|
9
|
|
3380
|
use RPerl::DataType::Integer; |
|
9
|
|
|
|
|
31
|
|
|
9
|
|
|
|
|
880
|
|
124
|
9
|
|
|
9
|
|
3627
|
use RPerl::DataType::Number; |
|
9
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
818
|
|
125
|
9
|
|
|
9
|
|
3348
|
use RPerl::DataType::Character; |
|
9
|
|
|
|
|
32
|
|
|
9
|
|
|
|
|
942
|
|
126
|
9
|
|
|
9
|
|
70
|
use RPerl::DataType::String; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
852
|
|
127
|
9
|
|
|
9
|
|
58
|
use RPerl::DataType::Scalar; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
213
|
|
128
|
9
|
|
|
9
|
|
3391
|
use RPerl::DataType::Unknown; |
|
9
|
|
|
|
|
24
|
|
|
9
|
|
|
|
|
400
|
|
129
|
9
|
|
|
9
|
|
3166
|
use RPerl::DataType::FileHandle; |
|
9
|
|
|
|
|
29
|
|
|
9
|
|
|
|
|
415
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
#RPerl::diag('in Class.pm BEGIN block, about to use data structures...' . "\n"); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# [[[ DATA STRUCTURES ]]] |
134
|
9
|
|
|
9
|
|
3188
|
use RPerl::DataStructure::Array; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
use RPerl::DataStructure::Array::SubTypes; |
136
|
|
|
|
|
|
|
use RPerl::DataStructure::Array::Reference; |
137
|
|
|
|
|
|
|
use RPerl::DataStructure::Hash; |
138
|
|
|
|
|
|
|
use RPerl::DataStructure::Hash::SubTypes; |
139
|
|
|
|
|
|
|
use RPerl::DataStructure::Hash::Reference; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
#RPerl::diag('in Class.pm BEGIN block, done' . "\n"); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# after compiling but before runtime: create symtab entries for all RPerl functions/methods, and accessors/mutators for all RPerl class properties |
145
|
|
|
|
|
|
|
INIT { |
146
|
|
|
|
|
|
|
create_symtab_entries_and_accessors_mutators(\%INC); |
147
|
|
|
|
|
|
|
}; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub create_symtab_entries_and_accessors_mutators { |
150
|
|
|
|
|
|
|
(my $INC_ref) = @ARG; |
151
|
|
|
|
|
|
|
# $RPerl::DEBUG = 1; |
152
|
|
|
|
|
|
|
# $RPerl::VERBOSE = 1; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# add calling .pl driver to INC for subroutine activation; |
155
|
|
|
|
|
|
|
# DEV NOTE: should be safe to use basename() here instead of fileparse(), because $PROGRAM_NAME should never end in a directory |
156
|
|
|
|
|
|
|
$INC{ basename($PROGRAM_NAME) } = $PROGRAM_NAME; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# RPerl::diag('in Class.pm INIT block, have $INC_ref =' . "\n" . Dumper($INC_ref) . "\n"); |
159
|
|
|
|
|
|
|
# RPerl::diag('in Class.pm INIT block, have $rperlnamespaces_generated::CORE =' . "\n" . Dumper($rperlnamespaces_generated::CORE) . "\n"); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my $module_filename_long; # string |
162
|
|
|
|
|
|
|
my $use_rperl; # boolean |
163
|
|
|
|
|
|
|
my $inside_package; # boolean |
164
|
|
|
|
|
|
|
my $package_name; # string |
165
|
|
|
|
|
|
|
my $package_name_underscores; # string |
166
|
|
|
|
|
|
|
my $namespace_root; # string |
167
|
|
|
|
|
|
|
my $object_properties; # hashref |
168
|
|
|
|
|
|
|
my $object_properties_string; # string |
169
|
|
|
|
|
|
|
my $object_properties_types; # hashref |
170
|
|
|
|
|
|
|
my $inside_object_properties; # boolean |
171
|
|
|
|
|
|
|
my $subroutine_type; # string |
172
|
|
|
|
|
|
|
my $subroutine_name; # string |
173
|
|
|
|
|
|
|
my $CHECK; # string |
174
|
|
|
|
|
|
|
my $inside_subroutine; # boolean |
175
|
|
|
|
|
|
|
my $inside_subroutine_arguments; # boolean |
176
|
|
|
|
|
|
|
my $subroutine_arguments_line; # string |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# RPerl::diag(q{in Class.pm INIT block, have $PROGRAM_NAME = '} . $PROGRAM_NAME . "'\n"); |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
foreach my $module_filename_short ( sort keys %{$INC_ref} ) { |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# RPerl::diag("in Class.pm INIT block, have \$module_filename_short = '$module_filename_short'\n"); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# skip special entry created by Filter::Util::Call |
185
|
|
|
|
|
|
|
if ( $module_filename_short eq '-e' ) { |
186
|
|
|
|
|
|
|
next; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
$module_filename_long = $INC{$module_filename_short}; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# skip absolute file names (such as Komodo's perl5db.pl) which came from a runtime `require $scalar` or `require 'foo.pm'`, |
192
|
|
|
|
|
|
|
# and we can not determine the correct package from the absolute path name, we don't know how to figure out which part was in @INC from the absolute path |
193
|
|
|
|
|
|
|
if ((not defined $module_filename_long) or ( $module_filename_long eq $module_filename_short )) { |
194
|
|
|
|
|
|
|
next; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# skip already-compiled files with PMC counterparts |
198
|
|
|
|
|
|
|
if (-e ($module_filename_long . 'c')) { |
199
|
|
|
|
|
|
|
next; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
$use_rperl = 0; |
203
|
|
|
|
|
|
|
$inside_package = 0; |
204
|
|
|
|
|
|
|
$package_name = q{}; |
205
|
|
|
|
|
|
|
$CHECK = $RPerl::CHECK; # reset data type checking to RPerl default for every file |
206
|
|
|
|
|
|
|
$object_properties_string = q{}; |
207
|
|
|
|
|
|
|
$object_properties_types = {}; |
208
|
|
|
|
|
|
|
$inside_object_properties = 0; |
209
|
|
|
|
|
|
|
$inside_subroutine = 0; |
210
|
|
|
|
|
|
|
$inside_subroutine_arguments = 0; |
211
|
|
|
|
|
|
|
$subroutine_arguments_line = q{}; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
$namespace_root = RPerl::filename_short_to_namespace_root_guess($module_filename_short); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
# RPerl::diag(q{in Class.pm INIT block, have $namespace_root = '} . $namespace_root . "'\n"); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# DEV NOTE: avoid error... |
218
|
|
|
|
|
|
|
# Name "rperlnamespaces_generated::RPERL_DEPS" used only once: possible typo |
219
|
|
|
|
|
|
|
my $tmp = $rperlnamespaces_generated::CORE; |
220
|
|
|
|
|
|
|
$tmp = $rperlnamespaces_generated::RPERL_DEPS; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
if ( ( not exists $rperlnamespaces_generated::CORE->{$namespace_root} ) and |
223
|
|
|
|
|
|
|
( not exists $rperlnamespaces_generated::RPERL_DEPS->{$namespace_root} ) and |
224
|
|
|
|
|
|
|
( not exists $rperlnamespaces_generated::RPERL_FILES->{$module_filename_short}) ) |
225
|
|
|
|
|
|
|
{ |
226
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, not skipping due to CORE & RPERL_DEPS namespaces, $module_filename_long = ' . $module_filename_long . "\n" ); |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
open my $MODULE_FILE, '<', $module_filename_long or croak $OS_ERROR; |
229
|
|
|
|
|
|
|
MODULE_FILE_LINE_LOOP: |
230
|
|
|
|
|
|
|
while ( my $module_file_line = <$MODULE_FILE> ) { |
231
|
|
|
|
|
|
|
chomp $module_file_line; |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
# RPerl::diag('in Class.pm INIT block, have $module_file_line =' . "\n" . $module_file_line . "\n"); |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
# set data type checking mode |
236
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\s*\#\s*\<\<\<\s*TYPE_CHECKING\s*\:\s*(\w+)\s*\>\>\>/xms ) { |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# RPerl::diag( "in Class.pm INIT block, have \$module_filename_long = '$module_filename_long'\n" ); |
239
|
|
|
|
|
|
|
if ($inside_subroutine) { |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, found <<< TYPE_CHECKING: ' . $1 . ' >>> while inside subroutine ' . $subroutine_name . '(), aborting RPerl activation of entire file' . "\n" ); |
242
|
|
|
|
|
|
|
last; |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
else { |
245
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, found <<< TYPE_CHECKING: ' . $1 . " >>>\n" ); |
246
|
|
|
|
|
|
|
$CHECK = $1; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
# skip single-line comments |
251
|
|
|
|
|
|
|
next if ( $module_file_line =~ /^\s*\#/xms ); |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
# skip multi-line POD comments |
254
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\=(\w+)/xms ) { |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# RPerl::diag("in Class.pm INIT block, skipping multi-line POD comment, have \$1 = '$1'\n"); |
257
|
|
|
|
|
|
|
$module_file_line = <$MODULE_FILE>; |
258
|
|
|
|
|
|
|
if ( not defined $module_file_line ) { |
259
|
|
|
|
|
|
|
croak "End of file '$module_filename_long' reached without finding '=cut' end of multi-line POD comment '=$1', croaking"; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
while ( $module_file_line !~ /^\=cut/xms ) { |
262
|
|
|
|
|
|
|
if ( not defined $module_file_line ) { |
263
|
|
|
|
|
|
|
croak "End of file '$module_filename_long' reached without finding '=cut' end of multi-line POD comment '=$1', croaking"; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
$module_file_line = <$MODULE_FILE>; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
next; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
# skip multi-line heredocs |
271
|
|
|
|
|
|
|
if ( ( $module_file_line =~ /\=\s*\<\<\s*(\w+)\s*\;\s*$/xms ) |
272
|
|
|
|
|
|
|
or ( $module_file_line =~ /\=\s*\<\<\s*\'(\w+)\'\s*\;\s*$/xms ) |
273
|
|
|
|
|
|
|
or ( $module_file_line =~ /\=\s*\<\<\s*\"(\w+)\"\s*\;\s*$/xms ) ) |
274
|
|
|
|
|
|
|
{ |
275
|
|
|
|
|
|
|
# RPerl::diag("in Class.pm INIT block, skipping multi-line heredoc, have \$1 = '$1'\n"); |
276
|
|
|
|
|
|
|
$module_file_line = <$MODULE_FILE>; |
277
|
|
|
|
|
|
|
if ( not defined $module_file_line ) { |
278
|
|
|
|
|
|
|
croak "End of file '$module_filename_long' reached without finding '$1' end of multi-line heredoc string, croaking"; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
while ( $module_file_line !~ /^$1/xms ) { |
281
|
|
|
|
|
|
|
$module_file_line = <$MODULE_FILE>; |
282
|
|
|
|
|
|
|
if ( not defined $module_file_line ) { |
283
|
|
|
|
|
|
|
croak "End of file '$module_filename_long' reached without finding '$1' end of multi-line heredoc string, croaking"; |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
next; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
# skip __DATA__ footer |
290
|
|
|
|
|
|
|
if ( $module_file_line eq '__DATA__' ) { |
291
|
|
|
|
|
|
|
# if ($inside_subroutine) { RPerl::diag( 'in Class.pm INIT block, skipping __DATA__ footer while inside subroutine ' . $subroutine_name . '(), aborting RPerl activation of entire file' . "\n" ); } |
292
|
|
|
|
|
|
|
# else { RPerl::diag('in Class.pm INIT block, skipping __DATA__ footer' . "\n"); } |
293
|
|
|
|
|
|
|
last; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
# skip __END__ footer |
297
|
|
|
|
|
|
|
if ( $module_file_line eq '__END__' ) { |
298
|
|
|
|
|
|
|
# if ($inside_subroutine) { RPerl::diag( 'in Class.pm INIT block, skipping __END__ footer while inside subroutine ' . $subroutine_name . '(), aborting RPerl activation of entire file' . "\n" ); } |
299
|
|
|
|
|
|
|
# else { RPerl::diag('in Class.pm INIT block, skipping __END__ footer' . "\n"); } |
300
|
|
|
|
|
|
|
last; |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
# RPerl::diag("in Class.pm INIT block, have \$module_file_line =\n$module_file_line\n"); |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
# create ops/types reporting subroutine & accessor/mutator object methods for each RPerl package |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
# user-style RPerl header, anything that starts with 'use RPerl;' |
308
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\s*(use\s+RPerl\s*;)/xms ) { |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
# RPerl::diag(q{in Class.pm INIT block, found '} . $1 . q{' in $module_filename_short = } . $module_filename_short . "\n"); |
311
|
|
|
|
|
|
|
$use_rperl = 1; |
312
|
|
|
|
|
|
|
next; |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
# package declaration |
316
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\s*package\s+/xms ) { |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
# object properties, save types from just-finished package |
319
|
|
|
|
|
|
|
if ($inside_package) { |
320
|
|
|
|
|
|
|
$object_properties_types = save_object_properties_types( $package_name, $object_properties_string, $object_properties_types ); |
321
|
|
|
|
|
|
|
$object_properties_string = q{}; |
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
$inside_package = 1; |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
# one-line package declaration, indexed by PAUSE unless listed in no_index in Makefile.PL |
326
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\s*package\s+(\w+(::\w+)*)\;.*$/xms ) { |
327
|
|
|
|
|
|
|
$package_name = $1; |
328
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, one-line package declaration, have $package name = ' . $package_name . "\n" ); |
329
|
|
|
|
|
|
|
} |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
# two-line package declaration, not indexed by PAUSE |
332
|
|
|
|
|
|
|
elsif ( $module_file_line =~ /^\s*package\s*\#\s*hide.*$/xms ) { # EX. package # hide from PAUSE indexing |
333
|
|
|
|
|
|
|
$module_file_line = <$MODULE_FILE>; |
334
|
|
|
|
|
|
|
chomp $module_file_line; |
335
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\s*(\w+(::\w+)*)\;.*$/xms ) { |
336
|
|
|
|
|
|
|
$package_name = $1; |
337
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, two-line package declaration, have $package name = ' . $package_name . "\n" ); |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
else { |
340
|
|
|
|
|
|
|
croak q{Improperly formed two-line package declaration found in file '} |
341
|
|
|
|
|
|
|
. $module_filename_long |
342
|
|
|
|
|
|
|
. q{' near '} |
343
|
|
|
|
|
|
|
. $module_file_line |
344
|
|
|
|
|
|
|
. q{', croaking}; |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
else { |
348
|
|
|
|
|
|
|
croak q{Improperly formed package declaration found in file '} |
349
|
|
|
|
|
|
|
. $module_filename_long |
350
|
|
|
|
|
|
|
. q{' near '} |
351
|
|
|
|
|
|
|
. $module_file_line |
352
|
|
|
|
|
|
|
. q{', croaking}; |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
if ($inside_subroutine) { |
356
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, have $package name = ' . $package_name . 'while inside subroutine ' . $subroutine_name . '(), aborting RPerl activation of entire file' . "\n" ); |
357
|
|
|
|
|
|
|
last; |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
# else { RPerl::diag( 'in Class.pm INIT block, have $package name = ' . $package_name . "\n" ); } |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
# system-style RPerl header, 'use strict; use warnings; use RPerl::AfterSubclass;' on 3 lines |
362
|
|
|
|
|
|
|
# don't check for $VERSION due to numerous un-versioned subtypes |
363
|
|
|
|
|
|
|
if ( not $use_rperl ) { |
364
|
|
|
|
|
|
|
foreach my $rperl_header_line ( 'use strict;', 'use warnings;', 'use RPerl::AfterSubclass;' ) { |
365
|
|
|
|
|
|
|
$module_file_line = <$MODULE_FILE>; |
366
|
|
|
|
|
|
|
chomp $module_file_line; |
367
|
|
|
|
|
|
|
if ( $module_file_line !~ /\Q$rperl_header_line/xms ) { |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
# RPerl::diag(q{in Class.pm INIT block, failed to find RPerl header line '} . $rperl_header_line . q{' for $module_filename_short = } . $module_filename_short . ', aborting RPerl activation of entire file' . "\n"); |
370
|
|
|
|
|
|
|
next MODULE_FILE_LINE_LOOP; |
371
|
|
|
|
|
|
|
} |
372
|
|
|
|
|
|
|
} |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
# RPerl::diag('in Class.pm INIT block, found RPerl header in $module_filename_short = ' . $module_filename_short . "\n"); |
375
|
|
|
|
|
|
|
$use_rperl = 1; |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
# RPerl::diag(q{in Class.pm INIT block, have $use_rperl, enabling package in $module_filename_short = } . $module_filename_short . "\n"); |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
# ops/types reporting subroutine |
381
|
|
|
|
|
|
|
# DEV NOTE, CORRELATION #rp018: RPerl::DataStructure::Array & Hash can not 'use RPerl;' so they are skipped in the header-checking loop above, their *__MODE_ID() subroutines are not created below |
382
|
|
|
|
|
|
|
$package_name_underscores = $package_name; |
383
|
|
|
|
|
|
|
$package_name_underscores =~ s/::/__/g; |
384
|
|
|
|
|
|
|
if ( not eval( 'defined &main::' . $package_name_underscores . '__MODE_ID' ) ) { |
385
|
|
|
|
|
|
|
eval( '*main::' . $package_name_underscores . '__MODE_ID = sub { return 0; };' ) # PERLOPS_PERLTYPES is 0 |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
# eval( 'sub main::' . $package_name_underscores . '__MODE_ID { return 0; }' ) # equivalent to previous line |
388
|
|
|
|
|
|
|
or croak($EVAL_ERROR); |
389
|
|
|
|
|
|
|
if ($EVAL_ERROR) { croak($EVAL_ERROR); } |
390
|
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
next; |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
# object properties, remember types for deferred accessor/mutator generation below |
396
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\s*our\s+hashref\s+\$properties/xms ) { |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
# hard-coded example |
399
|
|
|
|
|
|
|
#our hashref $properties = { foo => my Foo::Bar_arrayref $TYPED_foo = undef, quux => my integer_hashref $TYPED_quux = {a => 12, b => 21} }; |
400
|
|
|
|
|
|
|
$inside_object_properties = 1; |
401
|
|
|
|
|
|
|
chomp $module_file_line; # strip trailing newline |
402
|
|
|
|
|
|
|
$object_properties_string .= $module_file_line; |
403
|
|
|
|
|
|
|
next; |
404
|
|
|
|
|
|
|
} |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
# create symbol table entries for methods and plain-old non-method subroutines |
407
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\s*our\s+([\w:]+)\s+\$(\w+)\s+\=\s+sub\s+\{/xms ) { |
408
|
|
|
|
|
|
|
$inside_object_properties = 0; |
409
|
|
|
|
|
|
|
if ( not $use_rperl ) { |
410
|
|
|
|
|
|
|
# RPerl::diag(q{in Class.pm INIT block, do NOT have $use_rperl, skipping subroutine in $module_filename_short = } . $module_filename_short . "\n"); |
411
|
|
|
|
|
|
|
next; |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
# else { RPerl::diag(q{in Class.pm INIT block, have $use_rperl, enabling subroutine in $module_filename_short = } . $module_filename_short . "\n"); } |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
if ($inside_subroutine_arguments) { |
416
|
|
|
|
|
|
|
# RPerl::diag( q{in Class.pm INIT block, have $subroutine_type = } . $1 . q{, and $subroutine_name = } . $2 . '() while inside arguments of subroutine ' . $subroutine_name . '(), aborting RPerl activation of entire file' . "\n" ); |
417
|
|
|
|
|
|
|
last; # last line of file |
418
|
|
|
|
|
|
|
} |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
# activate previous subroutine, no arguments |
421
|
|
|
|
|
|
|
if ($inside_subroutine) { |
422
|
|
|
|
|
|
|
# RPerl::diag( q{in Class.pm INIT block, have $inside_subroutine = } . $inside_subroutine . q{, about to call activate_subroutine() while inside subroutine } . $subroutine_name . '()' . "\n" ); |
423
|
|
|
|
|
|
|
activate_subroutine( $package_name, $subroutine_name, $subroutine_type, q{}, $module_filename_long ); |
424
|
|
|
|
|
|
|
} |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
$subroutine_type = $1; |
427
|
|
|
|
|
|
|
$subroutine_name = $2; |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
# RPerl::diag( q{in Class.pm INIT block, have $subroutine_type = } . $subroutine_type . q{, and $subroutine_name = } . $subroutine_name . "()\n" ); |
430
|
|
|
|
|
|
|
# RPerl::diag( q{in Class.pm INIT block, have $CHECK = '} . $CHECK . "'\n" ); |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
if ( $CHECK eq 'OFF' ) { |
433
|
|
|
|
|
|
|
# RPerl::diag( q{in Class.pm INIT block, CHECK IS OFF, about to call activate_subroutine()...} . "\n" ); |
434
|
|
|
|
|
|
|
activate_subroutine( $package_name, $subroutine_name, $subroutine_type, q{}, $module_filename_long ); |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
elsif ( ( $CHECK ne 'ON' ) and ( $CHECK ne 'TRACE' ) ) { |
437
|
|
|
|
|
|
|
croak( 'Received invalid value ' |
438
|
|
|
|
|
|
|
. $CHECK |
439
|
|
|
|
|
|
|
. ' for RPerl preprocessor directive CHECK to control data type checking, valid values are OFF, ON, and TRACE, croaking' ); |
440
|
|
|
|
|
|
|
} |
441
|
|
|
|
|
|
|
else { |
442
|
|
|
|
|
|
|
$inside_subroutine = 1; |
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
next; |
445
|
|
|
|
|
|
|
} |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
# skip class properties AKA package variables |
448
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\s*our\s+[\w:]+\s+\$\w+\s+\=/xms ) { |
449
|
|
|
|
|
|
|
$inside_object_properties = 0; |
450
|
|
|
|
|
|
|
} |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
# skip non-RPerl-enabled subroutine/method, using normal Perl 'sub foo {}' syntax instead of RPerl 'our type $foo = sub {};' syntax |
453
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\s*sub\s+[\w:]+\s+\{/xms ) { |
454
|
|
|
|
|
|
|
$inside_object_properties = 0; |
455
|
|
|
|
|
|
|
} |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
# skip end-of-module line |
458
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\s*1\;\s+\#\ end\ of/xms ) { |
459
|
|
|
|
|
|
|
$inside_object_properties = 0; |
460
|
|
|
|
|
|
|
} |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
# object properties, continue to aggregate types |
463
|
|
|
|
|
|
|
if ($inside_object_properties) { |
464
|
|
|
|
|
|
|
chomp $module_file_line; # strip trailing newline |
465
|
|
|
|
|
|
|
$object_properties_string .= $module_file_line; |
466
|
|
|
|
|
|
|
next; |
467
|
|
|
|
|
|
|
} |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
# subroutine/method, process arguments and activate |
470
|
|
|
|
|
|
|
if ($inside_subroutine) { |
471
|
|
|
|
|
|
|
if ( not $use_rperl ) { |
472
|
|
|
|
|
|
|
# RPerl::diag(q{in Class.pm INIT block, do NOT have $use_rperl, skipping inside subroutine in $module_filename_short = } . $module_filename_short . "\n"); |
473
|
|
|
|
|
|
|
next; |
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
# else { RPerl::diag(q{in Class.pm INIT block, have $use_rperl, enabling inside subroutine in $module_filename_short = } . $module_filename_short . "\n"); } |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
# RPerl::diag( q{in Class.pm INIT block, have $inside_subroutine = 1} . "\n" ); |
478
|
|
|
|
|
|
|
# RPerl::diag("in Class.pm INIT block, have \$module_file_line =\n$module_file_line\n"); |
479
|
|
|
|
|
|
|
if ( $module_file_line =~ /^\s*\(\s*my/xms ) { |
480
|
|
|
|
|
|
|
$inside_subroutine_arguments = 1; |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
# RPerl::diag( q{in Class.pm INIT block, have $inside_subroutine_arguments = }, $inside_subroutine_arguments, "\n" ); |
484
|
|
|
|
|
|
|
if ($inside_subroutine_arguments) { |
485
|
|
|
|
|
|
|
$subroutine_arguments_line .= $module_file_line; |
486
|
|
|
|
|
|
|
if ( $subroutine_arguments_line =~ /\@ARG\;/xms ) { # @ARG; found |
487
|
|
|
|
|
|
|
if ( not( $subroutine_arguments_line =~ /\@ARG\;$/xms ) ) { # @ARG; found not at end-of-line |
488
|
|
|
|
|
|
|
# RPerl::diag( q{in Class.pm INIT block, found @ARG; NOT at end-of-line while inside subroutine } . $subroutine_name . '(), have $subroutine_arguments_line = ' . "\n" . $subroutine_arguments_line . "\n\n" . 'aborting RPerl activation of entire file' . "\n" ); |
489
|
|
|
|
|
|
|
last; |
490
|
|
|
|
|
|
|
} |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
# RPerl::diag( q{in Class.pm INIT block, found @ARG; at end-of-line while inside subroutine } . $subroutine_name . '(), have $subroutine_arguments_line = ' . "\n" . $subroutine_arguments_line . "\n" ); |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
my $subroutine_arguments = []; # string_arrayref_arrayref |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
# loop once per subroutine argument |
497
|
|
|
|
|
|
|
while ( $subroutine_arguments_line =~ m/my\s+(\w+)\s+\$(\w+)/g ) { |
498
|
|
|
|
|
|
|
push @{$subroutine_arguments}, [ $1, $2 ]; |
499
|
|
|
|
|
|
|
# RPerl::diag( q{in Class.pm INIT block, have subroutine argument type = } . $1 . q{ and subroutine argument name = } . $2 . "\n" ); |
500
|
|
|
|
|
|
|
} |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
# RPerl::diag( q{in Class.pm INIT block, have $subroutine_arguments = } . "\n" . Dumper($subroutine_arguments) . "\n" ); |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
my $subroutine_arguments_check_code = "\n"; # string |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
if ( $CHECK eq 'ON' ) { |
507
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, CHECK IS ON' . "\n" ); |
508
|
|
|
|
|
|
|
my $i = 0; # integer |
509
|
|
|
|
|
|
|
foreach my $subroutine_argument ( @{$subroutine_arguments} ) { |
510
|
|
|
|
|
|
|
$subroutine_arguments_check_code .= q{ } . $subroutine_argument->[0] . '_CHECK( $_[' . $i . '] );' . "\n"; |
511
|
|
|
|
|
|
|
$i++; |
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, CHECK IS ON, about to call activate_subroutine()...' . "\n" ); |
515
|
|
|
|
|
|
|
activate_subroutine( $package_name, $subroutine_name, $subroutine_type, $subroutine_arguments_check_code, |
516
|
|
|
|
|
|
|
$module_filename_long ); |
517
|
|
|
|
|
|
|
$inside_subroutine = 0; |
518
|
|
|
|
|
|
|
$subroutine_arguments_line = q{}; |
519
|
|
|
|
|
|
|
} |
520
|
|
|
|
|
|
|
elsif ( $CHECK eq 'TRACE' ) { |
521
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, CHECK IS TRACE' . "\n" ); |
522
|
|
|
|
|
|
|
my $i = 0; # integer |
523
|
|
|
|
|
|
|
foreach my $subroutine_argument ( @{$subroutine_arguments} ) { |
524
|
|
|
|
|
|
|
$subroutine_arguments_check_code |
525
|
|
|
|
|
|
|
.= q{ } . $subroutine_argument->[0] . '_CHECKTRACE( $_[' . $i . q{], '$} . $subroutine_argument->[1] . q{', '} . $subroutine_name . q{()' );} . "\n"; |
526
|
|
|
|
|
|
|
$i++; |
527
|
|
|
|
|
|
|
} |
528
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, CHECK IS TRACE, about to call activate_subroutine()...' . "\n" ); |
529
|
|
|
|
|
|
|
activate_subroutine( $package_name, $subroutine_name, $subroutine_type, $subroutine_arguments_check_code, |
530
|
|
|
|
|
|
|
$module_filename_long ); |
531
|
|
|
|
|
|
|
$inside_subroutine = 0; |
532
|
|
|
|
|
|
|
$subroutine_arguments_line = q{}; |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
else { |
535
|
|
|
|
|
|
|
croak( 'Received invalid value ' |
536
|
|
|
|
|
|
|
. $CHECK |
537
|
|
|
|
|
|
|
. ' for RPerl preprocessor directive CHECK to control data type checking, valid values are OFF, ON, and TRACE, croaking' |
538
|
|
|
|
|
|
|
); |
539
|
|
|
|
|
|
|
} |
540
|
|
|
|
|
|
|
$inside_subroutine_arguments = 0; |
541
|
|
|
|
|
|
|
} |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, have $subroutine_arguments_check_code =' . "\n" . $subroutine_arguments_check_code . "\n" ); |
544
|
|
|
|
|
|
|
next; # next file line |
545
|
|
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
} |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
close $MODULE_FILE or croak $OS_ERROR; |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
# activate final subroutine in file, no arguments |
552
|
|
|
|
|
|
|
if ($inside_subroutine) { |
553
|
|
|
|
|
|
|
if ($inside_subroutine_arguments) { |
554
|
|
|
|
|
|
|
croak('Did not find @ARG to end subroutine arguments before end of file, croaking'); |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, activating final subroutine in file, no subroutine arguments found' . "\n" ); |
558
|
|
|
|
|
|
|
activate_subroutine( $package_name, $subroutine_name, $subroutine_type, q{}, $module_filename_long ); |
559
|
|
|
|
|
|
|
$inside_subroutine = 0; |
560
|
|
|
|
|
|
|
} |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
# object properties, save final package's types |
563
|
|
|
|
|
|
|
$object_properties_types = save_object_properties_types( $package_name, $object_properties_string, $object_properties_types ); |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
# RPerl::diag( 'in Class.pm INIT block, have $object_properties_types = ' . "\n" . Dumper($object_properties_types) . "\n" ) if ( keys %{$object_properties_types} ); |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
# accessor/mutator object methods, deferred creation for all packages found in this file |
568
|
|
|
|
|
|
|
foreach $package_name ( sort keys %{$object_properties_types} ) { |
569
|
|
|
|
|
|
|
$object_properties = eval "\$$package_name\:\:properties"; |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
foreach my $property_name ( sort keys %{$object_properties} ) { |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
# RPerl::diag("in Class.pm INIT block, have \$property_name = '$property_name'\n"); |
574
|
|
|
|
|
|
|
# DEV NOTE, CORRELATION #rp003: avoid re-defining class accessor/mutator methods; so far only triggered by RPerl::CodeBlock::Subroutine |
575
|
|
|
|
|
|
|
# because it has a special BEGIN{} block with multiple package names including it's own package name |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
my $property_type = $object_properties_types->{$package_name}->{$property_name}; |
578
|
|
|
|
|
|
|
my $eval_string; |
579
|
|
|
|
|
|
|
my $return_whole = 0; |
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
# array element accessor/mutator |
582
|
|
|
|
|
|
|
if ( ( $property_type =~ /_arrayref$/ ) |
583
|
|
|
|
|
|
|
and ( not eval( 'defined &' . $package_name . '::get_' . $property_name . '_element' ) ) ) |
584
|
|
|
|
|
|
|
{ |
585
|
|
|
|
|
|
|
# hard-coded example |
586
|
|
|
|
|
|
|
#our int::method $get_foo_size = sub { ( my Foo::Bar $self ) = @ARG; return (scalar @{$self->{foo}}); }; |
587
|
|
|
|
|
|
|
#our Foo::Quux::method $get_foo_element = sub { ( my Foo::Bar $self, my integer $i ) = @ARG; return $self->{foo}->[$i]; }; |
588
|
|
|
|
|
|
|
#our void::method $set_foo_element = sub { ( my Foo::Bar $self, my integer $i, my Foo::Quux $foo_element ) = @ARG; $self->{foo}->[$i] = $foo_element; }; |
589
|
|
|
|
|
|
|
my $property_element_type = substr $property_type, 0, ( ( length $property_type ) - 9 ); # strip trailing '_arrayref' |
590
|
|
|
|
|
|
|
if ( exists $rperlnamespaces_generated::RPERL->{ $property_element_type . '::' } ) { |
591
|
|
|
|
|
|
|
$return_whole = 1; |
592
|
|
|
|
|
|
|
} |
593
|
|
|
|
|
|
|
else { |
594
|
|
|
|
|
|
|
$eval_string |
595
|
|
|
|
|
|
|
= '*{' |
596
|
|
|
|
|
|
|
. $package_name |
597
|
|
|
|
|
|
|
. '::get_' |
598
|
|
|
|
|
|
|
. $property_name . '_size' |
599
|
|
|
|
|
|
|
. '} = sub { ( my ' |
600
|
|
|
|
|
|
|
. $package_name |
601
|
|
|
|
|
|
|
. ' $self ) = @ARG; return (scalar @{$self->{' |
602
|
|
|
|
|
|
|
. $property_name |
603
|
|
|
|
|
|
|
. '}}); };'; |
604
|
|
|
|
|
|
|
$eval_string |
605
|
|
|
|
|
|
|
.= '*{' |
606
|
|
|
|
|
|
|
. $package_name |
607
|
|
|
|
|
|
|
. '::get_' |
608
|
|
|
|
|
|
|
. $property_name |
609
|
|
|
|
|
|
|
. '_element' |
610
|
|
|
|
|
|
|
. '} = sub { ( my ' |
611
|
|
|
|
|
|
|
. $package_name |
612
|
|
|
|
|
|
|
. ' $self, my integer $i ) = @ARG; return $self->{' |
613
|
|
|
|
|
|
|
. $property_name |
614
|
|
|
|
|
|
|
. '}->[$i]; };'; |
615
|
|
|
|
|
|
|
$eval_string |
616
|
|
|
|
|
|
|
.= '*{' |
617
|
|
|
|
|
|
|
. $package_name |
618
|
|
|
|
|
|
|
. '::set_' |
619
|
|
|
|
|
|
|
. $property_name |
620
|
|
|
|
|
|
|
. '_element' |
621
|
|
|
|
|
|
|
. '} = sub { ( my ' |
622
|
|
|
|
|
|
|
. $package_name |
623
|
|
|
|
|
|
|
. ' $self, my integer $i, my ' |
624
|
|
|
|
|
|
|
. $property_element_type . ' $' |
625
|
|
|
|
|
|
|
. $property_name |
626
|
|
|
|
|
|
|
. '_element ) = @ARG; $self->{' |
627
|
|
|
|
|
|
|
. $property_name |
628
|
|
|
|
|
|
|
. '}->[$i] = $' |
629
|
|
|
|
|
|
|
. $property_name |
630
|
|
|
|
|
|
|
. '_element; };'; |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
# RPerl::diag( 'in Class::INIT() block, have user-defined object array element accessor $eval_string = ' . "\n" . $eval_string . "\n" ); |
633
|
|
|
|
|
|
|
eval($eval_string) or croak($EVAL_ERROR); |
634
|
|
|
|
|
|
|
if ($EVAL_ERROR) { croak($EVAL_ERROR); } |
635
|
|
|
|
|
|
|
} |
636
|
|
|
|
|
|
|
} |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
# hash value accessor/mutator |
639
|
|
|
|
|
|
|
elsif ( ( $property_type =~ /_hashref$/ ) |
640
|
|
|
|
|
|
|
and ( not eval( 'defined &' . $package_name . '::get_' . $property_name . '_element' ) ) ) |
641
|
|
|
|
|
|
|
{ |
642
|
|
|
|
|
|
|
# hard-coded example |
643
|
|
|
|
|
|
|
#our string_arrayref::method $get_foo_keys = sub { ( my Foo::Bar $self ) = @ARG; return [sort keys %{$self->{foo}}]; }; |
644
|
|
|
|
|
|
|
#our Foo::Quux::method $get_foo_element = sub { ( my Foo::Bar $self, my integer $i ) = @ARG; return $self->{foo}->{$i}; }; |
645
|
|
|
|
|
|
|
#our void::method $set_foo_element = sub { ( my Foo::Bar $self, my integer $i, my Foo::Quux $foo_element ) = @ARG; $self->{foo}->{$i} = $foo_element; }; |
646
|
|
|
|
|
|
|
my $property_value_type = substr $property_type, 0, ( ( length $property_type ) - 8 ); # strip trailing '_hashref' |
647
|
|
|
|
|
|
|
if ( exists $rperlnamespaces_generated::RPERL->{ $property_value_type . '::' } ) { |
648
|
|
|
|
|
|
|
$return_whole = 1; |
649
|
|
|
|
|
|
|
} |
650
|
|
|
|
|
|
|
else { |
651
|
|
|
|
|
|
|
$eval_string |
652
|
|
|
|
|
|
|
= '*{' |
653
|
|
|
|
|
|
|
. $package_name |
654
|
|
|
|
|
|
|
. '::get_' |
655
|
|
|
|
|
|
|
. $property_name . '_keys' |
656
|
|
|
|
|
|
|
. '} = sub { ( my ' |
657
|
|
|
|
|
|
|
. $package_name |
658
|
|
|
|
|
|
|
. ' $self ) = @ARG; return [sort keys %{$self->{' |
659
|
|
|
|
|
|
|
. $property_name |
660
|
|
|
|
|
|
|
. '}}]; };'; |
661
|
|
|
|
|
|
|
$eval_string |
662
|
|
|
|
|
|
|
.= '*{' |
663
|
|
|
|
|
|
|
. $package_name |
664
|
|
|
|
|
|
|
. '::get_' |
665
|
|
|
|
|
|
|
. $property_name |
666
|
|
|
|
|
|
|
. '_element' |
667
|
|
|
|
|
|
|
. '} = sub { ( my ' |
668
|
|
|
|
|
|
|
. $package_name |
669
|
|
|
|
|
|
|
. ' $self, my integer $i ) = @ARG; return $self->{' |
670
|
|
|
|
|
|
|
. $property_name |
671
|
|
|
|
|
|
|
. '}->{$i}; };'; |
672
|
|
|
|
|
|
|
$eval_string |
673
|
|
|
|
|
|
|
.= '*{' |
674
|
|
|
|
|
|
|
. $package_name |
675
|
|
|
|
|
|
|
. '::set_' |
676
|
|
|
|
|
|
|
. $property_name |
677
|
|
|
|
|
|
|
. '_element' |
678
|
|
|
|
|
|
|
. '} = sub { ( my ' |
679
|
|
|
|
|
|
|
. $package_name |
680
|
|
|
|
|
|
|
. ' $self, my integer $i, my ' |
681
|
|
|
|
|
|
|
. $property_value_type . ' $' |
682
|
|
|
|
|
|
|
. $property_name |
683
|
|
|
|
|
|
|
. '_element ) = @ARG; $self->{' |
684
|
|
|
|
|
|
|
. $property_name |
685
|
|
|
|
|
|
|
. '}->{$i} = $' |
686
|
|
|
|
|
|
|
. $property_name |
687
|
|
|
|
|
|
|
. '_element; };'; |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
# RPerl::diag( 'in Class::INIT() block, have user-defined object hash value accessor $eval_string = ' . "\n" . $eval_string . "\n" ); |
690
|
|
|
|
|
|
|
eval($eval_string) or croak($EVAL_ERROR); |
691
|
|
|
|
|
|
|
if ($EVAL_ERROR) { croak($EVAL_ERROR); } |
692
|
|
|
|
|
|
|
} |
693
|
|
|
|
|
|
|
} |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
# scalar accessor/mutator |
696
|
|
|
|
|
|
|
else { |
697
|
|
|
|
|
|
|
$return_whole = 1; |
698
|
|
|
|
|
|
|
} |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
# return whole values for scalars, scalar arrayrefs, and scalar hashrefs |
701
|
|
|
|
|
|
|
if ($return_whole) { |
702
|
|
|
|
|
|
|
if ( not eval( 'defined &' . $package_name . '::get_' . $property_name ) ) { |
703
|
|
|
|
|
|
|
$eval_string = '*{' . $package_name . '::get_' . $property_name . '} = sub { return $_[0]->{' . $property_name . '}; };'; |
704
|
|
|
|
|
|
|
eval($eval_string) or croak($EVAL_ERROR); |
705
|
|
|
|
|
|
|
if ($EVAL_ERROR) { croak($EVAL_ERROR); } |
706
|
|
|
|
|
|
|
} |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
if ( not eval( 'defined &' . $package_name . '::set_' . $property_name ) ) { |
709
|
|
|
|
|
|
|
$eval_string |
710
|
|
|
|
|
|
|
= '*{' |
711
|
|
|
|
|
|
|
. $package_name |
712
|
|
|
|
|
|
|
. '::set_' |
713
|
|
|
|
|
|
|
. $property_name |
714
|
|
|
|
|
|
|
. '} = sub { $_[0]->{' |
715
|
|
|
|
|
|
|
. $property_name |
716
|
|
|
|
|
|
|
. '} = $_[1]; return $_[0]->{' |
717
|
|
|
|
|
|
|
. $property_name . '}; };'; |
718
|
|
|
|
|
|
|
eval($eval_string) |
719
|
|
|
|
|
|
|
or croak($EVAL_ERROR); |
720
|
|
|
|
|
|
|
if ($EVAL_ERROR) { croak($EVAL_ERROR); } |
721
|
|
|
|
|
|
|
} |
722
|
|
|
|
|
|
|
} |
723
|
|
|
|
|
|
|
} |
724
|
|
|
|
|
|
|
} |
725
|
|
|
|
|
|
|
} |
726
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
# else { RPerl::diag('in Class.pm INIT block, found existing $rperlnamespaces_generated::CORE->{' . $namespace_root . '}, aborting RPerl activation of entire file' . "\n"); } |
728
|
|
|
|
|
|
|
} |
729
|
|
|
|
|
|
|
} |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
# fake getting and setting values of *_raw subclass of user-defined type (AKA class), |
732
|
|
|
|
|
|
|
# achieved by treating normal Perl object reference (C++ std::unique_ptr<Foo> AKA Foo_ptr) as Perl object raw reference (C++ Foo* AKA Foo_rawptr) |
733
|
|
|
|
|
|
|
sub get_raw { |
734
|
|
|
|
|
|
|
( my $self ) = @ARG; |
735
|
|
|
|
|
|
|
return $self; |
736
|
|
|
|
|
|
|
} |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
sub set_raw { |
739
|
|
|
|
|
|
|
( my $self, my $self_new ) = @ARG; |
740
|
|
|
|
|
|
|
%{$self} = %{$self_new}; |
741
|
|
|
|
|
|
|
} |
742
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
sub save_object_properties_types { |
744
|
|
|
|
|
|
|
( my $package_name, my $object_properties_string, my $object_properties_types ) = @ARG; |
745
|
|
|
|
|
|
|
if ( $object_properties_string eq q{} ) { |
746
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
# RPerl::diag( 'in Class::save_object_properties_types(), have NO PROPERTIES $object_properties_string ' . "\n" ); |
748
|
|
|
|
|
|
|
} |
749
|
|
|
|
|
|
|
elsif ( $object_properties_string =~ /^\s*our\s+hashref\s+\$properties\s*=\s*\{\s*\}\;/xms ) { |
750
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
# RPerl::diag( 'in Class::save_object_properties_types(), have EMPTY PROPERTIES $object_properties_string = ' . "\n" . $object_properties_string . "\n" ); |
752
|
|
|
|
|
|
|
} |
753
|
|
|
|
|
|
|
else { |
754
|
|
|
|
|
|
|
my $object_property_key = undef; |
755
|
|
|
|
|
|
|
my $object_property_type = undef; |
756
|
|
|
|
|
|
|
my $object_property_inner_type_name = undef; |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
$object_properties_string =~ s/^\s*our\s+hashref\s+\$properties\s*=\s*\{(.*)\}\;\s*$/$1/xms; # strip everything but hash entries |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
# RPerl::diag( 'in Class::save_object_properties_types(), have NON-EMPTY PROPERTIES $object_properties_string = ' . "\n" . $object_properties_string . "\n\n" ); |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
if ( $object_properties_string =~ /(\w+)\s*\=\>\s*my\s+([\w:]+)\s+\$TYPED_(\w+)/gxms ) { |
763
|
|
|
|
|
|
|
$object_property_key = $1; |
764
|
|
|
|
|
|
|
$object_property_type = $2; |
765
|
|
|
|
|
|
|
$object_property_inner_type_name = $3; |
766
|
|
|
|
|
|
|
} |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
# RPerl::diag( 'in Class::save_object_properties_types(), before while() loop, have $object_property_key = ' . $object_property_key . "\n" ); |
769
|
|
|
|
|
|
|
# RPerl::diag( 'in Class::save_object_properties_types(), before while() loop, have $object_property_type = ' . $object_property_type . "\n" ); |
770
|
|
|
|
|
|
|
# RPerl::diag( 'in Class::save_object_properties_types(), before while() loop, have $object_property_inner_type_name = ' . $object_property_inner_type_name . "\n" ); |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
while ( ( defined $object_property_key ) and ( defined $object_property_type ) and ( defined $object_property_inner_type_name ) ) { |
773
|
|
|
|
|
|
|
if ( $object_property_key ne $object_property_inner_type_name ) { |
774
|
|
|
|
|
|
|
# DEV NOTE, CORRELATION #rp030: matches numbering of ECOGEASCP20 in RPerl/CompileUnit/Module/Class/Generator.pm |
775
|
|
|
|
|
|
|
die 'ERROR ECOGEPPRP20, CODE GENERATOR, PURE PERL TO RPERL: redundant name mismatch, inner type name ' . q{'} |
776
|
|
|
|
|
|
|
. $object_property_inner_type_name . q{'} |
777
|
|
|
|
|
|
|
. ' does not equal OO properties key ' . q{'} |
778
|
|
|
|
|
|
|
. $object_property_key . q{'} |
779
|
|
|
|
|
|
|
. ', dying' . "\n"; |
780
|
|
|
|
|
|
|
} |
781
|
|
|
|
|
|
|
$object_properties_types->{$package_name}->{$object_property_key} = $object_property_type; |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
if ( $object_properties_string =~ /(\w+)\s*\=\>\s*my\s+([\w:]+)\s+\$TYPED_(\w+)/gxms ) { |
784
|
|
|
|
|
|
|
$object_property_key = $1; |
785
|
|
|
|
|
|
|
$object_property_type = $2; |
786
|
|
|
|
|
|
|
$object_property_inner_type_name = $3; |
787
|
|
|
|
|
|
|
} |
788
|
|
|
|
|
|
|
else { |
789
|
|
|
|
|
|
|
$object_property_key = undef; |
790
|
|
|
|
|
|
|
$object_property_type = undef; |
791
|
|
|
|
|
|
|
$object_property_inner_type_name = undef; |
792
|
|
|
|
|
|
|
} |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
# RPerl::diag( 'in Class::save_object_properties_types(), bottom of while() loop, have $object_property_key = ' . $object_property_key . "\n" ); |
795
|
|
|
|
|
|
|
# RPerl::diag( 'in Class::save_object_properties_types(), bottom of while() loop, have $object_property_type = ' . $object_property_type . "\n" ); |
796
|
|
|
|
|
|
|
# RPerl::diag( 'in Class::save_object_properties_types(), bottom of while() loop, have $object_property_inner_type_name = ' . $object_property_inner_type_name . "\n" ); |
797
|
|
|
|
|
|
|
} |
798
|
|
|
|
|
|
|
} |
799
|
|
|
|
|
|
|
return $object_properties_types; |
800
|
|
|
|
|
|
|
} |
801
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
# create Perl symbol table entries for RPerl subroutines and methods |
803
|
|
|
|
|
|
|
sub activate_subroutine { |
804
|
|
|
|
|
|
|
( my $package_name, my $subroutine_name, my $subroutine_type, my $subroutine_arguments_check_code, my $module_filename_long ) = @ARG; |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
# RPerl::diag('in Class::activate_subroutine(), received $package_name = ' . $package_name . "\n"); |
807
|
|
|
|
|
|
|
# RPerl::diag('in Class::activate_subroutine(), received $subroutine_name = ' . $subroutine_name . "\n"); |
808
|
|
|
|
|
|
|
# RPerl::diag('in Class::activate_subroutine(), received $subroutine_type = ' . $subroutine_type . "\n"); |
809
|
|
|
|
|
|
|
# RPerl::diag('in Class::activate_subroutine(), received $subroutine_arguments_check_code = ' . $subroutine_arguments_check_code . "\n"); |
810
|
|
|
|
|
|
|
# RPerl::diag('in Class::activate_subroutine(), received $module_filename_long = ' . $module_filename_long . "\n"); |
811
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
my $package_name_tmp; # string |
813
|
|
|
|
|
|
|
my $subroutine_definition_code; # string |
814
|
|
|
|
|
|
|
my $subroutine_definition_diag_code = q{}; # string |
815
|
|
|
|
|
|
|
if ( $subroutine_type =~ /\::method$/xms ) { |
816
|
|
|
|
|
|
|
if ( $package_name eq '' ) { |
817
|
|
|
|
|
|
|
croak( 'Received no package name for method ', $subroutine_name, ' in file ' . $module_filename_long . ' ... croaking' ); |
818
|
|
|
|
|
|
|
} |
819
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
# $subroutine_definition_diag_code = "\n" . q{RPerl::diag("IN POST-INIT, method direct call MODE } . $package_name . '::' . $subroutine_name . q{\n"); } . "\n"; |
821
|
|
|
|
|
|
|
# RPerl::diag("in Class::activate_subroutine(), $subroutine_name is a method\n"); |
822
|
|
|
|
|
|
|
# NEED UPGRADE: is it possible to activate non-type-checked RPerl subroutines & methods w/out creating new subroutines? |
823
|
|
|
|
|
|
|
$subroutine_definition_code |
824
|
|
|
|
|
|
|
= '*{' |
825
|
|
|
|
|
|
|
. $package_name . '::' |
826
|
|
|
|
|
|
|
. $subroutine_name |
827
|
|
|
|
|
|
|
. '} = sub { ' |
828
|
|
|
|
|
|
|
. $subroutine_definition_diag_code |
829
|
|
|
|
|
|
|
. $subroutine_arguments_check_code |
830
|
|
|
|
|
|
|
. 'return &${' |
831
|
|
|
|
|
|
|
. $package_name . '::' |
832
|
|
|
|
|
|
|
. $subroutine_name |
833
|
|
|
|
|
|
|
. '}(@ARG); };'; |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
# if ($subroutine_arguments_check_code ne q{}) { RPerl::diag('in Class::activate_subroutine(), have method $subroutine_definition_code =' . "\n" . $subroutine_definition_code . "\n"); } |
836
|
|
|
|
|
|
|
eval($subroutine_definition_code) |
837
|
|
|
|
|
|
|
or croak($EVAL_ERROR); |
838
|
|
|
|
|
|
|
if ($EVAL_ERROR) { croak($EVAL_ERROR); } |
839
|
|
|
|
|
|
|
} |
840
|
|
|
|
|
|
|
else { |
841
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
|
845
|
|
|
|
|
|
|
# START HERE: why is sun() getting redefined and trigger ECOPR00 below??? |
846
|
|
|
|
|
|
|
# START HERE: why is sun() getting redefined and trigger ECOPR00 below??? |
847
|
|
|
|
|
|
|
# START HERE: why is sun() getting redefined and trigger ECOPR00 below??? |
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
|
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
|
852
|
|
|
|
|
|
|
# RPerl::diag( "in Class::activate_subroutine(), $subroutine_name is a non-method subroutine\n" ); |
853
|
|
|
|
|
|
|
if ( eval( 'defined(&main::' . $subroutine_name . ')' ) ) { |
854
|
|
|
|
|
|
|
croak |
855
|
|
|
|
|
|
|
"ERROR ECOPR00, Pre-Processor: Attempt by package '$package_name' to re-define shared global subroutine '$subroutine_name', please re-name your subroutine or make it a method, croaking"; |
856
|
|
|
|
|
|
|
} |
857
|
|
|
|
|
|
|
|
858
|
|
|
|
|
|
|
# DEV NOTE: must load into both main:: and $package_name:: namespaces, |
859
|
|
|
|
|
|
|
# in order to call subroutines w/out class prefix from within class file (package) itself, and not to use AUTOLOAD |
860
|
|
|
|
|
|
|
if ( $package_name eq '' ) { $package_name_tmp = 'main'; } |
861
|
|
|
|
|
|
|
else { $package_name_tmp = $package_name; } |
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
# $subroutine_definition_diag_code = "\n" . q{RPerl::diag("IN POST-INIT, subroutine direct call MODE main::} . $subroutine_name . q{\n"; } . "\n"); |
864
|
|
|
|
|
|
|
$subroutine_definition_code |
865
|
|
|
|
|
|
|
= '*{main::' |
866
|
|
|
|
|
|
|
. $subroutine_name |
867
|
|
|
|
|
|
|
. '} = sub { ' |
868
|
|
|
|
|
|
|
. $subroutine_definition_diag_code |
869
|
|
|
|
|
|
|
. $subroutine_arguments_check_code |
870
|
|
|
|
|
|
|
. 'return &${' |
871
|
|
|
|
|
|
|
. $package_name_tmp . '::' |
872
|
|
|
|
|
|
|
. $subroutine_name |
873
|
|
|
|
|
|
|
. '}(@ARG); };'; |
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
# if ($subroutine_arguments_check_code ne q{}) { RPerl::diag('in Class::activate_subroutine(), have subroutine main:: $subroutine_definition_code =' . "\n" . $subroutine_definition_code . "\n"); } |
876
|
|
|
|
|
|
|
eval($subroutine_definition_code) |
877
|
|
|
|
|
|
|
or croak($EVAL_ERROR); |
878
|
|
|
|
|
|
|
if ($EVAL_ERROR) { croak($EVAL_ERROR); } |
879
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
# no package name means 'main', handled above |
881
|
|
|
|
|
|
|
if ( $package_name ne '' ) { |
882
|
|
|
|
|
|
|
|
883
|
|
|
|
|
|
|
# $subroutine_definition_diag_code = "\n" . {RPerl::diag("IN POST-INIT, subroutine direct call MODE } . $package_name . '::' . $subroutine_name . q{\n"; } . "\n"); |
884
|
|
|
|
|
|
|
$subroutine_definition_code |
885
|
|
|
|
|
|
|
= '*{' |
886
|
|
|
|
|
|
|
. $package_name . '::' |
887
|
|
|
|
|
|
|
. $subroutine_name |
888
|
|
|
|
|
|
|
. '} = sub {' |
889
|
|
|
|
|
|
|
. $subroutine_definition_diag_code |
890
|
|
|
|
|
|
|
. $subroutine_arguments_check_code |
891
|
|
|
|
|
|
|
. 'return &${' |
892
|
|
|
|
|
|
|
. $package_name . '::' |
893
|
|
|
|
|
|
|
. $subroutine_name |
894
|
|
|
|
|
|
|
. '}(@ARG); };'; |
895
|
|
|
|
|
|
|
|
896
|
|
|
|
|
|
|
# if ($subroutine_arguments_check_code ne q{}) { |
897
|
|
|
|
|
|
|
# RPerl::diag('in Class::activate_subroutine(), have subroutine package:: $subroutine_definition_code =' . "\n" . $subroutine_definition_code . "\n"); |
898
|
|
|
|
|
|
|
# } |
899
|
|
|
|
|
|
|
eval($subroutine_definition_code) |
900
|
|
|
|
|
|
|
or croak($EVAL_ERROR); |
901
|
|
|
|
|
|
|
if ($EVAL_ERROR) { croak($EVAL_ERROR); } |
902
|
|
|
|
|
|
|
} |
903
|
|
|
|
|
|
|
} |
904
|
|
|
|
|
|
|
} |
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
1; # end of class |
907
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
__END__ |
909
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
# RPerl function/method autoloader, LONG FORM; allows syntax for typed functions/methods and automates get/set accessors/mutators for object properties; |
911
|
|
|
|
|
|
|
# creates real subroutines to avoid AUTOLOADing any function/method more than once, performs operation inside AUTOLOAD that one time |
912
|
|
|
|
|
|
|
# now fully deprecated in favor of INIT block above |
913
|
|
|
|
|
|
|
our $AUTOLOAD; |
914
|
|
|
|
|
|
|
sub AUTOLOAD |
915
|
|
|
|
|
|
|
{ |
916
|
|
|
|
|
|
|
RPerl::diag("IN AUTOLOAD, top of subroutine, received \$AUTOLOAD = '$AUTOLOAD', and \@ARG =\n" . Dumper(\@ARG) . "\n"); |
917
|
|
|
|
|
|
|
no strict; |
918
|
|
|
|
|
|
|
my $retval; |
919
|
|
|
|
|
|
|
|
920
|
|
|
|
|
|
|
# DISABLE RUNTIME ACCESSOR/MUTATOR BEHAVIOR |
921
|
|
|
|
|
|
|
# if ($AUTOLOAD =~ /^([\w+::]*)(get|set)_(\w+)$/) |
922
|
|
|
|
|
|
|
if (0) |
923
|
|
|
|
|
|
|
{ |
924
|
|
|
|
|
|
|
RPerl::diag("IN AUTOLOAD, accessor/mutator MODE, have \$1 = '$1', \$2 = '$2', \$3 = '$3'\n"); |
925
|
|
|
|
|
|
|
if ($2 eq 'get') |
926
|
|
|
|
|
|
|
{ |
927
|
|
|
|
|
|
|
RPerl::diag("IN AUTOLOAD, accessor MODE\n"); |
928
|
|
|
|
|
|
|
# eval "\*\{$AUTOLOAD\} \= sub \{ return \$\_\[0\]\-\>\{$3\}\; \}\;"; |
929
|
|
|
|
|
|
|
eval "\*\{$AUTOLOAD\} \= sub \{ RPerl::diag(\"IN POST\-AUTOLOAD\, accessor MODE $AUTOLOAD\\n\"\; return \$\_\[0\]\-\>\{$3\}\; \}\;"; |
930
|
|
|
|
|
|
|
$retval = $_[0]->{$3}; |
931
|
|
|
|
|
|
|
} |
932
|
|
|
|
|
|
|
else # ($2 eq 'set') |
933
|
|
|
|
|
|
|
{ |
934
|
|
|
|
|
|
|
RPerl::diag("IN AUTOLOAD, mutator MODE\n"); |
935
|
|
|
|
|
|
|
# eval "\*\{$AUTOLOAD\} \= sub \{ \$\_\[0\]\-\>\{$3\} \= \$\_\[1\]\; return \$\_\[0\]\-\>\{$3\}\; \}\;"; |
936
|
|
|
|
|
|
|
eval "\*\{$AUTOLOAD\} \= sub \{ RPerl::diag(\"IN POST\-AUTOLOAD\, mutator MODE $AUTOLOAD\\n\"\; \$\_\[0\]\-\>\{$3\} \= \$\_\[1\]\; return \$\_\[0\]\-\>\{$3\}\; \}\;"; |
937
|
|
|
|
|
|
|
$_[0]->{$3} = $_[1]; |
938
|
|
|
|
|
|
|
$retval = $_[0]->{$3}; |
939
|
|
|
|
|
|
|
} |
940
|
|
|
|
|
|
|
} |
941
|
|
|
|
|
|
|
else |
942
|
|
|
|
|
|
|
{ |
943
|
|
|
|
|
|
|
RPerl::diag("IN AUTOLOAD, direct call MODE\n"); |
944
|
|
|
|
|
|
|
# disable creating symtab entries here to avoid redefining subroutines in INIT block above; |
945
|
|
|
|
|
|
|
# still need direct call mode here in case we want to call an RPerl function/method before the INIT block executes, |
946
|
|
|
|
|
|
|
# such as when an RPerl class calls one of it's own functions/methods during compile time |
947
|
|
|
|
|
|
|
# eval "\*\{$AUTOLOAD\} \= sub \{ return \&\$\{$AUTOLOAD\}\(\@\_\)\; \}\;"; # NEED UPGRADE: how can I do this w/out a subroutine? |
948
|
|
|
|
|
|
|
# eval "\*\{$AUTOLOAD\} \= sub \{ RPerl::diag(\"IN POST\-AUTOLOAD\, direct call MODE $AUTOLOAD\\n\"\; return \&\$\{$AUTOLOAD\}\(\@\_\)\; \}\;"; # NEED UPGRADE: how can I do this w/out a subroutine? |
949
|
|
|
|
|
|
|
if (defined(${$AUTOLOAD})) { $retval = &${$AUTOLOAD}(@ARG); } |
950
|
|
|
|
|
|
|
else { die "Attempt to AUTOLOAD undefined subroutine '$AUTOLOAD', dying"; } |
951
|
|
|
|
|
|
|
} |
952
|
|
|
|
|
|
|
# is there any reason to encapsulate calls in an eval() to trap their errors??? |
953
|
|
|
|
|
|
|
# else |
954
|
|
|
|
|
|
|
# { |
955
|
|
|
|
|
|
|
# my $eval_string = '&$' . $AUTOLOAD . '(@ARG);'; |
956
|
|
|
|
|
|
|
# RPerl::diag("IN AUTOLOAD, eval call MODE, have \$eval_string = '$eval_string'\n"); |
957
|
|
|
|
|
|
|
# $retval = eval $eval_string; |
958
|
|
|
|
|
|
|
# } |
959
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
croak $EVAL_ERROR if ($EVAL_ERROR); # suppress '...propagated at RPerl/Class.pm' appended exception |
961
|
|
|
|
|
|
|
# croak if ($EVAL_ERROR); # allow '...propagated at RPerl/Class.pm' appended exception |
962
|
|
|
|
|
|
|
|
963
|
|
|
|
|
|
|
# RPerl::diag("IN AUTOLOAD, bottom of subroutine, about to return \$retval = '$retval'\n"); |
964
|
|
|
|
|
|
|
return $retval; |
965
|
|
|
|
|
|
|
} |
966
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
# RPerl object constructor, LONG FORM |
968
|
|
|
|
|
|
|
# DEPRECATED still uses %properties hash instead of $properties hashref |
969
|
|
|
|
|
|
|
#sub new($class_name_const_str) |
970
|
|
|
|
|
|
|
sub new_LONG FORM |
971
|
|
|
|
|
|
|
{ |
972
|
|
|
|
|
|
|
(my $class_name_const_str) = @ARG; |
973
|
|
|
|
|
|
|
RPerl::diag("in Class.pm, have \$class_name_const_str = '$class_name_const_str'\n"); |
974
|
|
|
|
|
|
|
my $properties_name_const_str = $class_name_const_str . '::properties'; |
975
|
|
|
|
|
|
|
RPerl::diag("in Class.pm, have \$properties_name_const_str = '$properties_name_const_str'\n"); |
976
|
|
|
|
|
|
|
my %properties = %{$properties_name_const_str}; |
977
|
|
|
|
|
|
|
RPerl::diag("in Class.pm, have \%properties =\n" . Dumper(\%properties) . "\n"); |
978
|
|
|
|
|
|
|
# my $new_obj = bless({%{$class_name_const_str . '::properties'}}, $class_name_const_str); |
979
|
|
|
|
|
|
|
my $new_obj = bless({%properties}, $class_name_const_str); |
980
|
|
|
|
|
|
|
RPerl::diag("in Class.pm, have \$new_obj =\n" . Dumper($new_obj) . "\n"); |
981
|
|
|
|
|
|
|
return $new_obj; |
982
|
|
|
|
|
|
|
} |