File Coverage

blib/lib/RPerl/DataStructure/Array/SubTypes.pm
Criterion Covered Total %
statement 417 521 80.0
branch 30 62 48.3
condition 3 6 50.0
subroutine 102 111 91.8
pod n/a
total 552 700 78.8


line stmt bran cond sub pod time code
1             ## no critic qw(ProhibitUselessNoCritic PodSpelling ProhibitExcessMainComplexity) # DEVELOPER DEFAULT 1a: allow unreachable & POD-commented code; SYSTEM SPECIAL 4: allow complex code outside subroutines, must be on line 1
2             package RPerl::DataStructure::Array::SubTypes;
3 7     7   42 use strict;
  7         15  
  7         456  
4 7     7   37 use warnings;
  7         15  
  7         162  
5 7     7   36 use RPerl::AfterSubclass;
  7         15  
  7         911  
6             our $VERSION = 0.013_000;
7              
8             # [[[ CRITICS ]]]
9             ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
10             ## no critic qw(ProhibitUnreachableCode RequirePodSections RequirePodAtEnd) # DEVELOPER DEFAULT 1b: allow unreachable & POD-commented code, must be after line 1
11             ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils
12             ## no critic qw(Capitalization ProhibitMultiplePackages ProhibitReusedNames) # SYSTEM DEFAULT 3: allow multiple & lower case package names
13              
14             # [[[ EXPORTS ]]]
15 7     7   42 use RPerl::Exporter 'import';
  7         16  
  7         38  
16             our @EXPORT = qw(arrayref_CHECK arrayref_CHECKTRACE integer_arrayref_CHECK integer_arrayref_CHECKTRACE number_arrayref_CHECK number_arrayref_CHECKTRACE string_arrayref_CHECK string_arrayref_CHECKTRACE integer_arrayref_to_string number_arrayref_to_string string_arrayref_to_string);
17             our @EXPORT_OK = qw(integer_arrayref__typetest0 integer_arrayref__typetest1 number_arrayref__typetest0 number_arrayref__typetest1 string_arrayref__typetest0 string_arrayref__typetest1);
18              
19             # [[[ INCLUDES ]]]
20 7     7   40 use RPerl::DataType::Integer; # integer_CHECKTRACE
  7         16  
  7         45  
21              
22             # [[[ PRE-DECLARED TYPES ]]]
23             package # hide from PAUSE indexing
24             boolean;
25             package # hide from PAUSE indexing
26             unsigned_integer;
27             #package # hide from PAUSE indexing
28             # integer;
29             package # hide from PAUSE indexing
30             number;
31             package # hide from PAUSE indexing
32             character;
33             package # hide from PAUSE indexing
34             string;
35              
36             # [[[ ARRAYS ]]]
37              
38             # an array is a 1-dimensional list/vector/sequence/set of data types;
39             # we never use this type directly, instead we always use the arrayref type,
40             # per LMPC #27: Thou Shalt Not Use Direct Access To Arrays & Hashes Stored In @ Or % Non-Scalar Variables
41             package # hide from PAUSE indexing
42             array;
43 7     7   40 use strict;
  7         14  
  7         123  
44 7     7   34 use warnings;
  7         13  
  7         192  
45 7     7   44 use parent qw(RPerl::DataStructure::Array);
  7         12  
  7         30  
46              
47             # [[[ ARRAY REF ]]]
48             # [[[ ARRAY REF ]]]
49             # [[[ ARRAY REF ]]]
50              
51             # ref to array
52             package # hide from PAUSE indexing
53             arrayref;
54 7     7   403 use strict;
  7         15  
  7         270  
55 7     7   40 use warnings;
  7         15  
  7         201  
56             #use parent -norequire, qw(ref); # NEED REMOVE: properly replaced by line below?
57 7     7   30 use parent -norequire, qw(RPerl::DataStructure::Array::Reference);
  7         14  
  7         25  
58 7     7   278 use Carp;
  7         13  
  7         348  
59              
60             # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
61             package RPerl::DataStructure::Array::SubTypes;
62 7     7   43 use strict;
  7         14  
  7         112  
63 7     7   27 use warnings;
  7         9  
  7         1379  
64              
65             # [[[ TYPE-CHECKING ]]]
66              
67             sub arrayref_CHECK {
68 0     0   0 { my void $RETURN_TYPE };
  0         0  
69 0         0 ( my $possible_arrayref ) = @ARG;
70 0 0       0 if ( not( defined $possible_arrayref ) ) {
71 0         0 croak(
72             "\nERROR EAVRV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref value expected but undefined/null value found,\ncroaking"
73             );
74             }
75              
76             # if ( UNIVERSAL::isa( $possible_arrayref, 'ARRAY' ) ) { # DEV NOTE: I believe these 2 lines are equivalent?
77 0 0       0 if ( not( main::RPerl_SvAROKp($possible_arrayref) ) ) {
78 0         0 croak(
79             "\nERROR EAVRV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref value expected but non-arrayref value found,\ncroaking"
80             );
81             }
82 0         0 return;
83             }
84              
85              
86             sub arrayref_CHECKTRACE {
87 0     0   0 { my void $RETURN_TYPE };
  0         0  
88 0         0 ( my $possible_arrayref, my $variable_name, my $subroutine_name ) = @ARG;
89 0 0       0 if ( not( defined $possible_arrayref ) ) {
90 0         0 croak(
91             "\nERROR EAVRV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
92             );
93             }
94 0 0       0 if ( not( main::RPerl_SvAROKp($possible_arrayref) ) ) {
95 0         0 croak(
96             "\nERROR EAVRV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref value expected but non-arrayref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
97             );
98             }
99 0         0 return;
100             }
101              
102             # [[[ INTEGER ARRAY REF ]]]
103             # [[[ INTEGER ARRAY REF ]]]
104             # [[[ INTEGER ARRAY REF ]]]
105              
106             # (ref to array) of integers
107             package # hide from PAUSE indexing
108             integer_arrayref;
109 7     7   40 use strict;
  7         20  
  7         113  
