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

filter: Statementstmt 0.0% 0 / 429 Branchbran 0.0% 0 / 84 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 / 606 CC 43 SCAR 31.0
CC
43
Cov
0%
hashref_integer_to_string_format
56.0
hashref_number_to_string_format
56.0
hashref_string_to_string_format
56.0
CRAP 22.1
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::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.018_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 hashref_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 hashref_integer_CHECK
22 hashref_integer_CHECKTRACE
23 hashref_number_CHECK
24 hashref_number_CHECKTRACE
25 hashref_string_CHECK
26 hashref_string_CHECKTRACE
27 hashref_integer_to_string_compact
28 hashref_integer_to_string
29 hashref_integer_to_string_pretty
30 hashref_integer_to_string_expand
31 hashref_integer_to_string_format
32 hashref_number_to_string_compact
33 hashref_number_to_string
34 hashref_number_to_string_pretty
35 hashref_number_to_string_expand
36 hashref_number_to_string_format
37 hashref_string_to_string_compact
38 hashref_string_to_string
39 hashref_string_to_string_pretty
40 hashref_string_to_string_expand
41 hashref_string_to_string_format
42 );
43 our @EXPORT_OK = qw(
44 hashref_integer_typetest0
45 hashref_integer_typetest1
46 hashref_number_typetest0
47 hashref_number_typetest1
48 hashref_string_typetest0
49 hashref_string_typetest1
50 );
51  
52 # [[[ HASH REF INTEGER ]]]
53 # [[[ HASH REF INTEGER ]]]
54 # [[[ HASH REF INTEGER ]]]
55  
56 # (ref to hash) of integers
57 package hashref::integer;
58 use strict;
59 use warnings;
60 use parent -norequire, qw(hashref);
61 use Carp;
62  
63 # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
64 package Perl::Structure::Hash::SubTypes1D;
65 use strict;
66 use warnings;
67  
68 # [[[ TYPE-CHECKING ]]]
69  
70 sub hashref_integer_CHECK {
71 { my void $RETURN_TYPE };
72 ( my $possible_hashref_integer ) = @ARG;
73  
74 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECK() subroutine, but with integer-specific error codes
75 if ( not( defined $possible_hashref_integer ) ) {
76 croak( "\nERROR EHVRVIV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::integer value expected but undefined/null value found,\ncroaking" );
77 }
78  
79 if ( not( main::PerlTypes_SvHROKp($possible_hashref_integer) ) ) {
80 croak( "\nERROR EHVRVIV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::integer value expected but non-hashref value found,\ncroaking" );
81 }
82  
83 my integer $possible_integer;
84 foreach my string $key ( sort keys %{$possible_hashref_integer} ) {
85 $possible_integer = $possible_hashref_integer->{$key};
86  
87 # DEV NOTE: the following two if() statements are functionally equivalent to the integer_CHECK() subroutine, but with hash-specific error codes
88 if ( not( defined $possible_integer ) ) {
89 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
90 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
91 croak( "\nERROR EHVRVIV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger value expected but undefined/null value found at key '$key',\ncroaking" );
92 }
93 if ( not( main::PerlTypes_SvIOKp($possible_integer) ) ) {
94 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
95 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
96 croak( "\nERROR EHVRVIV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger value expected but non-integer value found at key '$key',\ncroaking" );
97 }
98 }
99 return;
100 }
101  
102 sub hashref_integer_CHECKTRACE {
103 { my void $RETURN_TYPE };
104 ( my $possible_hashref_integer, my $variable_name, my $subroutine_name )
105 = @ARG;
106  
107 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECKTRACE() subroutine, but with integer-specific error codes
108 if ( not( defined $possible_hashref_integer ) ) {
109 croak( "\nERROR EHVRVIV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::integer value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
110 }
111  
112 if ( not( main::PerlTypes_SvHROKp($possible_hashref_integer) ) ) {
113 croak(
114 "\nERROR EHVRVIV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::integer value expected but non-hashref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" ); }
115  
116 my integer $possible_integer;
117 foreach my string $key ( sort keys %{$possible_hashref_integer} ) {
118 $possible_integer = $possible_hashref_integer->{$key};
119  
120 # DEV NOTE: the following two if() statements are functionally equivalent to the integer_CHECKTRACE() subroutine, but with hash-specific error codes
121 if ( not( defined $possible_integer ) ) {
122 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
123 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
124 croak( "\nERROR EHVRVIV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger value expected but undefined/null value found at key '$key',\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
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( "\nERROR EHVRVIV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\ninteger value expected but non-integer value found at key '$key',\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
130 }
131 }
132 return;
133 }
134  
135 # [[[ STRINGIFY ]]]
136  
137 # DEV NOTE: 1-D format levels are 1 less than 2-D format levels
138  
139 # call actual stringify routine, format level -2 (compact), indent level 0
140 sub hashref_integer_to_string_compact {
141 { my string $RETURN_TYPE };
142 ( my $input_hvref ) = @ARG;
143 return hashref_integer_to_string_format($input_hvref, -2, 0);
144 }
145  
146 # call actual stringify routine, format level -1 (normal), indent level 0, DEFAULT
147 sub hashref_integer_to_string {
148 { my string $RETURN_TYPE };
149 ( my $input_hvref ) = @ARG;
150 return hashref_integer_to_string_format($input_hvref, -1, 0);
151 }
152  
153 # call actual stringify routine, format level 0 (pretty), indent level 0
154 sub hashref_integer_to_string_pretty {
155 { my string $RETURN_TYPE };
156 ( my $input_hvref ) = @ARG;
157 return hashref_integer_to_string_format($input_hvref, 0, 0);
158 }
159  
160 # call actual stringify routine, format level 1 (expand), indent level 0
161 sub hashref_integer_to_string_expand {
162 { my string $RETURN_TYPE };
163 ( my $input_hvref ) = @ARG;
164 return hashref_integer_to_string_format($input_hvref, 1, 0);
165 }
166  
167 # convert from (Perl SV containing RV to (Perl HV of (Perl SVs containing IVs))) to Perl-parsable (Perl SV containing PV)
168 sub hashref_integer_to_string_format {
169 { my string $RETURN_TYPE };
170 ( my $input_hvref, my integer $format_level, my integer $indent_level ) = @ARG;
171  
172 # Perl::diag("in PERLOPS_PERLTYPES hashref_integer_to_string_format(), top of subroutine\n");
173  
174 # hashref_integer_CHECK($input_hvref);
175 hashref_integer_CHECKTRACE( $input_hvref, '$input_hvref', 'hashref_integer_to_string()' );
176  
177 # declare local variables, av & sv mean "array value" & "scalar value" as used in Perl core
178 my %input_hv;
179 # my integer $input_hv__length;
180 my integer $input_hv__entry_value;
181 my string $output_sv = q{};
182 my boolean $i_is_0 = 1;
183  
184 # dereference input hash reference
185 %input_hv = %{$input_hvref};
186  
187 # generate indent
188 my string $indent = q{ } x $indent_level;
189  
190 # compute length of (number of keys in) input hash
191 # $input_hv__length = scalar keys %input_hv;
192 # Perl::diag("in PERLOPS_PERLTYPES hashref_integer_to_string_format(), have \$input_hv__length = $input_hv__length\n");
193  
194 # pre-begin with optional indent, depending on format level
195 if ($format_level >= 1) { $output_sv .= $indent; }
196  
197 # begin output string with left-curly-brace, as required for all RPerl hashes
198 $output_sv .= '{';
199  
200 # loop through all hash keys
201 foreach my string $key ( sort keys %input_hv ) {
202 # retrieve input hash's entry value at key
203 $input_hv__entry_value = $input_hv{$key};
204  
205 # DEV NOTE: integer type-checking already done as part of hashref_integer_CHECKTRACE()
206 # integer_CHECK($input_hv__entry_value);
207 # integer_CHECKTRACE( $input_hv__entry_value, "\$input_hv__entry_value at key '$key'", 'hashref_integer_to_string()' );
208  
209 # append comma to output string for all elements except index 0
210 if ($i_is_0) { $i_is_0 = 0; }
211 else { $output_sv .= ','; }
212  
213 # append newline-indent-tab or space, depending on format level
214 if ($format_level >= 1) { $output_sv .= "\n" . $indent . q{ }; }
215 elsif ($format_level >= -1) { $output_sv .= q{ }; }
216  
217 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
218 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
219  
220 # DEV NOTE: emulate Data::Dumper & follow PBP by using single quotes for key strings
221 $output_sv .= q{'} . $key. q{'};
222  
223 # append spaces before and after fat arrow AKA fat comma, depending on format level
224 if ($format_level >= -1) { $output_sv .= ' => '; }
225 else { $output_sv .= '=>'; }
226  
227 # $output_sv .= $input_hv__entry_value; # NO UNDERSCORES
228 $output_sv .= ::integer_to_string($input_hv__entry_value); # YES UNDERSCORES
229 }
230  
231 # append newline-indent or space, depending on format level
232 if ($format_level >= 1) { $output_sv .= "\n" . $indent; }
233 elsif ($format_level >= -1) { $output_sv .= q{ }; }
234  
235 # end output string with right-curly-brace, as required for all RPerl hashes
236 $output_sv .= '}';
237  
238 # Perl::diag("in PERLOPS_PERLTYPES hashref_integer_to_string_format(), after for() loop, have \$output_sv =\n$output_sv\n");
239 # Perl::diag("in PERLOPS_PERLTYPES hashref_integer_to_string_format(), bottom of subroutine\n");
240 return ($output_sv);
241 }
242  
243 # [[[ TYPE TESTING ]]]
244  
245 sub hashref_integer_typetest0 {
246 { my string $RETURN_TYPE };
247 ( my hashref::integer $lucky_integers) = @ARG;
248  
249 # hashref_integer_CHECK($lucky_integers);
250 hashref_integer_CHECKTRACE( $lucky_integers, '$lucky_integers',
251 'hashref_integer_typetest0()' );
252  
253 # foreach my string $key ( sort keys %{$lucky_integers} ) {
254 # my $lucky_integer = $lucky_integers->{$key};
255 # $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
256 # $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
257 #
258 # Perl::diag("in PERLOPS_PERLTYPES hashref_integer_typetest0(), have lucky integer '$key' => " . $lucky_integer . ", BARSTOOL\n");
259 # }
260 # Perl::diag("in PERLOPS_PERLTYPES hashref_integer_typetest0(), bottom of subroutine\n");
261 return (
262 hashref_integer_to_string($lucky_integers) . 'PERLOPS_PERLTYPES' );
263 }
264  
265 sub hashref_integer_typetest1 {
266 { my hashref::integer $RETURN_TYPE };
267 ( my integer $my_size) = @ARG;
268  
269 # integer_CHECK($my_size);
270 integer_CHECKTRACE( $my_size, '$my_size',
271 'hashref_integer_typetest1()' );
272 my hashref::integer $new_hash = {};
273 my string $temp_key;
274 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
275 $temp_key = 'PERLOPS_PERLTYPES_funkey' . $i;
276 $new_hash->{$temp_key} = $i * 5;
277  
278 # Perl::diag("in PERLOPS_PERLTYPES hashref_integer_typetest1(), setting entry '$temp_key' => " . $new_hash->{$temp_key} . ", BARSTOOL\n");
279 }
280 return ($new_hash);
281 }
282  
283 # [[[ HASH REF NUMBER ]]]
284 # [[[ HASH REF NUMBER ]]]
285 # [[[ HASH REF NUMBER ]]]
286  
287 # (ref to hash) of numbers
288 package hashref::number;
289 use strict;
290 use warnings;
291 use parent -norequire, qw(hashref);
292 use Carp;
293  
294 # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
295 package Perl::Structure::Hash::SubTypes1D;
296 use strict;
297 use warnings;
298  
299 # [[[ TYPE-CHECKING ]]]
300  
301 sub hashref_number_CHECK {
302 { my void $RETURN_TYPE };
303 ( my $possible_hashref_number ) = @ARG;
304  
305 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECK() subroutine, but with number-specific error codes
306 if ( not( defined $possible_hashref_number ) ) {
307 croak( "\nERROR EHVRVNV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::number value expected but undefined/null value found,\ncroaking" );
308 }
309  
310 if ( not( main::PerlTypes_SvHROKp($possible_hashref_number) ) ) {
311 croak( "\nERROR EHVRVNV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::number value expected but non-hashref value found,\ncroaking" );
312 }
313  
314 my number $possible_number;
315 foreach my string $key ( sort keys %{$possible_hashref_number} ) {
316 $possible_number = $possible_hashref_number->{$key};
317  
318 # DEV NOTE: the following two if() statements are functionally equivalent to the number_CHECK() subroutine, but with hash-specific error codes
319 if ( not( defined $possible_number ) ) {
320 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
321 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
322 croak( "\nERROR EHVRVNV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber value expected but undefined/null value found at key '$key',\ncroaking" );
323 }
324 if (not( main::PerlTypes_SvNOKp($possible_number)
325 || main::PerlTypes_SvIOKp($possible_number) )
326 )
327 {
328 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
329 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
330 croak( "\nERROR EHVRVNV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber value expected but non-number value found at key '$key',\ncroaking" );
331 }
332 }
333 return;
334 }
335  
336 sub hashref_number_CHECKTRACE {
337 { my void $RETURN_TYPE };
338 ( my $possible_hashref_number, my $variable_name, my $subroutine_name )
339 = @ARG;
340  
341 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECKTRACE() subroutine, but with number-specific error codes
342 if ( not( defined $possible_hashref_number ) ) {
343 croak( "\nERROR EHVRVNV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::number value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
344 }
345  
346 if ( not( main::PerlTypes_SvHROKp($possible_hashref_number) ) ) {
347 croak( "\nERROR EHVRVNV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::number value expected but non-hashref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
348 }
349  
350 my number $possible_number;
351 foreach my string $key ( sort keys %{$possible_hashref_number} ) {
352 $possible_number = $possible_hashref_number->{$key};
353  
354 # DEV NOTE: the following two if() statements are functionally equivalent to the number_CHECKTRACE() subroutine, but with hash-specific error codes
355 if ( not( defined $possible_number ) ) {
356 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
357 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
358 croak( "\nERROR EHVRVNV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber value expected but undefined/null value found at key '$key',\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
359 }
360 if (not( main::PerlTypes_SvNOKp($possible_number)
361 || main::PerlTypes_SvIOKp($possible_number) )
362 )
363 {
364 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
365 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
366 croak( "\nERROR EHVRVNV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nnumber value expected but non-number value found at key '$key',\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
367 }
368 }
369 return;
370 }
371  
372 # [[[ STRINGIFY ]]]
373  
374 # DEV NOTE: 1-D format levels are 1 less than 2-D format levels
375  
376 # call actual stringify routine, format level -2 (compact), indent level 0
377 sub hashref_number_to_string_compact {
378 { my string $RETURN_TYPE };
379 ( my $input_hvref ) = @ARG;
380 return hashref_number_to_string_format($input_hvref, -2, 0);
381 }
382  
383 # call actual stringify routine, format level -1 (normal), indent level 0, DEFAULT
384 sub hashref_number_to_string {
385 { my string $RETURN_TYPE };
386 ( my $input_hvref ) = @ARG;
387 return hashref_number_to_string_format($input_hvref, -1, 0);
388 }
389  
390 # call actual stringify routine, format level 0 (pretty), indent level 0
391 sub hashref_number_to_string_pretty {
392 { my string $RETURN_TYPE };
393 ( my $input_hvref ) = @ARG;
394 return hashref_number_to_string_format($input_hvref, 0, 0);
395 }
396  
397 # call actual stringify routine, format level 1 (expand), indent level 0
398 sub hashref_number_to_string_expand {
399 { my string $RETURN_TYPE };
400 ( my $input_hvref ) = @ARG;
401 return hashref_number_to_string_format($input_hvref, 1, 0);
402 }
403  
404 # convert from (Perl SV containing RV to (Perl HV of (Perl SVs containing NVs))) to Perl-parsable (Perl SV containing PV)
405 sub hashref_number_to_string_format {
406 { my string $RETURN_TYPE };
407 ( my $input_hvref, my integer $format_level, my integer $indent_level ) = @ARG;
408  
409 # Perl::diag("in PERLOPS_PERLTYPES hashref_number_to_string_format(), top of subroutine\n");
410  
411 # hashref_number_CHECK($input_hvref);
412 hashref_number_CHECKTRACE( $input_hvref, '$input_hvref', 'hashref_number_to_string()' );
413  
414 # declare local variables, av & sv mean "array value" & "scalar value" as used in Perl core
415 my %input_hv;
416 # my integer $input_hv__length;
417 my number $input_hv__entry_value;
418 my string $output_sv = q{};
419 my boolean $i_is_0 = 1;
420  
421 # dereference input hash reference
422 %input_hv = %{$input_hvref};
423  
424 # generate indent
425 my string $indent = q{ } x $indent_level;
426  
427 # compute length of (number of keys in) input hash
428 # $input_hv__length = scalar keys %input_hv;
429 # Perl::diag("in PERLOPS_PERLTYPES hashref_number_to_string_format(), have \$input_hv__length = $input_hv__length\n");
430  
431 # pre-begin with optional indent, depending on format level
432 if ($format_level >= 1) { $output_sv .= $indent; }
433  
434 # begin output string with left-curly-brace, as required for all RPerl hashes
435 $output_sv .= '{';
436  
437 # loop through all hash keys
438 foreach my string $key ( sort keys %input_hv ) {
439 # retrieve input hash's entry value at key
440 $input_hv__entry_value = $input_hv{$key};
441  
442 # DEV NOTE: number type-checking already done as part of hashref_number_CHECKTRACE()
443 # number_CHECK($input_hv__entry_value);
444 # number_CHECKTRACE( $input_hv__entry_value, "\$input_hv__entry_value at key '$key'", 'hashref_number_to_string()' );
445  
446 # append comma to output string for all elements except index 0
447 if ($i_is_0) { $i_is_0 = 0; }
448 else { $output_sv .= ','; }
449  
450 # append newline-indent-tab or space, depending on format level
451 if ($format_level >= 1) { $output_sv .= "\n" . $indent . q{ }; }
452 elsif ($format_level >= -1) { $output_sv .= q{ }; }
453  
454 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
455 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
456  
457 # DEV NOTE: emulate Data::Dumper & follow PBP by using single quotes for key strings
458 $output_sv .= q{'} . $key. q{'};
459  
460 # append spaces before and after fat arrow AKA fat comma, depending on format level
461 if ($format_level >= -1) { $output_sv .= ' => '; }
462 else { $output_sv .= '=>'; }
463  
464 # $output_sv .= $input_hv__entry_value; # NO UNDERSCORES
465 $output_sv .= Perl::Type::Number::number_to_string($input_hv__entry_value); # YES UNDERSCORES
466 }
467  
468 # append newline-indent or space, depending on format level
469 if ($format_level >= 1) { $output_sv .= "\n" . $indent; }
470 elsif ($format_level >= -1) { $output_sv .= q{ }; }
471  
472 # end output string with right-curly-brace, as required for all RPerl hashes
473 $output_sv .= '}';
474  
475 # Perl::diag("in PERLOPS_PERLTYPES hashref_number_to_string_format(), after for() loop, have \$output_sv =\n$output_sv\n");
476 # Perl::diag("in PERLOPS_PERLTYPES hashref_number_to_string_format(), bottom of subroutine\n");
477 return ($output_sv);
478 }
479  
480 # [[[ TYPE TESTING ]]]
481  
482 sub hashref_number_typetest0 {
483 { my string $RETURN_TYPE };
484 ( my hashref::number $lucky_numbers) = @ARG;
485  
486 # hashref_number_CHECK($lucky_numbers);
487 hashref_number_CHECKTRACE( $lucky_numbers, '$lucky_numbers',
488 'hashref_number_typetest0()' );
489  
490 # foreach my string $key ( sort keys %{$lucky_numbers} ) {
491 # my $lucky_number = $lucky_numbers->{$key};
492 # $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
493 # $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
494 # Perl::diag("in PERLOPS_PERLTYPES hashref_number_typetest0(), have lucky number '$key' => " . $lucky_number . ", BARSTOOL\n");
495 # }
496 return (
497 hashref_number_to_string($lucky_numbers) . 'PERLOPS_PERLTYPES' );
498 }
499  
500 sub hashref_number_typetest1 {
501 { my hashref::number $RETURN_TYPE };
502 ( my integer $my_size) = @ARG;
503  
504 # integer_CHECK($my_size);
505 integer_CHECKTRACE( $my_size, '$my_size',
506 'hashref_number_typetest1()' );
507 my hashref::number $new_hash = {};
508 my string $temp_key;
509 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
510 $temp_key = 'PERLOPS_PERLTYPES_funkey' . $i;
511 $new_hash->{$temp_key} = $i * 5.123456789;
512  
513 # Perl::diag("in PERLOPS_PERLTYPES hashref_number_typetest1(), setting entry '$temp_key' => " . $new_hash->{$temp_key} . ", BARSTOOL\n");
514 }
515 return ($new_hash);
516 }
517  
518 # [[[ HASH REF CHARACTER ]]]
519 # [[[ HASH REF CHARACTER ]]]
520 # [[[ HASH REF CHARACTER ]]]
521  
522 # (ref to hash) of chars
523 package hashref::character;
524 use strict;
525 use warnings;
526 use parent -norequire, qw(hashref);
527  
528 # [[[ HASH REF STRING ]]]
529 # [[[ HASH REF STRING ]]]
530 # [[[ HASH REF STRING ]]]
531  
532 # (ref to hash) of strings
533 package hashref::string;
534 use strict;
535 use warnings;
536 use parent -norequire, qw(hashref);
537 use Carp;
538  
539 # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]]
540 package Perl::Structure::Hash::SubTypes1D;
541 use strict;
542 use warnings;
543  
544 # [[[ TYPE-CHECKING ]]]
545  
546 sub hashref_string_CHECK {
547 { my void $RETURN_TYPE };
548 ( my $possible_hashref_string ) = @ARG;
549  
550 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECK() subroutine, but with string-specific error codes
551 if ( not( defined $possible_hashref_string ) ) {
552 croak( "\nERROR EHVRVPV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::string value expected but undefined/null value found,\ncroaking" );
553 }
554  
555 if ( not( main::PerlTypes_SvHROKp($possible_hashref_string) ) ) {
556 croak( "\nERROR EHVRVPV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::string value expected but non-hashref value found,\ncroaking" );
557 }
558  
559 my string $possible_string;
560 foreach my string $key ( sort keys %{$possible_hashref_string} ) {
561 $possible_string = $possible_hashref_string->{$key};
562  
563 # DEV NOTE: the following two if() statements are functionally equivalent to the string_CHECK() subroutine, but with hash-specific error codes
564 if ( not( defined $possible_string ) ) {
565 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
566 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
567 croak( "\nERROR EHVRVPV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but undefined/null value found at key '$key',\ncroaking" );
568 }
569 if ( not( main::PerlTypes_SvPOKp($possible_string) ) ) {
570 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
571 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
572 croak( "\nERROR EHVRVPV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but non-string value found at key '$key',\ncroaking" );
573 }
574 }
575 return;
576 }
577  
578 sub hashref_string_CHECKTRACE {
579 { my void $RETURN_TYPE };
580 ( my $possible_hashref_string, my $variable_name, my $subroutine_name )
581 = @ARG;
582  
583 # DEV NOTE: the following two if() statements are functionally equivalent to the hashref_CHECKTRACE() subroutine, but with string-specific error codes
584 if ( not( defined $possible_hashref_string ) ) {
585 croak( "\nERROR EHVRVPV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::string value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
586 }
587  
588 if ( not( main::PerlTypes_SvHROKp($possible_hashref_string) ) ) {
589 croak( "\nERROR EHVRVPV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nhashref::string value expected but non-hashref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
590 }
591  
592 my string $possible_string;
593 foreach my string $key ( sort keys %{$possible_hashref_string} ) {
594 $possible_string = $possible_hashref_string->{$key};
595  
596 # DEV NOTE: the following two if() statements are functionally equivalent to the string_CHECKTRACE() subroutine, but with hash-specific error codes
597 if ( not( defined $possible_string ) ) {
598 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
599 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
600 croak( "\nERROR EHVRVPV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but undefined/null value found at key '$key',\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
601 }
602 if ( not( main::PerlTypes_SvPOKp($possible_string) ) ) {
603 $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
604 $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
605 croak( "\nERROR EHVRVPV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but non-string value found at key '$key',\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" );
606 }
607 }
608 return;
609 }
610  
611 # [[[ STRINGIFY ]]]
612  
613 # DEV NOTE: 1-D format levels are 1 less than 2-D format levels
614  
615 # call actual stringify routine, format level -2 (compact), indent level 0
616 sub hashref_string_to_string_compact {
617 { my string $RETURN_TYPE };
618 ( my $input_hvref ) = @ARG;
619 return hashref_string_to_string_format($input_hvref, -2, 0);
620 }
621  
622 # call actual stringify routine, format level -1 (normal), indent level 0, DEFAULT
623 sub hashref_string_to_string {
624 { my string $RETURN_TYPE };
625 ( my $input_hvref ) = @ARG;
626 return hashref_string_to_string_format($input_hvref, -1, 0);
627 }
628  
629 # call actual stringify routine, format level 0 (pretty), indent level 0
630 sub hashref_string_to_string_pretty {
631 { my string $RETURN_TYPE };
632 ( my $input_hvref ) = @ARG;
633 return hashref_string_to_string_format($input_hvref, 0, 0);
634 }
635  
636 # call actual stringify routine, format level 1 (expand), indent level 0
637 sub hashref_string_to_string_expand {
638 { my string $RETURN_TYPE };
639 ( my $input_hvref ) = @ARG;
640 return hashref_string_to_string_format($input_hvref, 1, 0);
641 }
642  
643 # convert from (Perl SV containing RV to (Perl HV of (Perl SVs containing PVs))) to Perl-parsable (Perl SV containing PV)
644 sub hashref_string_to_string_format {
645 { my string $RETURN_TYPE };
646 ( my $input_hvref, my integer $format_level, my integer $indent_level ) = @ARG;
647  
648 # Perl::diag("in PERLOPS_PERLTYPES hashref_string_to_string_format(), top of subroutine\n");
649  
650 # hashref_string_CHECK($input_hvref);
651 hashref_string_CHECKTRACE( $input_hvref, '$input_hvref', 'hashref_string_to_string()' );
652  
653 # declare local variables, av & sv mean "array value" & "scalar value" as used in Perl core
654 my %input_hv;
655 # my integer $input_hv__length;
656 my string $input_hv__entry_value;
657 my string $output_sv = q{};
658 my boolean $i_is_0 = 1;
659  
660 # dereference input hash reference
661 %input_hv = %{$input_hvref};
662  
663 # generate indent
664 my string $indent = q{ } x $indent_level;
665  
666 # compute length of (number of keys in) input hash
667 # $input_hv__length = scalar keys %input_hv;
668 # Perl::diag("in PERLOPS_PERLTYPES hashref_string_to_string_format(), have \$input_hv__length = $input_hv__length\n");
669  
670 # pre-begin with optional indent, depending on format level
671 if ($format_level >= 1) { $output_sv .= $indent; }
672  
673 # begin output string with left-curly-brace, as required for all RPerl hashes
674 $output_sv .= '{';
675  
676 # loop through all hash keys
677 foreach my string $key ( sort keys %input_hv ) {
678 # retrieve input hash's entry value at key
679 $input_hv__entry_value = $input_hv{$key};
680  
681 # DEV NOTE: string type-checking already done as part of hashref_string_CHECKTRACE()
682 # string_CHECK($input_hv__entry_value);
683 # string_CHECKTRACE( $input_hv__entry_value, "\$input_hv__entry_value at key '$key'", 'hashref_string_to_string()' );
684  
685 # append comma to output string for all elements except index 0
686 if ($i_is_0) { $i_is_0 = 0; }
687 else { $output_sv .= ','; }
688  
689 # append newline-indent-tab or space, depending on format level
690 if ($format_level >= 1) { $output_sv .= "\n" . $indent . q{ }; }
691 elsif ($format_level >= -1) { $output_sv .= q{ }; }
692  
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  
696 # DEV NOTE: emulate Data::Dumper & follow PBP by using single quotes for key strings
697 $output_sv .= q{'} . $key. q{'};
698  
699 # append spaces before and after fat arrow AKA fat comma, depending on format level
700 if ($format_level >= -1) { $output_sv .= ' => '; }
701 else { $output_sv .= '=>'; }
702  
703 $input_hv__entry_value =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
704 $input_hv__entry_value =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
705 $output_sv .= q{'} . $input_hv__entry_value . q{'};
706 }
707  
708 # append newline-indent or space, depending on format level
709 if ($format_level >= 1) { $output_sv .= "\n" . $indent; }
710 elsif ($format_level >= -1) { $output_sv .= q{ }; }
711  
712 # end output string with right-curly-brace, as required for all RPerl hashes
713 $output_sv .= '}';
714  
715 # Perl::diag("in PERLOPS_PERLTYPES hashref_string_to_string_format(), after for() loop, have \$output_sv =\n$output_sv\n");
716 # Perl::diag("in PERLOPS_PERLTYPES hashref_string_to_string_format(), bottom of subroutine\n");
717 return ($output_sv);
718 }
719  
720 # [[[ TYPE TESTING ]]]
721  
722 sub hashref_string_typetest0 {
723 { my string $RETURN_TYPE };
724 ( my hashref::string $people) = @ARG;
725  
726 # hashref_string_CHECK($lucky_numbers);
727 hashref_string_CHECKTRACE( $people, '$people',
728 'hashref_string_typetest0()' );
729  
730 # foreach my string $key ( sort keys %{$people} ) {
731 # my $person = $people->{$key};
732 # $key =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character
733 # $key =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character
734 # Perl::diag("in PERLOPS_PERLTYPES hashref_string_typetest0(), have person '$key' => '" . $person . "', STARBOOL\n");
735 # }
736 return ( hashref_string_to_string($people) . 'PERLOPS_PERLTYPES' );
737 }
738  
739 sub hashref_string_typetest1 {
740 { my hashref::string $RETURN_TYPE };
741 ( my integer $my_size) = @ARG;
742  
743 # integer_CHECK($my_size);
744 integer_CHECKTRACE( $my_size, '$my_size',
745 'hashref_string_typetest1()' );
746 my hashref::string $people = {};
747 for my integer $i ( 0 .. ( $my_size - 1 ) ) {
748 $people->{ 'PERLOPS_PERLTYPES_Luker_key' . $i }
749 = q{Jeffy Ten! } . $i . q{/} . ( $my_size - 1 );
750  
751 # Perl::diag("in PERLOPS_PERLTYPES hashref_string_typetest1(), bottom of for() loop, have i = $i, just set another Jeffy!\n");
752 }
753 return ($people);
754 }
755  
756 # [[[ HASH REF SCALAR ]]]
757 # [[[ HASH REF SCALAR ]]]
758 # [[[ HASH REF SCALAR ]]]
759  
760 # (ref to hash) of scalartypes
761 package hashref::scalartype;
762 use strict;
763 use warnings;
764 use parent -norequire, qw(hashref);
765  
766 1; # end of package