File Coverage

blib/lib/RPerl/DataStructure/Array/SubTypes.pm
Criterion Covered Total %
statement 258 346 74.5
branch 0 56 0.0
condition 0 6 0.0
subroutine 86 94 91.4
pod 0 8 0.0
total 344 510 67.4


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