110 7     7   52 use warnings;
  7         12  
  7         200  
111 7     7   32 use parent -norequire, qw(arrayref);
  7         14  
  7         25  
112 7     7   238 use Carp;
  7         20  
  7         342  
113              
114             # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
115             package RPerl::DataStructure::Array::SubTypes;
116 7     7   35 use strict;
  7         14  
  7         113  
117 7     7   54 use warnings;
  7         11  
  7         3944  
118              
119             # [[[ TYPE-CHECKING ]]]
120              
121             sub integer_arrayref_CHECK {
122 0     0   0 { my void $RETURN_TYPE };
  0         0  
123 0         0 ( my $possible_integer_arrayref ) = @ARG;
124              
125             # DEV NOTE: the following two if() statements are functionally equivalent to the arrayref_CHECK() subroutine, but with integer-specific error codes
126 0 0       0 if ( not( defined $possible_integer_arrayref ) ) {
127 0         0 croak(
128             "\nERROR EIVAVRV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger_arrayref value expected but undefined/null value found,\ncroaking"
129             );
130             }
131              
132 0 0       0 if ( not( main::RPerl_SvAROKp($possible_integer_arrayref) ) ) {
133 0         0 croak(
134             "\nERROR EIVAVRV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger_arrayref value expected but non-arrayref value found,\ncroaking"
135             );
136             }
137              
138 0         0 my integer $possible_integer;
139 0         0 for my integer $i (
140 0         0 0 .. ( ( scalar @{$possible_integer_arrayref} ) - 1 ) )
141             {
142 0         0 $possible_integer = $possible_integer_arrayref->[$i];
143              
144             # DEV NOTE: the following two if() statements are functionally equivalent to the integer_CHECK() subroutine, but with array-specific error codes
145 0 0       0 if ( not( defined $possible_integer ) ) {
146 0         0 croak(
147             "\nERROR EIVAVRV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger_arrayref element value expected but undefined/null value found at index $i,\ncroaking"
148             );
149             }
150 0 0       0 if ( not( main::RPerl_SvIOKp($possible_integer) ) ) {
151 0         0 croak(
152             "\nERROR EIVAVRV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger_arrayref element value expected but non-integer value found at index $i,\ncroaking"
153             );
154             }
155             }
156 0         0 return;
157             };
158              
159              
160             sub integer_arrayref_CHECKTRACE {
161 19     19   25 { my void $RETURN_TYPE };
  19         23  
162 19         38 ( my $possible_integer_arrayref, my $variable_name, my $subroutine_name )
163             = @ARG;
164 19 100       39 if ( not( defined $possible_integer_arrayref ) ) {
165 3         44 croak(
166             "\nERROR EIVAVRV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger_arrayref value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
167             );
168             }
169 16 100       51 if ( not( main::RPerl_SvAROKp($possible_integer_arrayref) ) ) {
170 5         54 croak(
171             "\nERROR EIVAVRV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger_arrayref value expected but non-arrayref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
172             );
173             }
174              
175 11         16 my integer $possible_integer;
176 11         17 for my integer $i (
177 11         30 0 .. ( ( scalar @{$possible_integer_arrayref} ) - 1 ) )
178             {
179 48         63 $possible_integer = $possible_integer_arrayref->[$i];
180 48 100       70 if ( not( defined $possible_integer ) ) {
181 2         31 croak(
182             "\nERROR EIVAVRV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger_arrayref element value expected but undefined/null value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
183             );
184             }
185 46 100       94 if ( not( main::RPerl_SvIOKp($possible_integer) ) ) {
186 5         55 croak(
187             "\nERROR EIVAVRV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger_arrayref element value expected but non-integer value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
188             );
189             }
190             }
191 4         10 return;
192             }
193              
194             # [[[ STRINGIFY ]]]
195              
196             # convert from (Perl SV containing RV to (Perl AV of (Perl SVs containing IVs))) to Perl-parsable (Perl SV containing PV)
197             # stringify an integer_arrayref
198             sub integer_arrayref_to_string {
199 14     14   7380 { my string $RETURN_TYPE };
  14         24  
200             # require exactly one integer_arrayref as input, store in variable $input_avref
201 14         21 ( my integer_arrayref $input_avref ) = @ARG;
202              
203             # RPerl::diag("in PERLOPS_PERLTYPES integer_arrayref_to_string(), top of subroutine\n");
204              
205             # integer_arrayref_CHECK($input_avref);
206 14         330 integer_arrayref_CHECKTRACE( $input_avref, '$input_avref', 'integer_arrayref_to_string()' );
207              
208             # declare local variables, av & sv mean "array value" & "scalar value" as used in Perl core
209             # my @input_av; # DEV NOTE: match CPPOPS_*TYPES code
210 3         5 my integer $input_av_length;
211             my integer $input_av_element;
212 3         0 my string $output_sv;
213 3         7 my boolean $i_is_0 = 1;
214              
215             # compute length of (number of elements in) input array
216             # @input_av = @{$input_avref}; # DEV NOTE: match CPPOPS_*TYPES code
217             # $input_av_length = scalar @input_av; # DEV NOTE: match CPPOPS_*TYPES code
218 3         5 $input_av_length = scalar @{$input_avref};
  3         5  
219              
220             # RPerl::diag("in PERLOPS_PERLTYPES integer_arrayref_to_string(), have \$input_av_length = $input_av_length\n");
221              
222             # begin output string with left-square-bracket, as required for all RPerl arrays
223 3         6 $output_sv = '[';
224              
225             # loop through all valid values of $i for use as index to input array
226 3         6 for my integer $i ( 0 .. ( $input_av_length - 1 ) ) {
227              
228             # retrieve input array's element at index $i
229             # $input_av_element = $input_av[$i]; # DEV NOTE: match CPPOPS_*TYPES code
230 15         24 $input_av_element = $input_avref->[$i];
231              
232             # DEV NOTE: integer type-checking already done as part of integer_arrayref_CHECKTRACE()
233             # integer_CHECK($input_av_element);
234             #integer_CHECKTRACE( $input_av_element, "\$input_av_element at index $i", 'integer_arrayref_to_string()' );
235              
236             # append comma & space to output string for all elements except index 0
237 15 100       29 if ($i_is_0) { $i_is_0 = 0; }
  3         5  
238 12         18 else { $output_sv .= ', '; }
239              
240             # stringify individual integer element, append to output string
241 15         28 $output_sv .= ::integer_to_string($input_av_element);
242             }
243              
244             # end output string with right-square-bracket, as required for all RPerl arrays
245 3         7 $output_sv .= ']';
246              
247             # RPerl::diag("in PERLOPS_PERLTYPES integer_arrayref_to_string(), after for() loop, have \$output_sv =\n$output_sv\n");
248             # RPerl::diag("in PERLOPS_PERLTYPES integer_arrayref_to_string(), bottom of subroutine\n");
249              
250             # return output string, containing stringified input array
251 3         16 return $output_sv;
252             }
253              
254             # [[[ TYPE TESTING ]]]
255              
256             sub integer_arrayref__typetest0 {
257 5     5   8 { my string $RETURN_TYPE };
  5         6  
258 5         9 ( my integer_arrayref $lucky_integers) = @ARG;
259              
260             # integer_arrayref_CHECK($lucky_integers);
261 5         90 integer_arrayref_CHECKTRACE( $lucky_integers, '$lucky_integers',
262             'integer_arrayref__typetest0()' );
263              
264             # my integer $how_lucky = scalar @{$lucky_integers};
265             # for my integer $i ( 0 .. ( $how_lucky - 1 ) ) {
266             # my $lucky_integer = $lucky_integers->[$i];
267             # RPerl::diag("in PERLOPS_PERLTYPES integer_arrayref__typetest0(), have lucky integer $i/" . ( $how_lucky - 1 ) . ' = ' . $lucky_integers->[$i] . ", BARBAT\n");
268             # }
269             # RPerl::diag("in PERLOPS_PERLTYPES integer_arrayref__typetest0(), bottom of subroutine\n");
270             return (
271 1         21 integer_arrayref_to_string($lucky_integers) . 'PERLOPS_PERLTYPES' );
272             }
273              
274             sub integer_arrayref__typetest1 {
275 1     1   3 { my integer_arrayref $RETURN_TYPE };
  1         2  
276 1         2 ( my integer $my_size) = @ARG;
277              
278             # integer_CHECK($my_size);
279 1         4 integer_CHECKTRACE( $my_size, '$my_size',
280             'integer_arrayref__typetest1()' );
281 1         3 my integer_arrayref $new_array = [];
282 1         4 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
283 5         10 $new_array->[$i] = $i * 5;
284              
285             # RPerl::diag("in PERLOPS_PERLTYPES integer_arrayref__typetest1(), setting element $i/" . ( $my_size - 1 ) . ' = ' . $new_array->[$i] . ", BARBAT\n");
286             }
287 1         6 return ($new_array);
288             }
289              
290             # [[[ NUMBER ARRAY REF ]]]
291             # [[[ NUMBER ARRAY REF ]]]
292             # [[[ NUMBER ARRAY REF ]]]
293              
294             # (ref to array) of numbers
295             package # hide from PAUSE indexing
296             number_arrayref;
297 7     7   46 use strict;
  7         14  
  7         121  
