Data-Dumper-Interp
view release on metacpan or search on metacpan
lib/Data/Dumper/Interp.pm view on Meta::CPAN
}
}
sub __condense_strings($) { # edits $_
if (/^"/) {
my $minrep_m1 = $_[0] - 1;
my $singlechar_restr = "[^\\\\${COND_LB}${COND_RB}${COND_MULT}]";
# Special case a string of nul represented as \n\n\n...\00n (n=0..7)
# D::D generates this to avoid ambiguity if a digit follows
s<( (\\([0-7])){$minrep_m1,}\\00\g{-1} )>
< $COND_LB."${2}${COND_MULT}".((length($1)-2)/length($2)).$COND_RB >xge;
# \0 \1 ... if there is no digit following, which makes it ambiguous
s<( (\\\d) \g{-1}{$minrep_m1,} ) (?![0-7]) >
< $COND_LB."${2}${COND_MULT}".(length($1)/length($2)).$COND_RB >xge;
# \x for almost any x besides a digit or \
s<( ($singlechar_restr | \\\D | \\[0-3][0-7][0-7] | \\x\{[^\{\}]+\})
\g{-1}{$minrep_m1,} )
>
< $COND_LB."${2}${COND_MULT}".(length($1)/length($2)).$COND_RB >xge;
}
}
sub __nums_in_hex() {
if (looks_like_number($_)) {
s/^([1-9]\d+)$/ sprintf("%#x", $1) /e; # Leave single-digit numbers as-is
}
}
t/80_random.t view on Meta::CPAN
if ($kind == 0) { $r = int(rand(50)); $r = int($r) if $r > 25; } #number
elsif ($kind == 1) { # bignum
my $subkind = int(rand(1+4));
if ($subkind == 0) { $r = Math::BigInt->new( int(rand(25)) ) }
elsif ($subkind == 1) { $r = Math::BigFloat->new( rand(25) ) }
elsif ($subkind == 2) { $r = Math::BigRat->new(42, 43) }
elsif ($subkind == 3) { $r = Math::BigRat->new(Math::BigInt->new(int(rand(25))), 43) }
}
elsif ($kind == 2) { $r = gen_list(int(rand(25))) }
elsif ($kind == 3) { $r = gen_hash(int(rand(25))) }
elsif ($kind == 4) { $r = \gen_item() }
elsif ($kind == 5) { $r = \\gen_item() }
elsif ($kind == 6) { $r = \\\gen_item() }
elsif ($kind == 7) { $r = "b" x int(rand(1+13)) } # bareword string
elsif ($kind == 8) { $r = " y \N{U+2650} " x int(rand(1+3)) } # complicated string
elsif ($kind == 9) { $r = undef }
elsif ($kind == 10) { $r = "" }
elsif ($kind == 11) { $r = 0 }
elsif ($kind == 12) { $r = \$globalA }
elsif ($kind == 13) { $r = @saved_items ? $saved_items[int rand($#saved_items+1)] : \$globalA } # self-references
else { die }
--$level;
push @saved_items, $r;
( run in 0.324 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )