blib/lib/Perl/Structure/Hash/SubTypes2D.pm untested

filter: Statementstmt 0.0% 0 / 549 Branchbran 0.0% 0 / 114 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 71 Podpod 0.0% 0 / 27 totaltotal 0.0% 0 / 771 CC 58 SCAR 34.9
CC
58
Cov
0%
hashref_arrayref_integer_to_string_format
72.0
hashref_arrayref_number_to_string_format
72.0
hashref_arrayref_string_to_string_format
72.0
CRAP 32.8
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::Hash::SubTypes2D;
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.025_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 # for TYPE_CHECK() used in hashref_arrayref_TYPE_typetestX()
16 use Perl::Type::Integer;
17 use Perl::Type::Number;
18 use Perl::Type::String;
19 # NEED ANSWER: is it bad to have this hash data type code dependent on the array data types?
20 use Perl::Structure::Array; # arrayref::integer, arrayref::number, arrayref::string
21  
22 # [[[ EXPORTS ]]]
23 # DEV NOTE, CORRELATION #rp051: hard-coded list of RPerl data types and data structures
24 use Exporter 'import';
25 our @EXPORT = qw(
26 hashref_arrayref_integer_CHECK
27 hashref_arrayref_integer_CHECKTRACE
28 hashref_arrayref_integer_to_string_compact
29 hashref_arrayref_integer_to_string
30 hashref_arrayref_integer_to_string_pretty
31 hashref_arrayref_integer_to_string_expand
32 hashref_arrayref_integer_to_string_format
33 hashref_arrayref_number_CHECK
34 hashref_arrayref_number_CHECKTRACE
35 hashref_arrayref_number_to_string_compact
36 hashref_arrayref_number_to_string
37 hashref_arrayref_number_to_string_pretty
38 hashref_arrayref_number_to_string_expand
39 hashref_arrayref_number_to_string_format
40 hashref_arrayref_string_CHECK
41 hashref_arrayref_string_CHECKTRACE
42 hashref_arrayref_string_to_string_compact
43 hashref_arrayref_string_to_string
44 hashref_arrayref_string_to_string_pretty
45 hashref_arrayref_string_to_string_expand
46 hashref_arrayref_string_to_string_format
47 );
48 our @EXPORT_OK = qw(
49 hashref_arrayref_integer_typetest0
50 hashref_arrayref_integer_typetest1
51 hashref_arrayref_number_typetest0
52 hashref_arrayref_number_typetest1
53 hashref_arrayref_string_typetest0
54 hashref_arrayref_string_typetest1
55 );
56  
57 # [[[ HASH REF ARRAY REF ]]]
58 # [[[ HASH REF ARRAY REF ]]]
59 # [[[ HASH REF ARRAY REF ]]]
60  
61 # (ref to hash) of (refs to arrays)
62 package hashref::arrayref;
63 use strict;
64 use warnings;
65 use parent -norequire, qw(hashref);
66  
67 # [[[ HASH REF ARRAY REF INTEGER ]]]
68 # [[[ HASH REF ARRAY REF INTEGER ]]]
69 # [[[ HASH REF ARRAY REF INTEGER ]]]
70  
71 # (ref to hash) of (refs to (arrays of integers))
72 package hashref::arrayref::integer;
73 use strict;
74 use warnings;
75 use parent -norequire, qw(hashref::arrayref);
76  
77 # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
78 package Perl::Structure::Hash::SubTypes2D;
79 use strict;
80 use warnings;
81  
82 # [[[ TYPE-CHECKING ]]]
83  
84 sub hashref_arrayref_integer_CHECK {
85 { my void $RETURN_TYPE };
86 ( my $possible_hashref_arrayref_integer ) = @ARG;
87  
88 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_integer_CHECK(), top of subroutine', "\n");
89  
90 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECK() subroutine, but with integer-specific error codes
91 if ( not( defined $possible_hashref_arrayref_integer ) ) {
92 croak( "\n" . 'ERROR EHVRVAVRVIV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::integer value expected but undefined/null value found,' . "\n" . 'croaking' );
93 }
94  
95 if ( not( main::PerlTypes_SvHROKp($possible_hashref_arrayref_integer) ) ) {
96 croak( "\n" . 'ERROR EHVRVAVRVIV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::integer value expected but non-hashref value found,' . "\n" . 'croaking' );
97 }
98  
99 my arrayref::integer $possible_arrayref_integer;
100 foreach my string $key ( sort keys %{$possible_hashref_arrayref_integer} ) {
101 $possible_arrayref_integer = $possible_hashref_arrayref_integer->{$key};
102  
103 # DEV NOTE: the following two if() statements are functionally equivalent to the arrayref_CHECK() subroutine, but with integer-specific error codes
104 if ( not( defined $possible_arrayref_integer ) ) {
105 croak( "\n" . 'ERROR EHVRVAVRVIV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
106 "\n" . 'arrayref::integer value expected but undefined/null value found at key ' . q{'} . $key . q{',} . "\n" . 'croaking' );
107 }
108  
109 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_integer) ) ) {
110 croak( "\n" . 'ERROR EHVRVAVRVIV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
111 "\n" . 'arrayref::integer value expected but non-arrayref value found at key ' . q{'} . $key . q{',} . "\n" . 'croaking' );
112 }
113  
114 my integer $possible_integer;
115 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_integer} ) - 1 ) )
116 {
117 $possible_integer = $possible_arrayref_integer->[$i];
118  
119 # DEV NOTE: the following two if() statements are functionally equivalent to the integer_CHECK() subroutine, but with arrayref_hashref-specific error codes
120 if ( not( defined $possible_integer ) ) {
121 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
122 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
123 croak( "\n" . 'ERROR EHVRVAVRVIV04, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
124 "\n" . 'integer value expected but undefined/null value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' . "\n" . 'croaking' );
125 }
126 if ( not( main::PerlTypes_SvIOKp($possible_integer) ) ) {
127 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
128 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
129 croak( "\n" . 'ERROR EHVRVAVRVIV05, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
130 "\n" . 'integer value expected but non-integer value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' . "\n" . 'croaking' );
131 }
132 }
133 }
134 return;
135 }
136  
137 sub hashref_arrayref_integer_CHECKTRACE {
138 { my void $RETURN_TYPE };
139 ( my $possible_hashref_arrayref_integer, my $variable_name, my $subroutine_name ) = @ARG;
140  
141 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_integer_CHECKTRACE(), top of subroutine', "\n");
142  
143 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECK() subroutine, but with integer-specific error codes
144 if ( not( defined $possible_hashref_arrayref_integer ) ) {
145 croak( "\n" . 'ERROR EHVRVAVRVIV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::integer value expected but undefined/null value found,' .
146 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
147 }
148  
149 if ( not( main::PerlTypes_SvHROKp($possible_hashref_arrayref_integer) ) ) {
150 croak( "\n" . 'ERROR EHVRVAVRVIV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::integer value expected but non-hashref value found,' .
151 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
152 }
153  
154 my arrayref::integer $possible_arrayref_integer;
155 foreach my string $key ( sort keys %{$possible_hashref_arrayref_integer} ) {
156 $possible_arrayref_integer = $possible_hashref_arrayref_integer->{$key};
157  
158 # DEV NOTE: the following two if() statements are functionally equivalent to the arrayref_CHECK() subroutine, but with integer-specific error codes
159 if ( not( defined $possible_arrayref_integer ) ) {
160 croak( "\n" . 'ERROR EHVRVAVRVIV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
161 "\n" . 'arrayref::integer value expected but undefined/null value found at key ' . q{'} . $key . q{',} .
162 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
163 }
164  
165 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_integer) ) ) {
166 croak( "\n" . 'ERROR EHVRVAVRVIV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
167 "\n" . 'arrayref::integer value expected but non-arrayref value found at key ' . q{'} . $key . q{',} .
168 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
169 }
170  
171 my integer $possible_integer;
172 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_integer} ) - 1 ) )
173 {
174 $possible_integer = $possible_arrayref_integer->[$i];
175  
176 # DEV NOTE: the following two if() statements are functionally equivalent to the integer_CHECK() subroutine, but with arrayref_hashref-specific error codes
177 if ( not( defined $possible_integer ) ) {
178 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
179 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
180 croak( "\n" . 'ERROR EHVRVAVRVIV04, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
181 "\n" . 'integer value expected but undefined/null value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' .
182 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
183 }
184 if ( not( main::PerlTypes_SvIOKp($possible_integer) ) ) {
185 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
186 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
187 croak( "\n" . 'ERROR EHVRVAVRVIV05, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
188 "\n" . 'integer value expected but non-integer value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' .
189 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
190 }
191 }
192 }
193 return;
194 }
195  
196 # [[[ STRINGIFY ]]]
197  
198 # call actual stringify routine, format level -1 (compact), indent level 0
199 sub hashref_arrayref_integer_to_string_compact {
200 { my string $RETURN_TYPE };
201 ( my $input_hvref_avref ) = @ARG;
202 return hashref_arrayref_integer_to_string_format($input_hvref_avref, -1, 0);
203 }
204  
205 # call actual stringify routine, format level 0 (normal), indent level 0, DEFAULT
206 sub hashref_arrayref_integer_to_string {
207 { my string $RETURN_TYPE };
208 ( my $input_hvref_avref ) = @ARG;
209 return hashref_arrayref_integer_to_string_format($input_hvref_avref, 0, 0);
210 }
211  
212 # call actual stringify routine, format level 1 (pretty), indent level 0
213 sub hashref_arrayref_integer_to_string_pretty {
214 { my string $RETURN_TYPE };
215 ( my $input_hvref_avref ) = @ARG;
216 return hashref_arrayref_integer_to_string_format($input_hvref_avref, 1, 0);
217 }
218  
219 # call actual stringify routine, format level 2 (expand), indent level 0
220 sub hashref_arrayref_integer_to_string_expand {
221 { my string $RETURN_TYPE };
222 ( my $input_hvref_avref ) = @ARG;
223 return hashref_arrayref_integer_to_string_format($input_hvref_avref, 2, 0);
224 }
225  
226 # convert from (Perl SV containing RV to (Perl HV of (Perl SVs containing IVs))) to Perl-parsable (Perl SV containing PV)
227 sub hashref_arrayref_integer_to_string_format {
228 { my string $RETURN_TYPE };
229 ( my $input_hvref_avref, my integer $format_level, my integer $indent_level ) = @ARG;
230  
231 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_integer_to_string_format(), top of subroutine\n");
232 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_integer_to_string_format(), received $format_level = ', $format_level, "\n");
233 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_integer_to_string_format(), received $indent_level = ', $indent_level, "\n");
234  
235 # hashref_arrayref_integer_CHECK($input_hvref_avref);
236 hashref_arrayref_integer_CHECKTRACE( $input_hvref_avref, '$input_hvref_avref', 'hashref_arrayref_integer_to_string_format()' );
237  
238 # declare local variables, av & sv mean "array value" & "scalar value" as used in Perl core
239 my %input_hv_avref;
240 # my integer $input_hv_avref__length;
241 my arrayref::integer $input_hv_avref__entry_value;
242 my string $output_sv;
243 my boolean $i_is_0 = 1;
244  
245 # dereference input hash reference
246 %input_hv_avref = %{$input_hvref_avref};
247  
248 # generate indent
249 my string $indent = q{ } x $indent_level;
250  
251 # compute length of (number of keys in) input hash
252 # $input_hv_avref__length = scalar keys %input_hv_avref;
253 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_integer_to_string_format(), have \$input_hv_avref__length = $input_hv_avref__length\n");
254  
255 # pre-begin with optional indent, depending on format level
256 if ($format_level >= 1) { $output_sv .= $indent; } # pretty
257  
258 # begin output string with left-curly-brace, as required for all RPerl hashes
259 $output_sv .= '{';
260  
261 # loop through all hash keys
262 foreach my string $key ( sort keys %input_hv_avref ) {
263 # retrieve input hash's entry value at key
264 $input_hv_avref__entry_value = $input_hv_avref{$key};
265  
266 # DEV NOTE: integer type-checking already done as part of hashref_arrayref_integer_CHECKTRACE()
267 # integer_CHECK($input_hv_avref__entry_value);
268 # integer_CHECKTRACE( $input_hv_avref__entry_value, "\$input_hv_avref__entry_value at key '$key'", 'hashref_arrayref_integer_to_string_format()' );
269  
270 # append comma to output string for all elements except index 0
271 if ($i_is_0) { $i_is_0 = 0; }
272 else { $output_sv .= ','; }
273  
274 # append newline-indent-tab or space, depending on format level
275 if ($format_level >= 1) { $output_sv .= "\n" . $indent . q{ }; } # pretty & expand
276 elsif ($format_level >= 0) { $output_sv .= q{ }; } # normal
277  
278 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
279 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
280  
281 # DEV NOTE: emulate Data::Dumper & follow PBP by using single quotes for key strings
282 $output_sv .= q{'} . $key . q{'};
283  
284 # append spaces before and after fat arrow AKA fat comma, depending on format level
285 if ($format_level >= 0) { $output_sv .= ' => '; } # normal & pretty & expand
286 else { $output_sv .= '=>'; } # compact
287  
288 # append newline after fat arrow AKA fat comma, depending on format level
289 if ($format_level >= 2) { $output_sv .= "\n"; } # expand
290  
291 # call *_to_string_format() for data sub-structure
292 $output_sv .= ::arrayref_integer_to_string_format($input_hv_avref__entry_value, ($format_level - 1), ($indent_level + 1)); # YES UNDERSCORES
293 }
294  
295 # append newline-indent or space, depending on format level
296 if ($format_level >= 1) { $output_sv .= "\n" . $indent; } # pretty & expand
297 elsif ($format_level >= 0) { $output_sv .= q{ }; } # normal
298  
299 # end output string with right-curly-brace, as required for all RPerl hashes
300 $output_sv .= '}';
301  
302 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_integer_to_string_format(), after for() loop, have \$output_sv =\n$output_sv\n");
303 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_integer_to_string_format(), bottom of subroutine\n");
304 return ($output_sv);
305 }
306  
307 # [[[ TYPE TESTING ]]]
308  
309 sub hashref_arrayref_integer_typetest0 {
310 { my string $RETURN_TYPE };
311 ( my hashref::arrayref::integer $lucky_integers) = @ARG;
312  
313 # hashref_arrayref_integer_CHECK($lucky_integers);
314 hashref_arrayref_integer_CHECKTRACE( $lucky_integers, '$lucky_integers', 'hashref_arrayref_integer_typetest0()' );
315  
316 # foreach my string $key ( sort keys %{$lucky_integers} ) {
317 # my $lucky_integer = $lucky_integers->{$key};
318 # $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
319 # $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
320 #
321 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_integer_typetest0(), have lucky integer '$key' => " . $lucky_integer . ", BARSTOOL\n");
322 # }
323 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_integer_typetest0(), bottom of subroutine\n");
324 return ( hashref_arrayref_integer_to_string($lucky_integers) . 'PERLOPS_PERLTYPES' );
325 }
326  
327 sub hashref_arrayref_integer_typetest1 {
328 { my hashref::arrayref::integer $RETURN_TYPE };
329 ( my integer $my_size) = @ARG;
330  
331 # integer_CHECK($my_size);
332 integer_CHECKTRACE( $my_size, '$my_size', 'hashref_arrayref_integer_typetest1()' );
333  
334 # create a square 2-D data structure
335 my hashref::arrayref::integer $new_hash = {};
336 my string $temp_key;
337 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
338 $temp_key = 'PERLOPS_PERLTYPES_funkey' . $i;
339 my arrayref::integer $temp_array = [];
340 for my integer $j ( 0 .. ( $my_size - 1)) {
341 $temp_array->[$j] = $i * $j;
342 }
343 $new_hash->{$temp_key} = $temp_array;
344  
345 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_integer_typetest1(), setting entry '$temp_key' => " . Dumper($new_hash->{$temp_key}) . ", BARSTOOL\n");
346 }
347 return ($new_hash);
348 }
349  
350 # [[[ HASH REF ARRAY REF NUMBER ]]]
351 # [[[ HASH REF ARRAY REF NUMBER ]]]
352 # [[[ HASH REF ARRAY REF NUMBER ]]]
353  
354 # (ref to hash) of (refs to (arrays of numbers))
355 package hashref::arrayref::number;
356 use strict;
357 use warnings;
358 use parent -norequire, qw(hashref::arrayref);
359  
360 # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
361 package Perl::Structure::Hash::SubTypes2D;
362 use strict;
363 use warnings;
364  
365 # [[[ TYPE-CHECKING ]]]
366  
367 sub hashref_arrayref_number_CHECK {
368 { my void $RETURN_TYPE };
369 ( my $possible_hashref_arrayref_number ) = @ARG;
370  
371 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_number_CHECK(), top of subroutine', "\n");
372  
373 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECK() subroutine, but with number-specific error codes
374 if ( not( defined $possible_hashref_arrayref_number ) ) {
375 croak( "\n" . 'ERROR EHVRVAVRVNV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::number value expected but undefined/null value found,' . "\n" . 'croaking' );
376 }
377  
378 if ( not( main::PerlTypes_SvHROKp($possible_hashref_arrayref_number) ) ) {
379 croak( "\n" . 'ERROR EHVRVAVRVNV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::number value expected but non-hashref value found,' . "\n" . 'croaking' );
380 }
381  
382 my arrayref::number $possible_arrayref_number;
383 foreach my string $key ( sort keys %{$possible_hashref_arrayref_number} ) {
384 $possible_arrayref_number = $possible_hashref_arrayref_number->{$key};
385  
386 # DEV NOTE: the following two if() statements are functionally equivalent to the arrayref_CHECK() subroutine, but with number-specific error codes
387 if ( not( defined $possible_arrayref_number ) ) {
388 croak( "\n" . 'ERROR EHVRVAVRVNV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
389 "\n" . 'arrayref::number value expected but undefined/null value found at key ' . q{'} . $key . q{',} . "\n" . 'croaking' );
390 }
391  
392 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_number) ) ) {
393 croak( "\n" . 'ERROR EHVRVAVRVNV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
394 "\n" . 'arrayref::number value expected but non-arrayref value found at key ' . q{'} . $key . q{',} . "\n" . 'croaking' );
395 }
396  
397 my number $possible_number;
398 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_number} ) - 1 ) )
399 {
400 $possible_number = $possible_arrayref_number->[$i];
401  
402 # DEV NOTE: the following two if() statements are functionally equivalent to the number_CHECK() subroutine, but with arrayref_hashref-specific error codes
403 if ( not( defined $possible_number ) ) {
404 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
405 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
406 croak( "\n" . 'ERROR EHVRVAVRVNV04, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
407 "\n" . 'number value expected but undefined/null value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' . "\n" . 'croaking' );
408 }
409 if (not( main::PerlTypes_SvNOKp($possible_number)
410 || main::PerlTypes_SvIOKp($possible_number) ) ) {
411 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
412 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
413 croak( "\n" . 'ERROR EHVRVAVRVNV05, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
414 "\n" . 'number value expected but non-number value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' . "\n" . 'croaking' );
415 }
416 }
417 }
418 return;
419 }
420  
421 sub hashref_arrayref_number_CHECKTRACE {
422 { my void $RETURN_TYPE };
423 ( my $possible_hashref_arrayref_number, my $variable_name, my $subroutine_name ) = @ARG;
424  
425 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_number_CHECKTRACE(), top of subroutine', "\n");
426  
427 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECK() subroutine, but with number-specific error codes
428 if ( not( defined $possible_hashref_arrayref_number ) ) {
429 croak( "\n" . 'ERROR EHVRVAVRVNV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::number value expected but undefined/null value found,' .
430 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
431 }
432  
433 if ( not( main::PerlTypes_SvHROKp($possible_hashref_arrayref_number) ) ) {
434 croak( "\n" . 'ERROR EHVRVAVRVNV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::number value expected but non-hashref value found,' .
435 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
436 }
437  
438 my arrayref::number $possible_arrayref_number;
439 foreach my string $key ( sort keys %{$possible_hashref_arrayref_number} ) {
440 $possible_arrayref_number = $possible_hashref_arrayref_number->{$key};
441  
442 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_number_CHECKTRACE(), at $key = ', q{'}, $key, q{'}, ', have $possible_arrayref_number = ', Dumper($possible_arrayref_number), "\n");
443  
444 # DEV NOTE: the following two if() statements are functionally equivalent to the arrayref_CHECK() subroutine, but with number-specific error codes
445 if ( not( defined $possible_arrayref_number ) ) {
446 croak( "\n" . 'ERROR EHVRVAVRVNV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
447 "\n" . 'arrayref::number value expected but undefined/null value found at key ' . q{'} . $key . q{',} .
448 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
449 }
450  
451 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_number) ) ) {
452 croak( "\n" . 'ERROR EHVRVAVRVNV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
453 "\n" . 'arrayref::number value expected but non-arrayref value found at key ' . q{'} . $key . q{',} .
454 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
455 }
456  
457 my number $possible_number;
458 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_number} ) - 1 ) )
459 {
460 $possible_number = $possible_arrayref_number->[$i];
461  
462 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_number_CHECKTRACE(), at $key = ', q{'}, $key, q{'}, ', index $i = ', $i, ', have $possible_number = ', $possible_number, "\n");
463  
464 # DEV NOTE: the following two if() statements are functionally equivalent to the number_CHECK() subroutine, but with arrayref_hashref-specific error codes
465 if ( not( defined $possible_number ) ) {
466 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
467 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
468 croak( "\n" . 'ERROR EHVRVAVRVNV04, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
469 "\n" . 'number value expected but undefined/null value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' .
470 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
471 }
472 if (not( main::PerlTypes_SvNOKp($possible_number)
473 || main::PerlTypes_SvIOKp($possible_number) ) ) {
474 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
475 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
476 croak( "\n" . 'ERROR EHVRVAVRVNV05, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
477 "\n" . 'number value expected but non-number value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' .
478 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
479 }
480 }
481 }
482 return;
483 }
484  
485 # [[[ STRINGIFY ]]]
486  
487 # call actual stringify routine, format level -1 (compact), indent level 0
488 sub hashref_arrayref_number_to_string_compact {
489 { my string $RETURN_TYPE };
490 ( my $input_hvref_avref ) = @ARG;
491 return hashref_arrayref_number_to_string_format($input_hvref_avref, -1, 0);
492 }
493  
494 # call actual stringify routine, format level 0 (normal), indent level 0, DEFAULT
495 sub hashref_arrayref_number_to_string {
496 { my string $RETURN_TYPE };
497 ( my $input_hvref_avref ) = @ARG;
498 return hashref_arrayref_number_to_string_format($input_hvref_avref, 0, 0);
499 }
500  
501 # call actual stringify routine, format level 1 (pretty), indent level 0
502 sub hashref_arrayref_number_to_string_pretty {
503 { my string $RETURN_TYPE };
504 ( my $input_hvref_avref ) = @ARG;
505 return hashref_arrayref_number_to_string_format($input_hvref_avref, 1, 0);
506 }
507  
508 # call actual stringify routine, format level 2 (expand), indent level 0
509 sub hashref_arrayref_number_to_string_expand {
510 { my string $RETURN_TYPE };
511 ( my $input_hvref_avref ) = @ARG;
512 return hashref_arrayref_number_to_string_format($input_hvref_avref, 2, 0);
513 }
514  
515 # convert from (Perl SV containing RV to (Perl HV of (Perl SVs containing NVs))) to Perl-parsable (Perl SV containing PV)
516 sub hashref_arrayref_number_to_string_format {
517 { my string $RETURN_TYPE };
518 ( my $input_hvref_avref, my integer $format_level, my integer $indent_level ) = @ARG;
519  
520 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_number_to_string_format(), top of subroutine\n");
521 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_number_to_string_format(), received $format_level = ', $format_level, "\n");
522 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_number_to_string_format(), received $indent_level = ', $indent_level, "\n");
523  
524 # hashref_arrayref_number_CHECK($input_hvref_avref);
525 hashref_arrayref_number_CHECKTRACE( $input_hvref_avref, '$input_hvref_avref', 'hashref_arrayref_number_to_string_format()' );
526  
527 # declare local variables, av & sv mean "array value" & "scalar value" as used in Perl core
528 my %input_hv_avref;
529 # my integer $input_hv_avref__length;
530 my arrayref::number $input_hv_avref__entry_value;
531 my string $output_sv;
532 my boolean $i_is_0 = 1;
533  
534 # dereference input hash reference
535 %input_hv_avref = %{$input_hvref_avref};
536  
537 # generate indent
538 my string $indent = q{ } x $indent_level;
539  
540 # compute length of (number of keys in) input hash
541 # $input_hv_avref__length = scalar keys %input_hv_avref;
542 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_number_to_string_format(), have \$input_hv_avref__length = $input_hv_avref__length\n");
543  
544 # pre-begin with optional indent, depending on format level
545 if ($format_level >= 1) { $output_sv .= $indent; } # pretty
546  
547 # begin output string with left-curly-brace, as required for all RPerl hashes
548 $output_sv .= '{';
549  
550 # loop through all hash keys
551 foreach my string $key ( sort keys %input_hv_avref ) {
552 # retrieve input hash's entry value at key
553 $input_hv_avref__entry_value = $input_hv_avref{$key};
554  
555 # DEV NOTE: number type-checking already done as part of hashref_arrayref_number_CHECKTRACE()
556 # number_CHECK($input_hv_avref__entry_value);
557 # number_CHECKTRACE( $input_hv_avref__entry_value, "\$input_hv_avref__entry_value at key '$key'", 'hashref_arrayref_number_to_string_format()' );
558  
559 # append comma to output string for all elements except index 0
560 if ($i_is_0) { $i_is_0 = 0; }
561 else { $output_sv .= ','; }
562  
563 # append newline-indent-tab or space, depending on format level
564 if ($format_level >= 1) { $output_sv .= "\n" . $indent . q{ }; } # pretty & expand
565 elsif ($format_level >= 0) { $output_sv .= q{ }; } # normal
566  
567 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
568 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
569  
570 # DEV NOTE: emulate Data::Dumper & follow PBP by using single quotes for key strings
571 $output_sv .= q{'} . $key . q{'};
572  
573 # append spaces before and after fat arrow AKA fat comma, depending on format level
574 if ($format_level >= 0) { $output_sv .= ' => '; } # normal & pretty & expand
575 else { $output_sv .= '=>'; } # compact
576  
577 # append newline after fat arrow AKA fat comma, depending on format level
578 if ($format_level >= 2) { $output_sv .= "\n"; } # expand
579  
580 # call *_to_string_format() for data sub-structure
581 $output_sv .= ::arrayref_number_to_string_format($input_hv_avref__entry_value, ($format_level - 1), ($indent_level + 1)); # YES UNDERSCORES
582 }
583  
584 # append newline-indent or space, depending on format level
585 if ($format_level >= 1) { $output_sv .= "\n" . $indent; } # pretty & expand
586 elsif ($format_level >= 0) { $output_sv .= q{ }; } # normal
587  
588 # end output string with right-curly-brace, as required for all RPerl hashes
589 $output_sv .= '}';
590  
591 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_number_to_string_format(), after for() loop, have \$output_sv =\n$output_sv\n");
592 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_number_to_string_format(), bottom of subroutine\n");
593 return ($output_sv);
594 }
595  
596 # [[[ TYPE TESTING ]]]
597  
598 sub hashref_arrayref_number_typetest0 {
599 { my string $RETURN_TYPE };
600 ( my hashref::arrayref::number $lucky_numbers) = @ARG;
601  
602 # hashref_arrayref_number_CHECK($lucky_numbers);
603 hashref_arrayref_number_CHECKTRACE( $lucky_numbers, '$lucky_numbers', 'hashref_arrayref_number_typetest0()' );
604  
605 # foreach my string $key ( sort keys %{$lucky_numbers} ) {
606 # my $lucky_number = $lucky_numbers->{$key};
607 # $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
608 # $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
609 #
610 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_number_typetest0(), have lucky number '$key' => " . $lucky_number . ", BARSTOOL\n");
611 # }
612 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_number_typetest0(), bottom of subroutine\n");
613 return ( hashref_arrayref_number_to_string($lucky_numbers) . 'PERLOPS_PERLTYPES' );
614 }
615  
616 sub hashref_arrayref_number_typetest1 {
617 { my hashref::arrayref::number $RETURN_TYPE };
618 ( my integer $my_size) = @ARG;
619  
620 # integer_CHECK($my_size);
621 integer_CHECKTRACE( $my_size, '$my_size', 'hashref_arrayref_number_typetest1()' );
622  
623 # create a square 2-D data structure
624 my hashref::arrayref::number $new_hash = {};
625 my string $temp_key;
626 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
627 $temp_key = 'PERLOPS_PERLTYPES_funkey' . $i;
628 my arrayref::number $temp_array = [];
629 for my integer $j ( 0 .. ( $my_size - 1)) {
630 $temp_array->[$j] = $i * $j * 5.123456789;
631 }
632 $new_hash->{$temp_key} = $temp_array;
633  
634 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_number_typetest1(), setting entry '$temp_key' => " . Dumper($new_hash->{$temp_key}) . ", BARSTOOL\n");
635 }
636 return ($new_hash);
637 }
638  
639 # [[[ HASH REF ARRAY REF STRING ]]]
640 # [[[ HASH REF ARRAY REF STRING ]]]
641 # [[[ HASH REF ARRAY REF STRING ]]]
642  
643 # (ref to hash) of (refs to (arrays of strings))
644 package hashref::arrayref::string;
645 use strict;
646 use warnings;
647 use parent -norequire, qw(hashref::arrayref);
648  
649 # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
650 package Perl::Structure::Hash::SubTypes2D;
651 use strict;
652 use warnings;
653  
654 # [[[ TYPE-CHECKING ]]]
655  
656 sub hashref_arrayref_string_CHECK {
657 { my void $RETURN_TYPE };
658 ( my $possible_hashref_arrayref_string ) = @ARG;
659  
660 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_string_CHECK(), top of subroutine', "\n");
661  
662 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECK() subroutine, but with string-specific error codes
663 if ( not( defined $possible_hashref_arrayref_string ) ) {
664 croak( "\n" . 'ERROR EHVRVAVRVPV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::string value expected but undefined/null value found,' . "\n" . 'croaking' );
665 }
666  
667 if ( not( main::PerlTypes_SvHROKp($possible_hashref_arrayref_string) ) ) {
668 croak( "\n" . 'ERROR EHVRVAVRVPV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::string value expected but non-hashref value found,' . "\n" . 'croaking' );
669 }
670  
671 my arrayref::string $possible_arrayref_string;
672 foreach my string $key ( sort keys %{$possible_hashref_arrayref_string} ) {
673 $possible_arrayref_string = $possible_hashref_arrayref_string->{$key};
674  
675 # DEV NOTE: the following two if() statements are functionally equivalent to the arrayref_CHECK() subroutine, but with string-specific error codes
676 if ( not( defined $possible_arrayref_string ) ) {
677 croak( "\n" . 'ERROR EHVRVAVRVPV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
678 "\n" . 'arrayref::string value expected but undefined/null value found at key ' . q{'} . $key . q{',} . "\n" . 'croaking' );
679 }
680  
681 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_string) ) ) {
682 croak( "\n" . 'ERROR EHVRVAVRVPV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
683 "\n" . 'arrayref::string value expected but non-arrayref value found at key ' . q{'} . $key . q{',} . "\n" . 'croaking' );
684 }
685  
686 my string $possible_string;
687 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_string} ) - 1 ) )
688 {
689 $possible_string = $possible_arrayref_string->[$i];
690  
691 # DEV NOTE: the following two if() statements are functionally equivalent to the string_CHECK() subroutine, but with arrayref_hashref-specific error codes
692 if ( not( defined $possible_string ) ) {
693 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
694 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
695 croak( "\n" . 'ERROR EHVRVAVRVPV04, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
696 "\n" . 'string value expected but undefined/null value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' . "\n" . 'croaking' );
697 }
698 if ( not( main::PerlTypes_SvPOKp($possible_string) ) ) {
699 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
700 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
701 croak( "\n" . 'ERROR EHVRVAVRVPV05, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
702 "\n" . 'string value expected but non-string value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' . "\n" . 'croaking' );
703 }
704 }
705 }
706 return;
707 }
708  
709 sub hashref_arrayref_string_CHECKTRACE {
710 { my void $RETURN_TYPE };
711 ( my $possible_hashref_arrayref_string, my $variable_name, my $subroutine_name ) = @ARG;
712  
713 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_string_CHECKTRACE(), top of subroutine', "\n");
714  
715 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECK() subroutine, but with string-specific error codes
716 if ( not( defined $possible_hashref_arrayref_string ) ) {
717 croak( "\n" . 'ERROR EHVRVAVRVPV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::string value expected but undefined/null value found,' .
718 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
719 }
720  
721 if ( not( main::PerlTypes_SvHROKp($possible_hashref_arrayref_string) ) ) {
722 croak( "\n" . 'ERROR EHVRVAVRVPV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' . "\n" . 'hashref::arrayref::string value expected but non-hashref value found,' .
723 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
724 }
725  
726 my arrayref::string $possible_arrayref_string;
727 foreach my string $key ( sort keys %{$possible_hashref_arrayref_string} ) {
728 $possible_arrayref_string = $possible_hashref_arrayref_string->{$key};
729  
730 # DEV NOTE: the following two if() statements are functionally equivalent to the arrayref_CHECK() subroutine, but with string-specific error codes
731 if ( not( defined $possible_arrayref_string ) ) {
732 croak( "\n" . 'ERROR EHVRVAVRVPV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
733 "\n" . 'arrayref::string value expected but undefined/null value found at key ' . q{'} . $key . q{',} .
734 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
735 }
736  
737 if ( not( main::PerlTypes_SvAROKp($possible_arrayref_string) ) ) {
738 croak( "\n" . 'ERROR EHVRVAVRVPV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
739 "\n" . 'arrayref::string value expected but non-arrayref value found at key ' . q{'} . $key . q{',} .
740 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
741 }
742  
743 my string $possible_string;
744 for my integer $i ( 0 .. ( ( scalar @{$possible_arrayref_string} ) - 1 ) )
745 {
746 $possible_string = $possible_arrayref_string->[$i];
747  
748 # DEV NOTE: the following two if() statements are functionally equivalent to the string_CHECK() subroutine, but with arrayref_hashref-specific error codes
749 if ( not( defined $possible_string ) ) {
750 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
751 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
752 croak( "\n" . 'ERROR EHVRVAVRVPV04, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
753 "\n" . 'string value expected but undefined/null value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' .
754 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
755 }
756 if ( not( main::PerlTypes_SvPOKp($possible_string) ) ) {
757 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
758 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
759 croak( "\n" . 'ERROR EHVRVAVRVPV05, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:' .
760 "\n" . 'string value expected but non-string value found at index ' . $i . ', key ' . q{'} . $key . q{'} . ',' .
761 "\n" . 'in variable ' . q{'} . $variable_name . q{'} . ' from subroutine ' . q{'} . $subroutine_name . q{',} . "\n" . 'croaking' );
762 }
763 }
764 }
765 return;
766 }
767  
768 # [[[ STRINGIFY ]]]
769  
770 # call actual stringify routine, format level -1 (compact), indent level 0
771 sub hashref_arrayref_string_to_string_compact {
772 { my string $RETURN_TYPE };
773 ( my $input_hvref_avref ) = @ARG;
774 return hashref_arrayref_string_to_string_format($input_hvref_avref, -1, 0);
775 }
776  
777 # call actual stringify routine, format level 0 (normal), indent level 0, DEFAULT
778 sub hashref_arrayref_string_to_string {
779 { my string $RETURN_TYPE };
780 ( my $input_hvref_avref ) = @ARG;
781 return hashref_arrayref_string_to_string_format($input_hvref_avref, 0, 0);
782 }
783  
784 # call actual stringify routine, format level 1 (pretty), indent level 0
785 sub hashref_arrayref_string_to_string_pretty {
786 { my string $RETURN_TYPE };
787 ( my $input_hvref_avref ) = @ARG;
788 return hashref_arrayref_string_to_string_format($input_hvref_avref, 1, 0);
789 }
790  
791 # call actual stringify routine, format level 2 (expand), indent level 0
792 sub hashref_arrayref_string_to_string_expand {
793 { my string $RETURN_TYPE };
794 ( my $input_hvref_avref ) = @ARG;
795 return hashref_arrayref_string_to_string_format($input_hvref_avref, 2, 0);
796 }
797  
798 # convert from (Perl SV containing RV to (Perl HV of (Perl SVs containing NVs))) to Perl-parsable (Perl SV containing PV)
799 sub hashref_arrayref_string_to_string_format {
800 { my string $RETURN_TYPE };
801 ( my $input_hvref_avref, my integer $format_level, my integer $indent_level ) = @ARG;
802  
803 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_string_to_string_format(), top of subroutine\n");
804 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_string_to_string_format(), received $format_level = ', $format_level, "\n");
805 # Perl::diag('in PERLOPS_PERLTYPES hashref_arrayref_string_to_string_format(), received $indent_level = ', $indent_level, "\n");
806  
807 # hashref_arrayref_string_CHECK($input_hvref_avref);
808 hashref_arrayref_string_CHECKTRACE( $input_hvref_avref, '$input_hvref_avref', 'hashref_arrayref_string_to_string_format()' );
809  
810 # declare local variables, av & sv mean "array value" & "scalar value" as used in Perl core
811 my %input_hv_avref;
812 # my integer $input_hv_avref__length;
813 my arrayref::string $input_hv_avref__entry_value;
814 my string $output_sv;
815 my boolean $i_is_0 = 1;
816  
817 # dereference input hash reference
818 %input_hv_avref = %{$input_hvref_avref};
819  
820 # generate indent
821 my string $indent = q{ } x $indent_level;
822  
823 # compute length of (number of keys in) input hash
824 # $input_hv_avref__length = scalar keys %input_hv_avref;
825 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_string_to_string_format(), have \$input_hv_avref__length = $input_hv_avref__length\n");
826  
827 # pre-begin with optional indent, depending on format level
828 if ($format_level >= 1) { $output_sv .= $indent; } # pretty
829  
830 # begin output string with left-curly-brace, as required for all RPerl hashes
831 $output_sv .= '{';
832  
833 # loop through all hash keys
834 foreach my string $key ( sort keys %input_hv_avref ) {
835 # retrieve input hash's entry value at key
836 $input_hv_avref__entry_value = $input_hv_avref{$key};
837  
838 # DEV NOTE: string type-checking already done as part of hashref_arrayref_string_CHECKTRACE()
839 # string_CHECK($input_hv_avref__entry_value);
840 # string_CHECKTRACE( $input_hv_avref__entry_value, "\$input_hv_avref__entry_value at key '$key'", 'hashref_arrayref_string_to_string_format()' );
841  
842 # append comma to output string for all elements except index 0
843 if ($i_is_0) { $i_is_0 = 0; }
844 else { $output_sv .= ','; }
845  
846 # append newline-indent-tab or space, depending on format level
847 if ($format_level >= 1) { $output_sv .= "\n" . $indent . q{ }; } # pretty & expand
848 elsif ($format_level >= 0) { $output_sv .= q{ }; } # normal
849  
850 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
851 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
852  
853 # DEV NOTE: emulate Data::Dumper & follow PBP by using single quotes for key strings
854 $output_sv .= q{'} . $key . q{'};
855  
856 # append spaces before and after fat arrow AKA fat comma, depending on format level
857 if ($format_level >= 0) { $output_sv .= ' => '; } # normal & pretty & expand
858 else { $output_sv .= '=>'; } # compact
859  
860 # append newline after fat arrow AKA fat comma, depending on format level
861 if ($format_level >= 2) { $output_sv .= "\n"; } # expand
862  
863 # call *_to_string_format() for data sub-structure
864 $output_sv .= ::arrayref_string_to_string_format($input_hv_avref__entry_value, ($format_level - 1), ($indent_level + 1)); # YES UNDERSCORES
865 }
866  
867 # append newline-indent or space, depending on format level
868 if ($format_level >= 1) { $output_sv .= "\n" . $indent; } # pretty & expand
869 elsif ($format_level >= 0) { $output_sv .= q{ }; } # normal
870  
871 # end output string with right-curly-brace, as required for all RPerl hashes
872 $output_sv .= '}';
873  
874 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_string_to_string_format(), after for() loop, have \$output_sv =\n$output_sv\n");
875 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_string_to_string_format(), bottom of subroutine\n");
876 return ($output_sv);
877 }
878  
879 # [[[ TYPE TESTING ]]]
880  
881 sub hashref_arrayref_string_typetest0 {
882 { my string $RETURN_TYPE };
883 ( my hashref::arrayref::string $lucky_strings) = @ARG;
884  
885 # hashref_arrayref_string_CHECK($lucky_strings);
886 hashref_arrayref_string_CHECKTRACE( $lucky_strings, '$lucky_strings', 'hashref_arrayref_string_typetest0()' );
887  
888 # foreach my string $key ( sort keys %{$lucky_strings} ) {
889 # my $lucky_string = $lucky_strings->{$key};
890 # $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
891 # $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
892 #
893 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_string_typetest0(), have lucky string '$key' => " . $lucky_string . ", BARSTOOL\n");
894 # }
895 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_string_typetest0(), bottom of subroutine\n");
896 return ( hashref_arrayref_string_to_string($lucky_strings) . 'PERLOPS_PERLTYPES' );
897 }
898  
899 sub hashref_arrayref_string_typetest1 {
900 { my hashref::arrayref::string $RETURN_TYPE };
901 ( my integer $my_size) = @ARG;
902  
903 # integer_CHECK($my_size);
904 integer_CHECKTRACE( $my_size, '$my_size', 'hashref_arrayref_string_typetest1()' );
905  
906 # create a square 2-D data structure
907 my hashref::arrayref::string $new_hash = {};
908 my string $temp_key;
909 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
910 $temp_key = 'PERLOPS_PERLTYPES_funkey' . $i;
911 my arrayref::string $temp_array = [];
912 for my integer $j ( 0 .. ( $my_size - 1)) {
913 $temp_array->[$j] = 'Jeffy Ten! (' . integer_to_string($i) . ', ' . integer_to_string($j) . ')/' . integer_to_string($my_size - 1);
914 }
915 $new_hash->{$temp_key} = $temp_array;
916  
917 # Perl::diag("in PERLOPS_PERLTYPES hashref_arrayref_string_typetest1(), setting entry '$temp_key' => " . Dumper($new_hash->{$temp_key}) . ", BARSTOOL\n");
918 }
919 return ($new_hash);
920 }
921  
922 # [[[ HASH REF HASH REF ]]]
923 # [[[ HASH REF HASH REF ]]]
924 # [[[ HASH REF HASH REF ]]]
925  
926 # (ref to hash) of (refs to hashs)
927 package hashref::hashref;
928 use strict;
929 use warnings;
930 use parent -norequire, qw(hashref);
931  
932 # (ref to hash) of (refs to (hashs of integers))
933 package hashref::hashref::integer;
934 use strict;
935 use warnings;
936 use parent -norequire, qw(hashref::hashref);
937  
938 # (ref to hash) of (refs to (hashs of numbers))
939 package hashref::hashref::number;
940 use strict;
941 use warnings;
942 use parent -norequire, qw(hashref::hashref);
943  
944 # (ref to hash) of (refs to (hashs of strings))
945 package hashref::hashref::string;
946 use strict;
947 use warnings;
948 use parent -norequire, qw(hashref::hashref);
949  
950 # (ref to hash) of (refs to (hashs of scalars))
951 package hashref::hashref::scalartype;
952 use strict;
953 use warnings;
954 use parent -norequire, qw(hashref::hashref);
955  
956 # [[[ HASH REF OBJECT (2-dimensional???) ]]]
957 # [[[ HASH REF OBJECT (2-dimensional???) ]]]
958 # [[[ HASH REF OBJECT (2-dimensional???) ]]]
959  
960 # (ref to hash) of objects
961 package hashref::object;
962 use strict;
963 use warnings;
964 use parent -norequire, qw(hashref);
965  
966 1; # end of package