298 7     7   28 use warnings;
  7         12  
  7         183  
299 7     7   27 use parent -norequire, qw(arrayref);
  7         17  
  7         30  
300 7     7   232 use Carp;
  7         14  
  7         340  
301              
302             # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
303             package RPerl::DataStructure::Array::SubTypes;
304 7     7   87 use strict;
  7         14  
  7         149  
305 7     7   32 use warnings;
  7         13  
  7         4019  
306              
307             # [[[ TYPE-CHECKING ]]]
308              
309             sub number_arrayref_CHECK {
310 0     0   0 { my void $RETURN_TYPE };
  0         0  
311 0         0 ( my $possible_number_arrayref ) = @ARG;
312 0 0       0 if ( not( defined $possible_number_arrayref ) ) {
313 0         0 croak(
314             "\nERROR ENVAVRV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber_arrayref value expected but undefined/null value found,\ncroaking"
315             );
316             }
317              
318 0 0       0 if ( not( main::RPerl_SvAROKp($possible_number_arrayref) ) ) {
319 0         0 croak(
320             "\nERROR ENVAVRV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber_arrayref value expected but non-arrayref value found,\ncroaking"
321             );
322             }
323              
324 0         0 my number $possible_number;
325 0         0 for my integer $i ( 0 .. ( ( scalar @{$possible_number_arrayref} ) - 1 ) )
  0         0  
326             {
327 0         0 $possible_number = $possible_number_arrayref->[$i];
328 0 0       0 if ( not( defined $possible_number ) ) {
329 0         0 croak(
330             "\nERROR ENVAVRV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber_arrayref element value expected but undefined/null value found at index $i,\ncroaking"
331             );
332             }
333 0 0 0     0 if (not( main::RPerl_SvNOKp($possible_number)
334             || main::RPerl_SvIOKp($possible_number) )
335             )
336             {
337 0         0 croak(
338             "\nERROR ENVAVRV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber_arrayref element value expected but non-number value found at index $i,\ncroaking"
339             );
340             }
341             }
342 0         0 return;
343             }
344              
345              
346             sub number_arrayref_CHECKTRACE {
347 21     21   33 { my void $RETURN_TYPE };
  21         26  
348 21         40 ( my $possible_number_arrayref, my $variable_name, my $subroutine_name )
349             = @ARG;
350 21 100       44 if ( not( defined $possible_number_arrayref ) ) {
351 3         39 croak(
352             "\nERROR ENVAVRV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber_arrayref value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
353             );
354             }
355 18 100       52 if ( not( main::RPerl_SvAROKp($possible_number_arrayref) ) ) {
356 5         54 croak(
357             "\nERROR ENVAVRV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber_arrayref value expected but non-arrayref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
358             );
359             }
360              
361 13         17 my number $possible_number;
362 13         18 for my integer $i ( 0 .. ( ( scalar @{$possible_number_arrayref} ) - 1 ) )
  13         36  
363             {
364 61         79 $possible_number = $possible_number_arrayref->[$i];
365 61 100       97 if ( not( defined $possible_number ) ) {
366 2         25 croak(
367             "\nERROR ENVAVRV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber_arrayref element value expected but undefined/null value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
368             );
369             }
370 59 100 100     163 if (not( main::RPerl_SvNOKp($possible_number)
371             || main::RPerl_SvIOKp($possible_number) )
372             )
373             {
374 4         46 croak(
375             "\nERROR ENVAVRV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber_arrayref element value expected but non-number value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
376             );
377             }
378             }
379 7         22 return;
380             }
381              
382             # [[[ STRINGIFY ]]]
383              
384             # convert from (Perl SV containing RV to (Perl AV of (Perl SVs containing NVs))) to Perl-parsable (Perl SV containing PV)
385             sub number_arrayref_to_string {
386 16     16   8184 { my string $RETURN_TYPE };
  16         28  
387 16         28 ( my $input_avref ) = @ARG;
388              
389             # RPerl::diag("in PERLOPS_PERLTYPES number_arrayref_to_string(), top of subroutine\n");
390              
391             # number_arrayref_CHECK($input_avref);
392 16         371 number_arrayref_CHECKTRACE( $input_avref, '$input_avref',
393             'number_arrayref_to_string()' );
394              
395 6         18 my @input_av;
396             my integer $input_av_length;
397 6         0 my number $input_av_element;
398 6         0 my string $output_sv;
399 6         8 my integer $i_is_0 = 1; # NEED UPGRADE: should be boolean type, not integer
400              
401 6         12 @input_av = @{$input_avref};
  6         15  
402 6         8 $input_av_length = scalar @input_av;
403              
404             # RPerl::diag("in PERLOPS_PERLTYPES number_arrayref_to_string(), have \$input_av_length = $input_av_length\n");
405              
406 6         11 $output_sv = '[';
407              
408 6         13 for my integer $i ( 0 .. ( $input_av_length - 1 ) ) {
409              
410 30         46 $input_av_element = $input_av[$i];
411              
412 30 100       50 if ($i_is_0) { $i_is_0 = 0; }
  6         9  
413 24         29 else { $output_sv .= ', '; }
414 30         573 $output_sv .= RPerl::DataType::Number::number_to_string($input_av_element);
415             }
416              
417 6         11 $output_sv .= ']';
418              
419             # RPerl::diag("in PERLOPS_PERLTYPES number_arrayref_to_string(), after for() loop, have \$output_sv =\n$output_sv\n");
420             # RPerl::diag("in PERLOPS_PERLTYPES number_arrayref_to_string(), bottom of subroutine\n");
421 6         24 return ($output_sv);
422             }
423              
424             # [[[ TYPE TESTING ]]]
425              
426             sub number_arrayref__typetest0 {
427 5     5   6 { my string $RETURN_TYPE };
  5         6  
428 5         9 ( my number_arrayref $lucky_numbers) = @ARG;
429              
430             # number_arrayref_CHECK($lucky_numbers);
431 5         90 number_arrayref_CHECKTRACE( $lucky_numbers, '$lucky_numbers',
432             'number_arrayref__typetest0()' );
433              
434             # my integer $how_lucky = scalar @{$lucky_numbers};
435             # for my integer $i ( 0 .. ( $how_lucky - 1 ) ) {
436             # my $lucky_number = $lucky_numbers->[$i];
437             # RPerl::diag("in PERLOPS_PERLTYPES number_arrayref__typetest0(), have lucky number $i/" . ( $how_lucky - 1 ) . ' = ' . $lucky_numbers->[$i] . ", BARBAZ\n");
438             # }
439             # RPerl::diag("in PERLOPS_PERLTYPES number_arrayref__typetest0(), bottom of subroutine\n");
440             return (
441 1         21 number_arrayref_to_string($lucky_numbers) . 'PERLOPS_PERLTYPES' );
442             }
443              
444             sub number_arrayref__typetest1 {
445 1     1   3 { my number_arrayref $RETURN_TYPE };
  1         3  
446 1         2 ( my integer $my_size) = @ARG;
447              
448             # integer_CHECK($my_size);
449 1         7 integer_CHECKTRACE( $my_size, '$my_size',
450             'number_arrayref__typetest1()' );
451 1         2 my number_arrayref $new_array = [];
452 1         5 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
453 5         11 $new_array->[$i] = $i * 5.123456789;
454              
455             # RPerl::diag("in PERLOPS_PERLTYPES number_arrayref__typetest1(), setting element $i/" . ( $my_size - 1 ) . ' = ' . $new_array->[$i] . ", BARBAZ\n");
456             }
457 1         6 return ($new_array);
458             }
459              
460             # [[[ CHARACTER ARRAY REF ]]]
461             # [[[ CHARACTER ARRAY REF ]]]
462             # [[[ CHARACTER ARRAY REF ]]]
463              
464             # (ref to array) of chars
465             package # hide from PAUSE indexing
466             character_arrayref;
467 7     7   49 use strict;
  7         15  
  7         149  
