6 use Fatal qw<open close>;
7 use Text::Balanced qw<extract_bracketed>;
9 open my $hash_t, '<', 't/20-hash.t';
10 open my $array_t, '>', 't/30-array.t';
11 open my $array_fast_t, '>', 't/31-array-fast.t';
14 my ($char) = $_[0] =~ /['"]?([a-z])['"]?/;
15 return ord($char) - ord('a')
20 return $h unless $h and ref $h eq 'HASH';
23 $array[num($_)] = hash2array($h->{$_});
31 return 'undef' unless defined $a;
34 die "Invalid argument" unless ref $a eq 'ARRAY';
35 return '[ ' . join(', ', map dump_array($_), @$a) . ' ]';
37 $a = "'\Q$a\E'" if $a !~ /^\s*\d/;
43 extract_bracketed $_[0], $_[1], qr/.*?(?<![\\@%])(?:\\\\)*(?=$_[1])/
46 sub convert_testcase ($$) {
50 s!(\ba\b)?(\s*)HASH\b!($1 ? 'an': '') . "$2ARRAY"!eg;
52 [\{\[]\s*(['"]?[a-z]['"]?(?:\s*,\s*['"]?[a-z]['"]?)*)\s*[\}\]]
54 '[' . join(', ', map { my $n = num($_); $fast ? $n : "\$N[$n]" }
55 split /\s*,\s*/, $1) . ']'
61 my ($bracket, $prefix);
62 while (do { ($bracket, $suffix, $prefix) = extract($suffix, '{'); $bracket }) {
63 my $array = dump_array(hash2array(eval $bracket));
64 $buf .= $prefix . $array;
78 print $array_fast_t $_;
82 print $array_fast_t $_;
84 print $array_t convert_testcase($_, 0);
85 print $array_fast_t convert_testcase($_, 1);
93 open my $hash_kv_t, '<', 't/22-hash-kv.t';
94 open my $array_kv_t, '>', 't/32-array-kv.t';
97 while (<$hash_kv_t>) {
100 } elsif (!$in_data) {
102 if (/\bplan\s*[\s\(]\s*tests\b/) {
105 $_ = qq($1if ("\$]" >= 5.011) { $_ } else { plan skip_all => 'perl 5.11 required for keys/values \@array' }\n);
108 $_ = convert_testcase($_, 1);
110 print $array_kv_t $_;