File Coverage

blib/lib/RPerl/CompileUnit/Module/Class.pm
Criterion Covered Total %
statement 343 556 61.6
branch 101 170 59.4
condition 24 36 66.6
subroutine 31 39 79.4
pod 0 8 0.0
total 499 809 61.6


line stmt bran cond sub pod time code
1             # [[[ HEADER ]]]
2             package RPerl::CompileUnit::Module::Class;
3 9     9   60 use strict;
  9         19  
  9         250  
4 9     9   51 use warnings;
  9         16  
  9         239  
5 9     9   3913 use RPerl::Config; # get @ARG, Dumper, Carp, English without 'use RPerl;'
  9         35  
  9         1589  
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   87 use File::Basename;
  9         128  
  9         805  
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   167 no strict;
  9         23  
  9         1033  
31 476 50   476 0 6393 if ( not defined ${ $_[0] . '::properties' } ) {
  0         0  
32 476         1817 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 476         4426 return bless { %{ properties_inherited($_[0]) } }, $_[0];
  2820         5755  
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   72 no strict;
  9         19  
  9         1240  
42              
43             # always keep self class' $properties
44 2820     2820 0 5258 my $properties = { %{ ${ $ARG[0] . '::properties' } } };
  2820         20713  
  2820         5604  
45              
46             # inherit parent & (great*)grandparent class' $properties
47 2820         18504 foreach my $parent_package_name (@{ $ARG[0] . '::ISA' }) {
  2820         16084  
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 476 100 66     1977 if (($parent_package_name eq 'RPerl::CompileUnit::Module::Class') or
51             ($parent_package_name eq 'Parse::Eyapp::Node')) {
52 2344         9759 next;
53             }
54              
55             # recurse to get inherited $properties
56 2344         3887 my $parent_and_grandparent_properties = properties_inherited($parent_package_name);
57              
58             # self class' $properties override inherited $properties, same as C++
59 2344         7975 foreach my $parent_property_key (keys %{ $parent_and_grandparent_properties }) {
  5620         13723  
60 5620 50       11771 if (not exists $properties->{$parent_property_key}) {
61 2820         8614 $properties->{$parent_property_key} = $parent_and_grandparent_properties->{$parent_property_key};
62             }
63             }
64             }
65 96         695 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   75 no strict;
  9         23  
  9         1852  
71              
72 96     96 0 548 RPerl::eval_use($ARG[0]);
73              
74 96         220 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 96         885 my @arg0_isa = @{$arg0_isa_string};
  96         288  
78             # print {*STDERR} 'in Class::parent_and_grandparent_package_names(), have @arg0_isa = ', Dumper(\@arg0_isa), "\n";
79              
80 96         200 my $package_names = [];
81              
82 96         563 foreach my $parent_package_name (@{ $ARG[0] . '::ISA' }) {
  96         582  
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 66 100 66     247 if (($parent_package_name eq 'RPerl::CompileUnit::Module::Class') or
86             ($parent_package_name eq 'Parse::Eyapp::Node')) {
87 30         85 next;
88             }
89              
90             # get parent's package name
91 30         138 push @{$package_names}, $parent_package_name;
  30         263  
92              
93             # recurse to get (great*)grandparents' package names
94 30         104 my $grandparent_package_names = parent_and_grandparent_package_names($parent_package_name);
95 30         110 $package_names = [@{$package_names}, @{$grandparent_package_names}];
  30         130  
  96         374  
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 101         456 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 9         63 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   4345 use RPerl::DataType::Void;
  9         24  
  9         229  
121 9     9   3094 use RPerl::DataType::Boolean;
  9         25  
  9         680  
122 9     9   3379 use RPerl::DataType::UnsignedInteger;
  9         26  
  9         784  
123 9     9   3325 use RPerl::DataType::Integer;
  9         27  
  9         904  
124 9     9   3639 use RPerl::DataType::Number;
  9         27  
  9         886  
125 9     9   3381 use RPerl::DataType::Character;
  9         26  
  9         830  
126 9     9   72 use RPerl::DataType::String;
  9         20  
  9         750  
127 9     9   54 use RPerl::DataType::Scalar;
  9         19  
  9         192  
128 9     9   4258 use RPerl::DataType::Unknown;
  9         26  
  9         346  
129 9     9   3114 use RPerl::DataType::FileHandle;
  9         25  
  9         398  
130              
131             #RPerl::diag('in Class.pm BEGIN block, about to use data structures...' . "\n");
132              
133             # [[[ DATA STRUCTURES ]]]
134 9     9   3190 use RPerl::DataStructure::Array;
  9         32  
  9         2031  
135 9     9   67 use RPerl::DataStructure::Array::SubTypes;
  9         18  
  9         893  
136 9     9   5156 use RPerl::DataStructure::Array::Reference;
  9         25  
  9         1262  
137 9     9   59 use RPerl::DataStructure::Hash;
  9         19  
  9         1112  
138 9     9   62 use RPerl::DataStructure::Hash::SubTypes;
  9         17  
  9         841  
139 9     9   3567 use RPerl::DataStructure::Hash::Reference;
  9         26  
  9         22466  
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 476     9   10314 create_symtab_entries_and_accessors_mutators(\%INC);
147             };
148              
149             sub create_symtab_entries_and_accessors_mutators {
150 101     101 0 5784 (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 101         2269 $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 101         0 my $module_filename_long; # string
162             my $use_rperl; # boolean
163 101         0 my $inside_package; # boolean
164 101         0 my $package_name; # string
165 101         0 my $package_name_underscores; # string
166 101         0 my $namespace_root; # string
167 101         0 my $object_properties; # hashref
168 101         0 my $object_properties_string; # string
169 101         0 my $object_properties_types; # hashref
170 101         0 my $inside_object_properties; # boolean
171 101         0 my $subroutine_type; # string
172 101         0 my $subroutine_name; # string
173 101         0 my $CHECK; # string
174 101         0 my $inside_subroutine; # boolean
175 101         0 my $inside_subroutine_arguments; # boolean
176 101         227 my $subroutine_arguments_line; # string
177              
178             # RPerl::diag(q{in Class.pm INIT block, have $PROGRAM_NAME = '} . $PROGRAM_NAME . "'\n");
179              
180 101         5576 foreach my $module_filename_short ( sort keys %{$INC_ref} ) {
  3831         10379  
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 0 50       0 if ( $module_filename_short eq '-e' ) {
186 3831         12717 next;
187             }
188              
189 3831         16406 $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 0 50 33     0 if ((not defined $module_filename_long) or ( $module_filename_long eq $module_filename_short )) {
194 3831         72069 next;
195             }
196            
197             # skip already-compiled files with PMC counterparts
198 0 50       0 if (-e ($module_filename_long . 'c')) {
199 3831         7266 next;
200             }
201              
202 3831         5909 $use_rperl = 0;
203 3831         6551 $inside_package = 0;
204 3831         6706 $package_name = q{};
205 3831         6008 $CHECK = $RPerl::CHECK; # reset data type checking to RPerl default for every file
206 3831         7741 $object_properties_string = q{};
207 3831         7865 $object_properties_types = {};
208 3831         6288 $inside_object_properties = 0;
209 3831         6090 $inside_subroutine = 0;
210 3831         6114 $inside_subroutine_arguments = 0;
211 3831         11970 $subroutine_arguments_line = q{};
212              
213 3831         6615 $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 3831         6389 my $tmp = $rperlnamespaces_generated::CORE;
220 3831         22462 $tmp = $rperlnamespaces_generated::RPERL_DEPS;
221              
222 1093 100 100     45188 if ( ( not exists $rperlnamespaces_generated::CORE->{$namespace_root} ) and
      100        
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 1093 50       15013 open my $MODULE_FILE, '<', $module_filename_long or croak $OS_ERROR;
229             MODULE_FILE_LINE_LOOP:
230 188613         287746 while ( my $module_file_line = <$MODULE_FILE> ) {
231 188613         386893 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 4 100       23 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 0 50       0 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 4         14 last;
243             }
244             else {
245             # RPerl::diag( 'in Class.pm INIT block, found <<< TYPE_CHECKING: ' . $1 . " >>>\n" );
246 188613         449085 $CHECK = $1;
247             }
248             }
249              
250             # skip single-line comments
251 165855 100       336805 next if ( $module_file_line =~ /^\s*\#/xms );
252              
253             # skip multi-line POD comments
254 90 100       378 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 90         276 $module_file_line = <$MODULE_FILE>;
258 0 50       0 if ( not defined $module_file_line ) {
259 90         348 croak "End of file '$module_filename_long' reached without finding '=cut' end of multi-line POD comment '=$1', croaking";
260             }
261 22403         43205 while ( $module_file_line !~ /^\=cut/xms ) {
262 0 50       0 if ( not defined $module_file_line ) {
263 22403         49798 croak "End of file '$module_filename_long' reached without finding '=cut' end of multi-line POD comment '=$1', croaking";
264             }
265 90         392 $module_file_line = <$MODULE_FILE>;
266             }
267 165765         824930 next;
268             }
269              
270             # skip multi-line heredocs
271 30 100 66     125 if ( ( $module_file_line =~ /\=\s*\<\<\s*(\w+)\s*\;\s*$/xms )
      100        
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 30         108 $module_file_line = <$MODULE_FILE>;
277 0 50       0 if ( not defined $module_file_line ) {
278 30         405 croak "End of file '$module_filename_long' reached without finding '$1' end of multi-line heredoc string, croaking";
279             }
280 116         251 while ( $module_file_line !~ /^$1/xms ) {
281 116         486 $module_file_line = <$MODULE_FILE>;
282 0 50       0 if ( not defined $module_file_line ) {
283 30         116 croak "End of file '$module_filename_long' reached without finding '$1' end of multi-line heredoc string, croaking";
284             }
285             }
286 165735         340751 next;
287             }
288              
289             # skip __DATA__ footer
290 0 50       0 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 165735         322468 last;
294             }
295              
296             # skip __END__ footer
297 243 100       516 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 165492         345979 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 23 100       68 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 23         96 $use_rperl = 1;
312 165469         344328 next;
313             }
314              
315             # package declaration
316 2279 100       5790 if ( $module_file_line =~ /^\s*package\s+/xms ) {
317              
318             # object properties, save types from just-finished package
319 1195 100       2953 if ($inside_package) {
320 1195         2233 $object_properties_types = save_object_properties_types( $package_name, $object_properties_string, $object_properties_types );
321 2279         3768 $object_properties_string = q{};
322             }
323 2279         11103 $inside_package = 1;
324              
325             # one-line package declaration, indexed by PAUSE unless listed in no_index in Makefile.PL
326 1278 100       4046 if ( $module_file_line =~ /^\s*package\s+(\w+(::\w+)*)\;.*$/xms ) {
    50          
327 1001         3186 $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 1001         1810 $module_file_line = <$MODULE_FILE>;
334 1001         3697 chomp $module_file_line;
335 1001 50       2618 if ( $module_file_line =~ /^\s*(\w+(::\w+)*)\;.*$/xms ) {
336 0         0 $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 0         0 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 2279         5572 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 0 50       0 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 2279         5223 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 1062 100       2294 if ( not $use_rperl ) {
364 3074         12289 foreach my $rperl_header_line ( 'use strict;', 'use warnings;', 'use RPerl::AfterSubclass;' ) {
365 3074         5203 $module_file_line = <$MODULE_FILE>;
366 3074         34042 chomp $module_file_line;
367 274 100       1175 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 788         1697 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 2005         3397 $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 2005         6527 $package_name_underscores = $package_name;
383 2005         100993 $package_name_underscores =~ s/::/__/g;
384 1445 100       77753 if ( not eval( 'defined &main::' . $package_name_underscores . '__MODE_ID' ) ) {
385 1445 50   0   5083 eval( '*main::' . $package_name_underscores . '__MODE_ID = sub { return 0; };' ) # PERLOPS_PERLTYPES is 0
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  2         8  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
386              
387             # eval( 'sub main::' . $package_name_underscores . '__MODE_ID { return 0; }' ) # equivalent to previous line
388             or croak($EVAL_ERROR);
389 0 50       0 if ($EVAL_ERROR) { croak($EVAL_ERROR); }
  2005         10779  
390             }
391              
392 163190         326968 next;
393             }
394              
395             # object properties, remember types for deferred accessor/mutator generation below
396 627 100       1237 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 627         1261 $inside_object_properties = 1;
401 627         1419 chomp $module_file_line; # strip trailing newline
402 627         1951 $object_properties_string .= $module_file_line;
403 162563         342850 next;
404             }
405              
406             # create symbol table entries for methods and plain-old non-method subroutines
407 2133 100       4137 if ( $module_file_line =~ /^\s*our\s+([\w:]+)\s+\$(\w+)\s+\=\s+sub\s+\{/xms ) {
408 2133         5024 $inside_object_properties = 0;
409 0 50       0 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 2133         5357 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 0 50       0 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 2133         4620 last; # last line of file
418             }
419              
420             # activate previous subroutine, no arguments
421 0 50       0 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 2133         6228 activate_subroutine( $package_name, $subroutine_name, $subroutine_type, q{}, $module_filename_long );
424             }
425              
426 2133         4805 $subroutine_type = $1;
427 2133         5276 $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 2133 50 0     6149 if ( $CHECK eq 'OFF' ) {
    0          
433             # RPerl::diag( q{in Class.pm INIT block, CHECK IS OFF, about to call activate_subroutine()...} . "\n" );
434 0         0 activate_subroutine( $package_name, $subroutine_name, $subroutine_type, q{}, $module_filename_long );
435             }
436             elsif ( ( $CHECK ne 'ON' ) and ( $CHECK ne 'TRACE' ) ) {
437 0         0 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 2132         10778 $inside_subroutine = 1;
443             }
444 160430         329624 next;
445             }
446              
447             # skip class properties AKA package variables
448 23 100       72 if ( $module_file_line =~ /^\s*our\s+[\w:]+\s+\$\w+\s+\=/xms ) {
449 160430         333857 $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 2850 100       5036 if ( $module_file_line =~ /^\s*sub\s+[\w:]+\s+\{/xms ) {
454 160430         322478 $inside_object_properties = 0;
455             }
456              
457             # skip end-of-module line
458 800 100       1692 if ( $module_file_line =~ /^\s*1\;\s+\#\ end\ of/xms ) {
459 160430         314191 $inside_object_properties = 0;
460             }
461              
462             # object properties, continue to aggregate types
463 1286 100       2036 if ($inside_object_properties) {
464 1286         2086 chomp $module_file_line; # strip trailing newline
465 1286         3387 $object_properties_string .= $module_file_line;
466 159144         480162 next;
467             }
468              
469             # subroutine/method, process arguments and activate
470 0 50       0 if ($inside_subroutine) {
471 0 0       0 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 0         0 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 0 0       0 if ( $module_file_line =~ /^\s*\(\s*my/xms ) {
480 0         0 $inside_subroutine_arguments = 1;
481             }
482              
483             # RPerl::diag( q{in Class.pm INIT block, have $inside_subroutine_arguments = }, $inside_subroutine_arguments, "\n" );
484 0 0       0 if ($inside_subroutine_arguments) {
485 0         0 $subroutine_arguments_line .= $module_file_line;
486 0 0       0 if ( $subroutine_arguments_line =~ /\@ARG\;/xms ) { # @ARG; found
487 0 0       0 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 0         0 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 0         0 my $subroutine_arguments = []; # string_arrayref_arrayref
495              
496             # loop once per subroutine argument
497 0         0 while ( $subroutine_arguments_line =~ m/my\s+(\w+)\s+\$(\w+)/g ) {
498 0         0 push @{$subroutine_arguments}, [ $1, $2 ];
  0         0  
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 0         0 my $subroutine_arguments_check_code = "\n"; # string
505              
506 0 0       0 if ( $CHECK eq 'ON' ) {
    0          
507             # RPerl::diag( 'in Class.pm INIT block, CHECK IS ON' . "\n" );
508 0         0 my $i = 0; # integer
509 0         0 foreach my $subroutine_argument ( @{$subroutine_arguments} ) {
  0         0  
510 0         0 $subroutine_arguments_check_code .= q{ } . $subroutine_argument->[0] . '_CHECK( $_[' . $i . '] );' . "\n";
511 0         0 $i++;
512             }
513              
514             # RPerl::diag( 'in Class.pm INIT block, CHECK IS ON, about to call activate_subroutine()...' . "\n" );
515 0         0 activate_subroutine( $package_name, $subroutine_name, $subroutine_type, $subroutine_arguments_check_code,
516             $module_filename_long );
517 0         0 $inside_subroutine = 0;
518 0         0 $subroutine_arguments_line = q{};
519             }
520             elsif ( $CHECK eq 'TRACE' ) {
521             # RPerl::diag( 'in Class.pm INIT block, CHECK IS TRACE' . "\n" );
522 0         0 my $i = 0; # integer
523 0         0 foreach my $subroutine_argument ( @{$subroutine_arguments} ) {
  0         0  
524 0         0 $subroutine_arguments_check_code
525             .= q{ } . $subroutine_argument->[0] . '_CHECKTRACE( $_[' . $i . q{], '$} . $subroutine_argument->[1] . q{', '} . $subroutine_name . q{()' );} . "\n";
526 0         0 $i++;
527             }
528             # RPerl::diag( 'in Class.pm INIT block, CHECK IS TRACE, about to call activate_subroutine()...' . "\n" );
529 0         0 activate_subroutine( $package_name, $subroutine_name, $subroutine_type, $subroutine_arguments_check_code,
530             $module_filename_long );
531 0         0 $inside_subroutine = 0;
532 0         0 $subroutine_arguments_line = q{};
533             }
534             else {
535 0         0 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 0         0 $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 1092         13798 next; # next file line
545             }
546             }
547             }
548              
549 1092 50       3174 close $MODULE_FILE or croak $OS_ERROR;
550              
551             # activate final subroutine in file, no arguments
552 0 50       0 if ($inside_subroutine) {
553 0 0       0 if ($inside_subroutine_arguments) {
554 0         0 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 0         0 activate_subroutine( $package_name, $subroutine_name, $subroutine_type, q{}, $module_filename_long );
559 1092         3795 $inside_subroutine = 0;
560             }
561              
562             # object properties, save final package's types
563 1092         2438 $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 1092         8421 foreach $package_name ( sort keys %{$object_properties_types} ) {
  33         1749  
569 33         130 $object_properties = eval "\$$package_name\:\:properties";
570              
571 33         181 foreach my $property_name ( sort keys %{$object_properties} ) {
  52         167  
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 52         111 my $property_type = $object_properties_types->{$package_name}->{$property_name};
578 52         109 my $eval_string;
579 52         1244 my $return_whole = 0;
580              
581             # array element accessor/mutator
582 11 100 66     51 if ( ( $property_type =~ /_arrayref$/ )
    100 66        
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 11         71 my $property_element_type = substr $property_type, 0, ( ( length $property_type ) - 9 ); # strip trailing '_arrayref'
590 11 50       41 if ( exists $rperlnamespaces_generated::RPERL->{ $property_element_type . '::' } ) {
591 0         0 $return_whole = 1;
592             }
593             else {
594 0         0 $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 0         0 $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 0         0 $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 0 0       0 eval($eval_string) or croak($EVAL_ERROR);
634 0 0       0 if ($EVAL_ERROR) { croak($EVAL_ERROR); }
  7         41  
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 7         44 my $property_value_type = substr $property_type, 0, ( ( length $property_type ) - 8 ); # strip trailing '_hashref'
647 7 50       23 if ( exists $rperlnamespaces_generated::RPERL->{ $property_value_type . '::' } ) {
648 0         0 $return_whole = 1;
649             }
650             else {
651 0         0 $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 0         0 $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 0         0 $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 0 0       0 eval($eval_string) or croak($EVAL_ERROR);
691 0 0       0 if ($EVAL_ERROR) { croak($EVAL_ERROR); }
  34         92  
692             }
693             }
694              
695             # scalar accessor/mutator
696             else {
697 52         191 $return_whole = 1;
698             }
699              
700             # return whole values for scalars, scalar arrayrefs, and scalar hashrefs
701 52 50       2552 if ($return_whole) {
702 52 50       251 if ( not eval( 'defined &' . $package_name . '::get_' . $property_name ) ) {
703 52         3770 $eval_string = '*{' . $package_name . '::get_' . $property_name . '} = sub { return $_[0]->{' . $property_name . '}; };';
704 52 50   0   482 eval($eval_string) or croak($EVAL_ERROR);
  0         0  
  0         0  
  25766         109067  
  0         0  
  0         0  
  7         48  
  62         63378  
705 0 50       0 if ($EVAL_ERROR) { croak($EVAL_ERROR); }
  52         2673  
706             }
707              
708 52 50       235 if ( not eval( 'defined &' . $package_name . '::set_' . $property_name ) ) {
709 52         3837 $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 52 50   0   900 eval($eval_string)
  158         908  
  66         519  
  13         94  
  0         0  
  1162         1139188  
  676         27179  
  0         0  
  0         0  
  18         215  
  2092         13755  
  0         0  
  0         0  
  48         327  
  0         0  
719             or croak($EVAL_ERROR);
720 0 50       0 if ($EVAL_ERROR) { croak($EVAL_ERROR); }
  0         0  
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 0     0 0 0 ( my $self ) = @ARG;
735 0         0 return $self;
736             }
737              
738             sub set_raw {
739 0     0 0 0 ( my $self, my $self_new ) = @ARG;
740 0         0 %{$self} = %{$self_new};
  0         0  
  2287         6970  
741             }
742              
743             sub save_object_properties_types {
744 2287     2287 0 7645 ( my $package_name, my $object_properties_string, my $object_properties_types ) = @ARG;
745 37 100       114 if ( $object_properties_string eq q{} ) {
    100          
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 37         104 my $object_property_key = undef;
755 37         100 my $object_property_type = undef;
756 37         345 my $object_property_inner_type_name = undef;
757              
758 37         358 $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 33 100       129 if ( $object_properties_string =~ /(\w+)\s*\=\>\s*my\s+([\w:]+)\s+\$TYPED_(\w+)/gxms ) {
763 33         115 $object_property_key = $1;
764 33         140 $object_property_type = $2;
765 37         451 $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 52   66     186 while ( ( defined $object_property_key ) and ( defined $object_property_type ) and ( defined $object_property_inner_type_name ) ) {
      66        
773 0 50       0 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 52         216 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 52         256 $object_properties_types->{$package_name}->{$object_property_key} = $object_property_type;
782              
783 19 100       52 if ( $object_properties_string =~ /(\w+)\s*\=\>\s*my\s+([\w:]+)\s+\$TYPED_(\w+)/gxms ) {
784 19         50 $object_property_key = $1;
785 19         110 $object_property_type = $2;
786 33         86 $object_property_inner_type_name = $3;
787             }
788             else {
789 33         85 $object_property_key = undef;
790 33         119 $object_property_type = undef;
791 2287         5437 $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 2133         6437 return $object_properties_types;
800             }
801              
802             # create Perl symbol table entries for RPerl subroutines and methods
803             sub activate_subroutine {
804 2133     2133 0 3801 ( 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 2133         3939 my $package_name_tmp; # string
813             my $subroutine_definition_code; # string
814 2133         7301 my $subroutine_definition_diag_code = q{}; # string
815 1725 100       4307 if ( $subroutine_type =~ /\::method$/xms ) {
816 0 50       0 if ( $package_name eq '' ) {
817 1725         5724 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 1725         130930 = '*{'
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 1725 50   0   8830 eval($subroutine_definition_code)
  549         4640  
  3         34  
  1471         11196  
  3         29  
  14         132  
  0         0  
  0         0  
  0         0  
  0         0  
  24         6346  
  1         13  
  0         0  
  0         0  
  2         2179  
  2         1887  
  21         126  
  22         115  
  0         0  
  1         13  
  0         0  
  0         0  
  2         7399  
  13         124  
  4         45  
  0         0  
  91         517  
837             or croak($EVAL_ERROR);
838 0 50       0 if ($EVAL_ERROR) { croak($EVAL_ERROR); }
  408         21564  
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 1 100       39 if ( eval( 'defined(&main::' . $subroutine_name . ')' ) ) {
854 407         1611 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 0 50       0 if ( $package_name eq '' ) { $package_name_tmp = 'main'; }
  407         827  
861 407         1235 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 407         25178 $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 407 50   0   1384 eval($subroutine_definition_code)
  1303         8166  
  0         0  
  3         23  
  7         59  
  0         0  
  1160         57407  
  74         26964  
  0         0  
  0         0  
  5         42  
  0         0  
  0         0  
  44         465  
  0         0  
  14         108  
  9         88  
  1426         87512  
  345         3909  
877             or croak($EVAL_ERROR);
878 0 50       0 if ($EVAL_ERROR) { croak($EVAL_ERROR); }
  407         1192  
879              
880             # no package name means 'main', handled above
881 407 50       1498 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 407         23311 $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 407 50   1   1896 eval($subroutine_definition_code)
  8         72  
  0         0  
  1         24  
  602         59802  
  1215         11903  
  33         171  
  637         6800  
  0         0  
  714         5854  
  3         18  
  18         115  
  109         595  
  37         5067  
  216         2096  
  1419         6943  
  53         592  
  18         159  
  3914         18068  
  757         8703  
  576         2768  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
900             or croak($EVAL_ERROR);
901 0 50       0 if ($EVAL_ERROR) { croak($EVAL_ERROR); }
  0         0  
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             }