468 7     7   35 use warnings;
  7         14  
  7         216  
469 7     7   35 use parent -norequire, qw(arrayref);
  7         19  
  7         29  
470              
471             # [[[ STRING ARRAY REF ]]]
472             # [[[ STRING ARRAY REF ]]]
473             # [[[ STRING ARRAY REF ]]]
474              
475             # (ref to array) of strings
476             package # hide from PAUSE indexing
477             string_arrayref;
478 7     7   284 use strict;
  7         12  
  7         123  
479 7     7   29 use warnings;
  7         11  
  7         178  
480 7     7   29 use parent -norequire, qw(arrayref);
  7         14  
  7         29  
481 7     7   210 use Carp;
  7         12  
  7         343  
482              
483             # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
484             package RPerl::DataStructure::Array::SubTypes;
485 7     7   41 use strict;
  7         12  
  7         127  
486 7     7   33 use warnings;
  7         14  
  7         4134  
487              
488             # [[[ TYPE-CHECKING ]]]
489              
490             sub string_arrayref_CHECK {
491 0     0   0 { my void $RETURN_TYPE };
  0         0  
492 0         0 ( my $possible_string_arrayref ) = @ARG;
493 0 0       0 if ( not( defined $possible_string_arrayref ) ) {
494 0         0 croak(
495             "\nERROR EPVAVRV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring_arrayref value expected but undefined/null value found,\ncroaking"
496             );
497             }
498              
499 0 0       0 if ( not( main::RPerl_SvAROKp($possible_string_arrayref) ) ) {
500 0         0 croak(
501             "\nERROR EPVAVRV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring_arrayref value expected but non-arrayref value found,\ncroaking"
502             );
503             }
504              
505 0         0 my string $possible_string;
506 0         0 for my integer $i ( 0 .. ( ( scalar @{$possible_string_arrayref} ) - 1 ) )
  0         0  
507             {
508 0         0 $possible_string = $possible_string_arrayref->[$i];
509 0 0       0 if ( not( defined $possible_string ) ) {
510 0         0 croak(
511             "\nERROR EPVAVRV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring_arrayref element value expected but undefined/null value found at index $i,\ncroaking"
512             );
513             }
514 0 0       0 if ( not( main::RPerl_SvPOKp($possible_string) ) ) {
515 0         0 croak(
516             "\nERROR EPVAVRV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring_arrayref element value expected but non-string value found at index $i,\ncroaking"
517             );
518             }
519             }
520 0         0 return;
521             }
522              
523              
524             sub string_arrayref_CHECKTRACE {
525 23     23   32 { my void $RETURN_TYPE };
  23         37  
526 23         45 ( my $possible_string_arrayref, my $variable_name, my $subroutine_name )
527             = @ARG;
528 23 100       52 if ( not( defined $possible_string_arrayref ) ) {
529 3         45 croak(
530             "\nERROR EPVAVRV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring_arrayref value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
531             );
532             }
533 20 100       59 if ( not( main::RPerl_SvAROKp($possible_string_arrayref) ) ) {
534 5         53 croak(
535             "\nERROR EPVAVRV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring_arrayref value expected but non-arrayref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
536             );
537             }
538              
539 15         21 my string $possible_string;
540 15         24 for my integer $i ( 0 .. ( ( scalar @{$possible_string_arrayref} ) - 1 ) )
  15         41  
541             {
542 65         95 $possible_string = $possible_string_arrayref->[$i];
543 65 100       100 if ( not( defined $possible_string ) ) {
544 2         26 croak(
545             "\nERROR EPVAVRV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring_arrayref element value expected but undefined/null value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
546             );
547             }
548 63 100       117 if ( not( main::RPerl_SvPOKp($possible_string) ) ) {
549 5         56 croak(
550             "\nERROR EPVAVRV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring_arrayref element value expected but non-string value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking"
551             );
552             }
553             }
554 8         18 return;
555             }
556              
557             # [[[ STRINGIFY ]]]
558              
559             # convert from (Perl SV containing RV to (Perl AV of (Perl SVs containing PVs))) to Perl-parsable (Perl SV containing PV)
560             sub string_arrayref_to_string {
561 18     18   9407 { my string $RETURN_TYPE };
  18         30  
562 18         33 ( my $input_avref ) = @ARG;
563              
564             # RPerl::diag("in PERLOPS_PERLTYPES string_arrayref_to_string(), top of subroutine\n");
565              
566             # string_arrayref_CHECK($input_avref);
567 18         447 string_arrayref_CHECKTRACE( $input_avref, '$input_avref',
568             'string_arrayref_to_string()' );
569              
570 7         21 my @input_av;
571             my integer $input_av_length;
572 7         0 my string $input_av_element;
573 7         0 my string $output_sv;
574 7         10 my integer $i_is_0 = 1; # NEED UPGRADE: should be boolean type, not integer
575              
576 7         11 @input_av = @{$input_avref};
  7         14  
577 7         15 $input_av_length = scalar @input_av;
578              
579             # RPerl::diag("in PERLOPS_PERLTYPES string_arrayref_to_string(), have \$input_av_length = $input_av_length\n");
580              
581 7         9 $output_sv = '[';
582              
583 7         14 for my integer $i ( 0 .. ( $input_av_length - 1 ) ) {
584              
585 30         39 $input_av_element = $input_av[$i];
586              
587 30 100       43 if ($i_is_0) { $i_is_0 = 0; }
  7         10  
588 23         26 else { $output_sv .= ', '; }
589 30         41 $input_av_element =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
590 30         38 $input_av_element =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
591 30         55 $output_sv .= "'$input_av_element'";
592             }
593              
594 7         10 $output_sv .= ']';
595              
596             # RPerl::diag("in PERLOPS_PERLTYPES string_arrayref_to_string(), after for() loop, have \$output_sv =\n$output_sv\n");
597             # RPerl::diag("in PERLOPS_PERLTYPES string_arrayref_to_string(), bottom of subroutine\n");
598 7         34 return ($output_sv);
599             }
600              
601             # [[[ TYPE TESTING ]]]
602              
603             sub string_arrayref__typetest0 {
604 5     5   9 { my string $RETURN_TYPE };
  5         8  
605 5         8 ( my string_arrayref $people) = @ARG;
606              
607             # string_arrayref_CHECK($people);
608 5         93 string_arrayref_CHECKTRACE( $people, '$people',
609             'string_arrayref__typetest0()' );
610              
611             # my integer $how_crowded = scalar @{$people};
612             # for my integer $i ( 0 .. ( $how_crowded - 1 ) ) {
613             # my $person = $people->[$i];
614             # RPerl::diag("in PERLOPS_PERLTYPES string_arrayref__typetest0(), have person $i/" . ( $how_crowded - 1 ) . ' = ' . $people->[$i] . ", BARBAR\n");
615             # }
616             # RPerl::diag("in PERLOPS_PERLTYPES string_arrayref__typetest0(), bottom of subroutine\n");
617 1         21 return ( string_arrayref_to_string($people) . 'PERLOPS_PERLTYPES' );
618             }
619              
620             sub string_arrayref__typetest1 {
621 1     1   3 { my string_arrayref $RETURN_TYPE };
  1         2  
622 1         3 ( my integer $my_size) = @ARG;
623              
624             # integer_CHECK($my_size);
625 1         8 integer_CHECKTRACE( $my_size, '$my_size',
626             'string_arrayref__typetest1()' );
627 1         4 my string_arrayref $new_array = [];
628 1         4 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
629 5         15 $new_array->[$i]
630             = "Jeffy Ten! $i/" . ( $my_size - 1 ) . ' PERLOPS_PERLTYPES';
631              
632             # RPerl::diag("in PERLOPS_PERLTYPES string_arrayref__typetest1(), bottom of for() loop, have i = $i, just set another Jeffy, BARBAR\n");
633             }
634 1         10 return ($new_array);
635             }
636              
637             =block_comment
638             THIS IS AN EXAMPLE BLOCK COMMENT
639             it's purpose is to keep from triggering the UselessNoCritic rule,
640             so we can keep the no critic sections at the top of the file for reference
641             =cut
642              
643             # [[[ SCALAR ARRAYS ]]]
644              
645             # (ref to array) of scalartypes
646             package # hide from PAUSE indexing
647             scalartype_arrayref;
648 7     7   48 use strict;
  7         15  
  7         178  
