blib/lib/Perl/Structure/Array/SubTypes1D.pm untested

filter: Statementstmt 0.0% 0 / 389 Branchbran 0.0% 0 / 78 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 56 Podpod 0.0% 0 / 27 totaltotal 0.0% 0 / 560 CC 40 SCAR 29.1
CC
40
Cov
0%
arrayref_integer_to_string_format
42.0
arrayref_number_to_string_format
42.0
arrayref_string_to_string_format
42.0
CRAP 18.4
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 Perl::Structure::Array::SubTypes1D;
3 use strict;
4 use warnings;
5 use Perl::Config; # don't use Perl::Types inside itself, in order to avoid circular includes
6 our $VERSION = 0.021_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 # [[[ INCLUDES ]]]
15 use Perl::Type::Integer; # for integer_CHECKTRACE(), used in arrayref_TYPE_typetest1()
16  
17 # [[[ EXPORTS ]]]
18 # DEV NOTE, CORRELATION #rp051: hard-coded list of RPerl data types and data structures
19 use Exporter 'import';
20 our @EXPORT = qw(
21 arrayref_integer_CHECK
22 arrayref_integer_CHECKTRACE
23 arrayref_number_CHECK
24 arrayref_number_CHECKTRACE
25 arrayref_string_CHECK
26 arrayref_string_CHECKTRACE
27 arrayref_integer_to_string_compact
28 arrayref_integer_to_string
29 arrayref_integer_to_string_pretty
30 arrayref_integer_to_string_expand
31 arrayref_integer_to_string_format
32 arrayref_number_to_string_compact
33 arrayref_number_to_string
34 arrayref_number_to_string_pretty
35 arrayref_number_to_string_expand
36 arrayref_number_to_string_format
37 arrayref_string_to_string_compact
38 arrayref_string_to_string
39 arrayref_string_to_string_pretty
40 arrayref_string_to_string_expand
41 arrayref_string_to_string_format
42 );
43 our @EXPORT_OK = qw(
44 arrayref_integer_typetest0
45 arrayref_integer_typetest1
46 arrayref_number_typetest0
47 arrayref_number_typetest1
48 arrayref_string_typetest0
49 arrayref_string_typetest1
50 );
51  
52 # [[[ ARRAY REF INTEGER ]]]
53 # [[[ ARRAY REF INTEGER ]]]
54 # [[[ ARRAY REF INTEGER ]]]
55  
56 # (ref to array) of integers
57 package arrayref::integer;
58 use strict;
59 use warnings;
60 use parent -norequire, qw(arrayref);
61 use Carp;
62  
63 # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
64 package Perl::Structure::Array::SubTypes1D;
65 use strict;
66 use warnings;
67  
68 # [[[ TYPE-CHECKING ]]]
69  
70 sub arrayref_integer_CHECK {
71 { my void $RETURN_TYPE };
72 ( my $possible_arrayref_integer ) = @ARG;
73  
74 # DEV NOTE: the following two if() statements are functionally equivalent to the arrayref_CHECK() subroutine, but with integer-specific error codes
75 if ( not( defined $possible_arrayref_integer ) ) {
76 croak( "\nERROR EAVRVIV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_integer value expected but undefined/null value found,\ncroaking" );
77 }
78  
79 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_integer) ) ) {
80 croak( "\nERROR EAVRVIV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_integer value expected but non-arrayref value found,\ncroaking" );
81 }
82  
83 my integer $possible_integer;
84 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_integer} ) - 1 ) )
85 {
86 $possible_integer = $possible_arrayref_integer->[$i];
87  
88 # DEV NOTE: the following two if() statements are functionally equivalent to the integer_CHECK() subroutine, but with array-specific error codes
89 if ( not( defined $possible_integer ) ) {
90 croak( "\nERROR EAVRVIV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger value expected but undefined/null value found at index $i,\ncroaking" );
91 }
92 if ( not( main::PerlTypes_SvIOKp($possible_integer) ) ) {
93 croak( "\nERROR EAVRVIV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger value expected but non-integer value found at index $i,\ncroaking" );
94 }
95 }
96 return;
97 };
98  
99 sub arrayref_integer_CHECKTRACE {
100 { my void $RETURN_TYPE };
101 ( my $possible_arrayref_integer, my $variable_name, my $subroutine_name ) = @ARG;
102 if ( not( defined $possible_arrayref_integer ) ) {
103 croak( "\nERROR EAVRVIV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_integer value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
104 }
105 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_integer) ) ) {
106 croak( "\nERROR EAVRVIV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_integer value expected but non-arrayref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
107 }
108  
109 my integer $possible_integer;
110 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_integer} ) - 1 ) )
111 {
112 $possible_integer = $possible_arrayref_integer->[$i];
113 if ( not( defined $possible_integer ) ) {
114 croak( "\nERROR EAVRVIV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger value expected but undefined/null value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
115 }
116 if ( not( main::PerlTypes_SvIOKp($possible_integer) ) ) {
117 croak( "\nERROR EAVRVIV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger value expected but non-integer value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
118 }
119 }
120 return;
121 }
122  
123 # [[[ STRINGIFY ]]]
124  
125 # DEV NOTE: 1-D format levels are 1 less than 2-D format levels
126  
127 # call actual stringify routine, format level -2 (compact), indent level 0
128 sub arrayref_integer_to_string_compact {
129 { my string $RETURN_TYPE };
130 ( my $input_avref ) = @ARG;
131 return arrayref_integer_to_string_format($input_avref, -2, 0);
132 }
133  
134 # call actual stringify routine, format level -1 (normal), indent level 0, DEFAULT
135 sub arrayref_integer_to_string {
136 { my string $RETURN_TYPE };
137 ( my $input_avref ) = @ARG;
138 return arrayref_integer_to_string_format($input_avref, -1, 0);
139 }
140  
141 # call actual stringify routine, format level 0 (pretty), indent level 0
142 sub arrayref_integer_to_string_pretty {
143 { my string $RETURN_TYPE };
144 ( my $input_avref ) = @ARG;
145 return arrayref_integer_to_string_format($input_avref, 0, 0);
146 }
147  
148 # call actual stringify routine, format level 1 (expand), indent level 0
149 sub arrayref_integer_to_string_expand {
150 { my string $RETURN_TYPE };
151 ( my $input_avref ) = @ARG;
152 return arrayref_integer_to_string_format($input_avref, 1, 0);
153 }
154  
155 # convert from (Perl SV containing RV to (Perl AV of (Perl SVs containing IVs))) to Perl-parsable (Perl SV containing PV)
156 # stringify an arrayref::integer
157 sub arrayref_integer_to_string_format {
158 { my string $RETURN_TYPE };
159 ( my arrayref::integer $input_avref, my integer $format_level, my integer $indent_level ) = @ARG;
160  
161 # Perl::diag("in PERLOPS_PERLTYPES arrayref_integer_to_string_format(), top of subroutine\n");
162 # Perl::diag('in PERLOPS_PERLTYPES arrayref_integer_to_string_format(), received $format_level = ', $format_level, "\n");
163 # Perl::diag('in PERLOPS_PERLTYPES arrayref_integer_to_string_format(), received $indent_level = ', $indent_level, "\n");
164  
165 # arrayref_integer_CHECK($input_avref);
166 arrayref_integer_CHECKTRACE( $input_avref, '$input_avref', 'arrayref_integer_to_string_format()' );
167  
168 # declare local variables, av & sv mean "array value" & "scalar value" as used in Perl core
169 # my @input_av; # DEV NOTE: match CPPOPS_*TYPES code
170 my integer $input_av__length;
171 my integer $input_av__element;
172 my string $output_sv = q{};
173 my boolean $i_is_0 = 1;
174  
175 # generate indent
176 my string $indent = q{ } x $indent_level;
177  
178 # compute length of (number of elements in) input array
179 # @input_av = @{$input_avref}; # DEV NOTE: match CPPOPS_*TYPES code
180 # $input_av__length = scalar @input_av; # DEV NOTE: match CPPOPS_*TYPES code
181 $input_av__length = scalar @{$input_avref};
182  
183 # Perl::diag("in PERLOPS_PERLTYPES arrayref_integer_to_string_format(), have \$input_av__length = $input_av__length\n");
184  
185 # pre-begin with optional indent, depending on format level
186 if ($format_level >= 1) { $output_sv .= $indent; }
187  
188 # begin output string with left-square-bracket, as required for all RPerl arrays
189 $output_sv .= '[';
190  
191 # loop through all valid values of $i for use as index to input array
192 for my integer $i ( 0 .. ( $input_av__length - 1 ) ) {
193  
194 # retrieve input array's element at index $i
195 # $input_av__element = $input_av[$i]; # DEV NOTE: match CPPOPS_*TYPES code
196 $input_av__element = $input_avref->[$i];
197  
198 # DEV NOTE: type-checking already done as part of arrayref_integer_CHECKTRACE()
199 # integer_CHECK($input_av__element);
200 #integer_CHECKTRACE( $input_av__element, "\$input_av__element at index $i", 'arrayref_integer_to_string_format()' );
201  
202 # append comma to output string for all elements except index 0
203 if ($i_is_0) { $i_is_0 = 0; }
204 else { $output_sv .= ','; }
205  
206 # append newline-indent-tab or space, depending on format level
207 if ($format_level >= 1) { $output_sv .= "\n" . $indent . q{ }; }
208 elsif ($format_level >= -1) { $output_sv .= q{ }; }
209  
210 # stringify individual element, append to output string
211 # $output_sv .= $input_av__element; # NO UNDERSCORES
212 $output_sv .= ::integer_to_string($input_av__element); # YES UNDERSCORES
213 }
214  
215 # append newline-indent or space, depending on format level
216 if ($format_level >= 1) { $output_sv .= "\n" . $indent; }
217 elsif ($format_level >= -1) { $output_sv .= q{ }; }
218  
219 # end output string with right-square-bracket, as required for all RPerl arrays
220 $output_sv .= ']';
221  
222 # Perl::diag("in PERLOPS_PERLTYPES arrayref_integer_to_string_format(), after for() loop, have \$output_sv =\n$output_sv\n");
223 # Perl::diag("in PERLOPS_PERLTYPES arrayref_integer_to_string_format(), bottom of subroutine\n");
224  
225 # return output string, containing stringified input array
226 return $output_sv;
227 }
228  
229 # [[[ TYPE TESTING ]]]
230  
231 sub arrayref_integer_typetest0 {
232 { my string $RETURN_TYPE };
233 ( my arrayref::integer $lucky_integers) = @ARG;
234  
235 # arrayref_integer_CHECK($lucky_integers);
236 arrayref_integer_CHECKTRACE( $lucky_integers, '$lucky_integers', 'arrayref_integer_typetest0()' );
237  
238 # my integer $how_lucky = scalar @{$lucky_integers};
239 # for my integer $i ( 0 .. ( $how_lucky - 1 ) ) {
240 # my $lucky_integer = $lucky_integers->[$i];
241 # Perl::diag("in PERLOPS_PERLTYPES arrayref_integer_typetest0(), have lucky integer $i/" . ( $how_lucky - 1 ) . ' = ' . $lucky_integers->[$i] . ", BARBAT\n");
242 # }
243 # Perl::diag("in PERLOPS_PERLTYPES arrayref_integer_typetest0(), bottom of subroutine\n");
244 return ( arrayref_integer_to_string($lucky_integers) . 'PERLOPS_PERLTYPES' );
245 }
246  
247 sub arrayref_integer_typetest1 {
248 { my arrayref::integer $RETURN_TYPE };
249 ( my integer $my_size) = @ARG;
250  
251 # integer_CHECK($my_size);
252 integer_CHECKTRACE( $my_size, '$my_size', 'arrayref_integer_typetest1()' );
253 my arrayref::integer $new_array = [];
254 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
255 $new_array->[$i] = $i * 5;
256  
257 # Perl::diag("in PERLOPS_PERLTYPES arrayref_integer_typetest1(), setting element $i/" . ( $my_size - 1 ) . ' = ' . $new_array->[$i] . ", BARBAT\n");
258 }
259 return ($new_array);
260 }
261  
262 # [[[ ARRAY REF NUMBER ]]]
263 # [[[ ARRAY REF NUMBER ]]]
264 # [[[ ARRAY REF NUMBER ]]]
265  
266 # (ref to array) of numbers
267 package arrayref::number;
268 use strict;
269 use warnings;
270 use parent -norequire, qw(arrayref);
271 use Carp;
272  
273 # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
274 package Perl::Structure::Array::SubTypes1D;
275 use strict;
276 use warnings;
277  
278 # [[[ TYPE-CHECKING ]]]
279  
280 sub arrayref_number_CHECK {
281 { my void $RETURN_TYPE };
282 ( my $possible_arrayref_number ) = @ARG;
283 if ( not( defined $possible_arrayref_number ) ) {
284 croak( "\nERROR EAVRVNV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_number value expected but undefined/null value found,\ncroaking" );
285 }
286  
287 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_number) ) ) {
288 croak( "\nERROR EAVRVNV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_number value expected but non-arrayref value found,\ncroaking" );
289 }
290  
291 my number $possible_number;
292 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_number} ) - 1 ) )
293 {
294 $possible_number = $possible_arrayref_number->[$i];
295 if ( not( defined $possible_number ) ) {
296 croak( "\nERROR EAVRVNV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber value expected but undefined/null value found at index $i,\ncroaking" );
297 }
298 if (not( main::PerlTypes_SvNOKp($possible_number)
299 || main::PerlTypes_SvIOKp($possible_number) )
300 )
301 {
302 croak( "\nERROR EAVRVNV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber value expected but non-number value found at index $i,\ncroaking" );
303 }
304 }
305 return;
306 }
307  
308 sub arrayref_number_CHECKTRACE {
309 { my void $RETURN_TYPE };
310 ( my $possible_arrayref_number, my $variable_name, my $subroutine_name ) = @ARG;
311 if ( not( defined $possible_arrayref_number ) ) {
312 croak( "\nERROR EAVRVNV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_number value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
313 }
314 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_number) ) ) {
315 croak( "\nERROR EAVRVNV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_number value expected but non-arrayref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
316 }
317  
318 my number $possible_number;
319 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_number} ) - 1 ) )
320 {
321 $possible_number = $possible_arrayref_number->[$i];
322 if ( not( defined $possible_number ) ) {
323 croak( "\nERROR EAVRVNV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber value expected but undefined/null value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
324 }
325 if (not( main::PerlTypes_SvNOKp($possible_number)
326 || main::PerlTypes_SvIOKp($possible_number) ) ) {
327 croak( "\nERROR EAVRVNV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber value expected but non-number value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
328 }
329 }
330 return;
331 }
332  
333 # [[[ STRINGIFY ]]]
334  
335 # DEV NOTE: 1-D format levels are 1 less than 2-D format levels
336  
337 # call actual stringify routine, format level -2 (compact), indent level 0
338 sub arrayref_number_to_string_compact {
339 { my string $RETURN_TYPE };
340 ( my $input_avref ) = @ARG;
341 return arrayref_number_to_string_format($input_avref, -2, 0);
342 }
343  
344 # call actual stringify routine, format level -1 (normal), indent level 0, DEFAULT
345 sub arrayref_number_to_string {
346 { my string $RETURN_TYPE };
347 ( my $input_avref ) = @ARG;
348 return arrayref_number_to_string_format($input_avref, -1, 0);
349 }
350  
351 # call actual stringify routine, format level 0 (pretty), indent level 0
352 sub arrayref_number_to_string_pretty {
353 { my string $RETURN_TYPE };
354 ( my $input_avref ) = @ARG;
355 return arrayref_number_to_string_format($input_avref, 0, 0);
356 }
357  
358 # call actual stringify routine, format level 1 (expand), indent level 0
359 sub arrayref_number_to_string_expand {
360 { my string $RETURN_TYPE };
361 ( my $input_avref ) = @ARG;
362 return arrayref_number_to_string_format($input_avref, 1, 0);
363 }
364  
365 # convert from (Perl SV containing RV to (Perl AV of (Perl SVs containing NVs))) to Perl-parsable (Perl SV containing PV)
366 # stringify an arrayref::number
367 sub arrayref_number_to_string_format {
368 { my string $RETURN_TYPE };
369 ( my arrayref::number $input_avref, my integer $format_level, my integer $indent_level ) = @ARG;
370  
371 # Perl::diag("in PERLOPS_PERLTYPES arrayref_number_to_string_format(), top of subroutine\n");
372 # Perl::diag('in PERLOPS_PERLTYPES arrayref_number_to_string_format(), received $format_level = ', $format_level, "\n");
373 # Perl::diag('in PERLOPS_PERLTYPES arrayref_number_to_string_format(), received $indent_level = ', $indent_level, "\n");
374  
375 # arrayref_number_CHECK($input_avref);
376 arrayref_number_CHECKTRACE( $input_avref, '$input_avref', 'arrayref_number_to_string_format()' );
377  
378 # declare local variables, av & sv mean "array value" & "scalar value" as used in Perl core
379 # my @input_av; # DEV NOTE: match CPPOPS_*TYPES code
380 my integer $input_av__length;
381 my integer $input_av__element;
382 my string $output_sv = q{};
383 my boolean $i_is_0 = 1;
384  
385 # generate indent
386 my string $indent = q{ } x $indent_level;
387  
388 # compute length of (number of elements in) input array
389 # @input_av = @{$input_avref}; # DEV NOTE: match CPPOPS_*TYPES code
390 # $input_av__length = scalar @input_av; # DEV NOTE: match CPPOPS_*TYPES code
391 $input_av__length = scalar @{$input_avref};
392  
393 # Perl::diag("in PERLOPS_PERLTYPES arrayref_number_to_string_format(), have \$input_av__length = $input_av__length\n");
394  
395 # pre-begin with optional indent, depending on format level
396 if ($format_level >= 1) { $output_sv .= $indent; }
397  
398 # begin output string with left-square-bracket, as required for all RPerl arrays
399 $output_sv .= '[';
400  
401 # loop through all valid values of $i for use as index to input array
402 for my integer $i ( 0 .. ( $input_av__length - 1 ) ) {
403  
404 # retrieve input array's element at index $i
405 # $input_av__element = $input_av[$i]; # DEV NOTE: match CPPOPS_*TYPES code
406 $input_av__element = $input_avref->[$i];
407  
408 # DEV NOTE: type-checking already done as part of arrayref_number_CHECKTRACE()
409 # number_CHECK($input_av__element);
410 #number_CHECKTRACE( $input_av__element, "\$input_av__element at index $i", 'arrayref_number_to_string_format()' );
411  
412 # append comma to output string for all elements except index 0
413 if ($i_is_0) { $i_is_0 = 0; }
414 else { $output_sv .= ','; }
415  
416 # append newline-indent-tab or space, depending on format level
417 if ($format_level >= 1) { $output_sv .= "\n" . $indent . q{ }; }
418 elsif ($format_level >= -1) { $output_sv .= q{ }; }
419  
420 # stringify individual element, append to output string
421 # $output_sv .= $input_av__element; # NO UNDERSCORES
422 $output_sv .= Perl::Type::Number::number_to_string($input_av__element); # YES UNDERSCORES
423 }
424  
425 # append newline-indent or space, depending on format level
426 if ($format_level >= 1) { $output_sv .= "\n" . $indent; }
427 elsif ($format_level >= -1) { $output_sv .= q{ }; }
428  
429 # end output string with right-square-bracket, as required for all RPerl arrays
430 $output_sv .= ']';
431  
432 # Perl::diag("in PERLOPS_PERLTYPES arrayref_number_to_string_format(), after for() loop, have \$output_sv =\n$output_sv\n");
433 # Perl::diag("in PERLOPS_PERLTYPES arrayref_number_to_string_format(), bottom of subroutine\n");
434  
435 # return output string, containing stringified input array
436 return $output_sv;
437 }
438  
439 # [[[ TYPE TESTING ]]]
440  
441 sub arrayref_number_typetest0 {
442 { my string $RETURN_TYPE };
443 ( my arrayref::number $lucky_numbers) = @ARG;
444  
445 # arrayref_number_CHECK($lucky_numbers);
446 arrayref_number_CHECKTRACE( $lucky_numbers, '$lucky_numbers', 'arrayref_number_typetest0()' );
447  
448 # my integer $how_lucky = scalar @{$lucky_numbers};
449 # for my integer $i ( 0 .. ( $how_lucky - 1 ) ) {
450 # my $lucky_number = $lucky_numbers->[$i];
451 # Perl::diag("in PERLOPS_PERLTYPES arrayref_number_typetest0(), have lucky number $i/" . ( $how_lucky - 1 ) . ' = ' . $lucky_numbers->[$i] . ", BARBAZ\n");
452 # }
453 # Perl::diag("in PERLOPS_PERLTYPES arrayref_number_typetest0(), bottom of subroutine\n");
454 return ( arrayref_number_to_string($lucky_numbers) . 'PERLOPS_PERLTYPES' );
455 }
456  
457 sub arrayref_number_typetest1 {
458 { my arrayref::number $RETURN_TYPE };
459 ( my integer $my_size) = @ARG;
460  
461 # integer_CHECK($my_size);
462 integer_CHECKTRACE( $my_size, '$my_size', 'arrayref_number_typetest1()' );
463 my arrayref::number $new_array = [];
464 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
465 $new_array->[$i] = $i * 5.123456789;
466  
467 # Perl::diag("in PERLOPS_PERLTYPES arrayref_number_typetest1(), setting element $i/" . ( $my_size - 1 ) . ' = ' . $new_array->[$i] . ", BARBAZ\n");
468 }
469 return ($new_array);
470 }
471  
472 # [[[ ARRAY REF CHARACTER ]]]
473 # [[[ ARRAY REF CHARACTER ]]]
474 # [[[ ARRAY REF CHARACTER ]]]
475  
476 # (ref to array) of chars
477 package arrayref::character;
478 use strict;
479 use warnings;
480 use parent -norequire, qw(arrayref);
481  
482 # [[[ ARRAY REF STRING ]]]
483 # [[[ ARRAY REF STRING ]]]
484 # [[[ ARRAY REF STRING ]]]
485  
486 # (ref to array) of strings
487 package arrayref::string;
488 use strict;
489 use warnings;
490 use parent -norequire, qw(arrayref);
491 use Carp;
492  
493 # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
494 package Perl::Structure::Array::SubTypes1D;
495 use strict;
496 use warnings;
497  
498 # [[[ TYPE-CHECKING ]]]
499  
500 sub arrayref_string_CHECK {
501 { my void $RETURN_TYPE };
502 ( my $possible_arrayref_string ) = @ARG;
503 if ( not( defined $possible_arrayref_string ) ) {
504 croak( "\nERROR EAVRVPV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_string value expected but undefined/null value found,\ncroaking" );
505 }
506  
507 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_string) ) ) {
508 croak( "\nERROR EAVRVPV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_string value expected but non-arrayref value found,\ncroaking" );
509 }
510  
511 my string $possible_string;
512 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_string} ) - 1 ) )
513 {
514 $possible_string = $possible_arrayref_string->[$i];
515 if ( not( defined $possible_string ) ) {
516 croak( "\nERROR EAVRVPV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but undefined/null value found at index $i,\ncroaking" );
517 }
518 if ( not( main::PerlTypes_SvPOKp($possible_string) ) ) {
519 croak( "\nERROR EAVRVPV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but non-string value found at index $i,\ncroaking" );
520 }
521 }
522 return;
523 }
524  
525 sub arrayref_string_CHECKTRACE {
526 { my void $RETURN_TYPE };
527 ( my $possible_arrayref_string, my $variable_name, my $subroutine_name ) = @ARG;
528 if ( not( defined $possible_arrayref_string ) ) {
529 croak( "\nERROR EAVRVPV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_string value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
530 }
531 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_string) ) ) {
532 croak( "\nERROR EAVRVPV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref_string value expected but non-arrayref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
533 }
534  
535 my string $possible_string;
536 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_string} ) - 1 ) )
537 {
538 $possible_string = $possible_arrayref_string->[$i];
539 if ( not( defined $possible_string ) ) {
540 croak( "\nERROR EAVRVPV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but undefined/null value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
541 }
542 if ( not( main::PerlTypes_SvPOKp($possible_string) ) ) {
543 croak( "\nERROR EAVRVPV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but non-string value found at index $i,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
544 }
545 }
546 return;
547 }
548  
549 # [[[ STRINGIFY ]]]
550  
551 # DEV NOTE: 1-D format levels are 1 less than 2-D format levels
552  
553 # call actual stringify routine, format level -2 (compact), indent level 0
554 sub arrayref_string_to_string_compact {
555 { my string $RETURN_TYPE };
556 ( my $input_avref ) = @ARG;
557 return arrayref_string_to_string_format($input_avref, -2, 0);
558 }
559  
560 # call actual stringify routine, format level -1 (normal), indent level 0, DEFAULT
561 sub arrayref_string_to_string {
562 { my string $RETURN_TYPE };
563 ( my $input_avref ) = @ARG;
564 return arrayref_string_to_string_format($input_avref, -1, 0);
565 }
566  
567 # call actual stringify routine, format level 0 (pretty), indent level 0
568 sub arrayref_string_to_string_pretty {
569 { my string $RETURN_TYPE };
570 ( my $input_avref ) = @ARG;
571 return arrayref_string_to_string_format($input_avref, 0, 0);
572 }
573  
574 # call actual stringify routine, format level 1 (expand), indent level 0
575 sub arrayref_string_to_string_expand {
576 { my string $RETURN_TYPE };
577 ( my $input_avref ) = @ARG;
578 return arrayref_string_to_string_format($input_avref, 1, 0);
579 }
580  
581 # convert from (Perl SV containing RV to (Perl AV of (Perl SVs containing PVs))) to Perl-parsable (Perl SV containing PV)
582 # stringify an arrayref::string
583 sub arrayref_string_to_string_format {
584 { my string $RETURN_TYPE };
585 ( my arrayref::string $input_avref, my integer $format_level, my integer $indent_level ) = @ARG;
586  
587 # Perl::diag("in PERLOPS_PERLTYPES arrayref_string_to_string_format(), top of subroutine\n");
588 # Perl::diag('in PERLOPS_PERLTYPES arrayref_string_to_string_format(), received $format_level = ', $format_level, "\n");
589 # Perl::diag('in PERLOPS_PERLTYPES arrayref_string_to_string_format(), received $indent_level = ', $indent_level, "\n");
590  
591 # arrayref_string_CHECK($input_avref);
592 arrayref_string_CHECKTRACE( $input_avref, '$input_avref', 'arrayref_string_to_string_format()' );
593  
594 # declare local variables, av & sv mean "array value" & "scalar value" as used in Perl core
595 # my @input_av; # DEV NOTE: match CPPOPS_*TYPES code
596 my integer $input_av__length;
597 my integer $input_av__element;
598 my string $output_sv = q{};
599 my boolean $i_is_0 = 1;
600  
601 # generate indent
602 my string $indent = q{ } x $indent_level;
603  
604 # compute length of (number of elements in) input array
605 # @input_av = @{$input_avref}; # DEV NOTE: match CPPOPS_*TYPES code
606 # $input_av__length = scalar @input_av; # DEV NOTE: match CPPOPS_*TYPES code
607 $input_av__length = scalar @{$input_avref};
608  
609 # Perl::diag("in PERLOPS_PERLTYPES arrayref_string_to_string_format(), have \$input_av__length = $input_av__length\n");
610  
611 # pre-begin with optional indent, depending on format level
612 if ($format_level >= 1) { $output_sv .= $indent; }
613  
614 # begin output string with left-square-bracket, as required for all RPerl arrays
615 $output_sv .= '[';
616  
617 # loop through all valid values of $i for use as index to input array
618 for my integer $i ( 0 .. ( $input_av__length - 1 ) ) {
619  
620 # retrieve input array's element at index $i
621 # $input_av__element = $input_av[$i]; # DEV NOTE: match CPPOPS_*TYPES code
622 $input_av__element = $input_avref->[$i];
623  
624 # DEV NOTE: type-checking already done as part of arrayref_string_CHECKTRACE()
625 # string_CHECK($input_av__element);
626 #string_CHECKTRACE( $input_av__element, "\$input_av__element at index $i", 'arrayref_string_to_string_format()' );
627  
628 # append comma to output string for all elements except index 0
629 if ($i_is_0) { $i_is_0 = 0; }
630 else { $output_sv .= ','; }
631  
632 # append newline-indent-tab or space, depending on format level
633 if ($format_level >= 1) { $output_sv .= "\n" . $indent . q{ }; }
634 elsif ($format_level >= -1) { $output_sv .= q{ }; }
635  
636 # stringify individual element, append to output string
637 $input_av__element =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
638 $input_av__element =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
639 $output_sv .= "'$input_av__element'";
640 }
641  
642 # append newline-indent or space, depending on format level
643 if ($format_level >= 1) { $output_sv .= "\n" . $indent; }
644 elsif ($format_level >= -1) { $output_sv .= q{ }; }
645  
646 # end output string with right-square-bracket, as required for all RPerl arrays
647 $output_sv .= ']';
648  
649 # Perl::diag("in PERLOPS_PERLTYPES arrayref_string_to_string_format(), after for() loop, have \$output_sv =\n$output_sv\n");
650 # Perl::diag("in PERLOPS_PERLTYPES arrayref_string_to_string_format(), bottom of subroutine\n");
651  
652 # return output string, containing stringified input array
653 return $output_sv;
654 }
655  
656 # [[[ TYPE TESTING ]]]
657  
658 sub arrayref_string_typetest0 {
659 { my string $RETURN_TYPE };
660 ( my arrayref::string $people) = @ARG;
661  
662 # arrayref_string_CHECK($people);
663 arrayref_string_CHECKTRACE( $people, '$people', 'arrayref_string_typetest0()' );
664  
665 # my integer $how_crowded = scalar @{$people};
666 # for my integer $i ( 0 .. ( $how_crowded - 1 ) ) {
667 # my $person = $people->[$i];
668 # Perl::diag("in PERLOPS_PERLTYPES arrayref_string_typetest0(), have person $i/" . ( $how_crowded - 1 ) . ' = ' . $people->[$i] . ", BARBAR\n");
669 # }
670 # Perl::diag("in PERLOPS_PERLTYPES arrayref_string_typetest0(), bottom of subroutine\n");
671 return ( arrayref_string_to_string($people) . 'PERLOPS_PERLTYPES' );
672 }
673  
674 sub arrayref_string_typetest1 {
675 { my arrayref::string $RETURN_TYPE };
676 ( my integer $my_size) = @ARG;
677  
678 # integer_CHECK($my_size);
679 integer_CHECKTRACE( $my_size, '$my_size', 'arrayref_string_typetest1()' );
680 my arrayref::string $new_array = [];
681 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
682 $new_array->[$i] = "Jeffy Ten! $i/" . ( $my_size - 1 ) . ' PERLOPS_PERLTYPES';
683  
684 # Perl::diag("in PERLOPS_PERLTYPES arrayref_string_typetest1(), bottom of for() loop, have i = $i, just set another Jeffy, BARBAR\n");
685 }
686 return ($new_array);
687 }
688  
689 =block_comment
690 THIS IS AN EXAMPLE BLOCK COMMENT
691 it's purpose is to keep from triggering the UselessNoCritic rule,
692 so we can keep the no critic sections at the top of the file for reference
693 =cut
694  
695 # [[[ ARRAY REF SCALAR ]]]
696 # [[[ ARRAY REF SCALAR ]]]
697 # [[[ ARRAY REF SCALAR ]]]
698  
699 # (ref to array) of scalartypes
700 package arrayref::scalartype;
701 use strict;
702 use warnings;
703 use parent -norequire, qw(arrayref);
704  
705 1; # end of package