649 7     7   42 use warnings;
  7         22  
  7         224  
650 7     7   43 use parent -norequire, qw(arrayref);
  7         14  
  7         31  
651              
652             # [[[ ARRAY ARRAYS (2-dimensional) ]]]
653              
654             # (ref to array) of (refs to arrays)
655             package # hide from PAUSE indexing
656             arrayref_arrayref;
657 7     7   297 use strict;
  7         15  
  7         111  
658 7     7   27 use warnings;
  7         11  
  7         185  
659 7     7   31 use parent -norequire, qw(arrayref);
  7         11  
  7         29  
660              
661             # [ HOMOGENEOUS ARRAY ARRAYS (2-dimensional) ]
662              
663             # method returning (ref to array) of (refs to (arrays of integers))
664             package # hide from PAUSE indexing
665             integer_arrayref_arrayref::method;
666 7     7   294 use strict;
  7         15  
  7         108  
667 7     7   25 use warnings;
  7         14  
  7         187  
668 7     7   30 use parent -norequire, qw(method);
  7         13  
  7         28  
669              
670             # (ref to array) of (refs to (arrays of integers))
671             package # hide from PAUSE indexing
672             integer_arrayref_arrayref;
673 7     7   254 use strict;
  7         12  
  7         661  
674 7     7   38 use warnings;
  7         332  
  7         232  
675 7     7   37 use parent -norequire, qw(arrayref_arrayref);
  7         14  
  7         30  
676              
677 7     7   255 use RPerl::Config; # for 'use English;' etc.
  7         13  
  7         1694  
678              
679             # emulate C++ behavior by actually creating arrays (and presumably allocating memory) at initialization time
680             sub new {
681 0     0     { my integer_arrayref_arrayref::method $RETURN_TYPE };
  0            
682 0           ( my integer $row_count, my integer $column_count ) = @ARG; # row-major form (RMF)
683 0           my integer_arrayref_arrayref $retval = [];
684 0           for my integer $j (0 .. ($row_count - 1)) {
685 0           my integer_arrayref $retval_row = [];
686 0           for my integer $i (0 .. ($column_count - 1)) {
687 0           $retval_row->[$i] = undef;
688             }
689 0           $retval->[$j] = $retval_row;
690             }
691 0           return $retval;
692             }
693              
694             # method returning (ref to array) of (refs to (arrays of numbers))
695             package # hide from PAUSE indexing
696             number_arrayref_arrayref::method;
697 7     7   44 use strict;
  7         16  
  7         142  
698 7     7   36 use warnings;
  7         28  
  7         225  
699 7     7   35 use parent -norequire, qw(method);
  7         11  
  7         34  
700              
701             # (ref to array) of (refs to (arrays of numbers))
702             package # hide from PAUSE indexing
703             number_arrayref_arrayref;
704 7     7   301 use strict;
  7         25  
  7         132  
705 7     7   36 use warnings;
  7         13  
  7         231  
706 7     7   36 use parent -norequire, qw(arrayref_arrayref);
  7         13  
  7         32  
707              
708 7     7   288 use RPerl::Config; # for 'use English;' etc.
  7         26  
  7         1678  
709              
710             # emulate C++ behavior by actually creating arrays (and presumably allocating memory) at initialization time
711             sub new {
712 0     0     { my number_arrayref_arrayref::method $RETURN_TYPE };
  0            
713 0           ( my integer $row_count, my integer $column_count ) = @ARG; # row-major form (RMF)
714 0           my number_arrayref_arrayref $retval = [];
715 0           for my integer $j (0 .. ($row_count - 1)) {
716 0           my number_arrayref $retval_row = [];
717 0           for my integer $i (0 .. ($column_count - 1)) {
718 0           $retval_row->[$i] = undef;
719             }
720 0           $retval->[$j] = $retval_row;
721             }
722 0           return $retval;
723             }
724              
725             # method returning (ref to array) of (refs to (arrays of strings))
726             package # hide from PAUSE indexing
727             string_arrayref_arrayref::method;
728 7     7   49 use strict;
  7         17  
  7         163  
729 7     7   34 use warnings;
  7         12  
  7         288  
730 7     7   34 use parent -norequire, qw(method);
  7         11  
  7         39  
731              
732             # (ref to array) of (refs to (arrays of strings))
733             package # hide from PAUSE indexing
734             string_arrayref_arrayref;
735 7     7   333 use strict;
  7         12  
  7         125  
736 7     7   28 use warnings;
  7         12  
  7         193  
737 7     7   33 use parent -norequire, qw(arrayref_arrayref);
  7         12  
  7         28  
738              
739 7     7   271 use RPerl::Config; # for 'use English;' etc.
  7         12  
  7         1460  
740              
741             # emulate C++ behavior by actually creating arrays (and presumably allocating memory) at initialization time
742             sub new {
743 0     0     { my string_arrayref_arrayref::method $RETURN_TYPE };
  0            
744 0           ( my integer $row_count, my integer $column_count ) = @ARG; # row-major form (RMF)
745 0           my string_arrayref_arrayref $retval = [];
746 0           for my integer $j (0 .. ($row_count - 1)) {
747 0           my string_arrayref $retval_row = [];
748 0           for my integer $i (0 .. ($column_count - 1)) {
749 0           $retval_row->[$i] = undef;
750             }
751 0           $retval->[$j] = $retval_row;
752             }
753 0           return $retval;
754             }
755              
756             # method returning (ref to array) of (refs to (arrays of scalartypes))
757             package # hide from PAUSE indexing
758             scalartype_arrayref_arrayref::method;
759 7     7   49 use strict;
  7         10  
  7         123  
760 7     7   27 use warnings;
  7         12  
  7         207  
761 7     7   32 use parent -norequire, qw(method);
  7         16  
  7         38  
762              
763             # (ref to array) of (refs to (arrays of scalars))
764             package # hide from PAUSE indexing
765             scalartype_arrayref_arrayref;
766 7     7   295 use strict;
  7         15  
  7         145  
767 7     7   28 use warnings;
  7         36  
  7         179  
768 7     7   33 use parent -norequire, qw(arrayref_arrayref);
  7         14  
  7         23  
769              
770 7     7   235 use RPerl::Config; # for 'use English;' etc.
  7         15  
  7         1370  
771              
772             # emulate C++ behavior by actually creating arrays (and presumably allocating memory) at initialization time
773             sub new {
774 0     0     { my scalartype_arrayref_arrayref::method $RETURN_TYPE };
  0            
775 0           ( my integer $row_count, my integer $column_count ) = @ARG; # row-major form (RMF)
776 0           my scalartype_arrayref_arrayref $retval = [];
777 0           for my integer $j (0 .. ($row_count - 1)) {
778 0           my scalartype_arrayref $retval_row = [];
779 0           for my integer $i (0 .. ($column_count - 1)) {
780 0           $retval_row->[$i] = undef;
781             }
782 0           $retval->[$j] = $retval_row;
783             }
784 0           return $retval;
785             }
786              
787             # [[[ ARRAY ARRAY ARRAYS (3-dimensional) ]]]
788              
789             # (ref to array) of (refs to arrays) of (refs to arrays)
790             package # hide from PAUSE indexing
791             arrayref_arrayref_arrayref;
792 7     7   42 use strict;
  7         11  
  7         120  
793 7     7   25 use warnings;
  7         16  
  7         189  
794 7     7   30 use parent -norequire, qw(arrayref);
  7         11  
  7         29  
795              
796             # [ HOMOGENEOUS ARRAY ARRAY ARRAYS (3-dimensional) ]
797              
798             # (ref to array) of (refs to arrays) of (refs to (arrays of integers))
799             package # hide from PAUSE indexing
800             integer_arrayref_arrayref_arrayref;
801 7     7   282 use strict;
  7         20  
  7         127  
802 7     7   29 use warnings;
  7         12  
  7         232  
803 7     7   32 use parent -norequire, qw(arrayref_arrayref_arrayref);
  7         9  
  7         27  
804              
805             # (ref to array) of (refs to arrays) of (refs to (arrays of numbers))
806             package # hide from PAUSE indexing
807             number_arrayref_arrayref_arrayref;
808 7     7   310 use strict;
  7         16  
  7         123  
809 7     7   29 use warnings;
  7         11  
  7         172  
810 7     7   26 use parent -norequire, qw(arrayref_arrayref_arrayref);
  7         10  
  7         25  
811              
812             # (ref to array) of (refs to arrays) of (refs to (arrays of strings))
813             package # hide from PAUSE indexing
814             string_arrayref_arrayref_arrayref;
815 7     7   277 use strict;
  7         12  
  7         96  
816 7     7   23 use warnings;
  7         12  
  7         156  
817 7     7   27 use parent -norequire, qw(arrayref_arrayref_arrayref);
  7         13  
  7         22  
818              
819             # (ref to array) of (refs to arrays) of (refs to (arrays of scalars))
820             package # hide from PAUSE indexing
821             scalartype_arrayref_arrayref_arrayref;
822 7     7   253 use strict;
  7         15  
  7         102  
823 7     7   31 use warnings;
  7         11  
  7         207  
824 7     7   32 use parent -norequire, qw(arrayref_arrayref_arrayref);
  7         15  
  7         24  
825              
826             # [[[ HASH ARRAYS (2-dimensional) ]]]
827              
828             # (ref to array) of (refs to hashs)
829             package # hide from PAUSE indexing
830             hashref_arrayref;
831 7     7   346 use strict;
  7         9  
  7         116  
832 7     7   29 use warnings;
  7         10  
  7         191  
833 7     7   39 use parent -norequire, qw(arrayref);
  7         15  
  7         24  
834              
835             # [[[ OBJECT ARRAYS (2-dimensional) ]]]
836              
837             # (ref to array) of objects
838             package # hide from PAUSE indexing
839             object_arrayref;
840 7     7   348 use strict;
  7         12  
  7         110  
841 7     7   25 use warnings;
  7         10  
  7         166  
842 7     7   32 use parent -norequire, qw(arrayref);
  7         10  
  7         23  
843              
844             1; # end of package