Data-Dumper-AutoEncode
view release on metacpan or search on metacpan
lib/Data/Dumper/AutoEncode.pm view on Meta::CPAN
return wantarray ? @retval : $retval[0];
}
sub _exec {
my ($code, $arg) = @_;
if (ref $BEFORE_HOOK eq 'CODE') {
$arg = $BEFORE_HOOK->($arg);
}
my $result = $code->($arg);
if (ref $AFTER_HOOK eq 'CODE') {
return $AFTER_HOOK->($result);
}
return $result;
}
# copied from Data::Recursive::Encode
sub _is_number {
my $value = shift;
return 0 unless defined $value;
my $b_obj = B::svref_2object(\$value);
my $flags = $b_obj->FLAGS;
return $flags & ( B::SVp_IOK | B::SVp_NOK ) && !( $flags & B::SVp_POK ) ? 1 : 0;
}
sub _can_exec {
my ($arg) = @_;
return unless defined($arg);
return if $DO_NOT_PROCESS_NUMERIC_VALUE && _is_number($arg);
return 1 if Encode::is_utf8($arg);
return 1 if !$CHECK_ALREADY_ENCODED && !Encode::is_utf8($arg);
return;
}
1;
__END__
=encoding UTF-8
=head1 NAME
Data::Dumper::AutoEncode - Dump with recursive encoding
=head1 SYNOPSIS
use utf8;
use Data::Dumper::AutoEncode;
eDumper(+{ foo => 'ãã§ã' })
=head1 DESCRIPTION
Data::Dumper::AutoEncode stringifies perl data structures including unicode string to human-readable.
example:
use utf8;
use Data::Dumper;
my $foo = +{ foo => 'ãã§ã' };
print Dumper($foo);
It will dump like this
{ foo => "\x{304a}\x{3067}\x{3093}" }
This is not human-readable.
Data::Dumper::AutoEncode exports `eDumper` function. You can use it.
use utf8;
use Data::Dumper::AutoEncode;
my $foo = +{ foo => 'ãã§ã' };
print eDumper($foo);
# { foo => "ãã§ã" }
Also `Dumper` function is exported from Data::Dumper::AutoEncode. It is same as Data::Dumper::Dumper
=head1 METHOD
By default, both functions B<eDumper> and B<Dumper> will be exported.
=over
=item eDumper(LIST)
Dump with recursive encoding(default: utf8)
If you want to encode other encoding, set encoding to $Data::Dumper::AutoEncode::ENCODING.
$Data::Dumper::AutoEncode::ENCODING = 'CP932';
=item Dumper(LIST)
Same as the C<Dumper> function of L<Data::Dumper>. However, if you specify an import option C<-dumper>, then the C<Dumper> function will work as same as C<eDumper> function. Please see C<IMPORT OPTIONS> section for more details.
=item encode($encoding, $stuff)
Just encode stuff.
=back
=head1 IMPORT OPTIONS
You can specify an import option to override C<Dumper> function.
use Data::Dumper::AutoEncode '-dumper';
It means C<Dumper> function is overrided as same as eDumper.
( run in 0.649 second using v1.01-cache-2.11-cpan-524268b4103 )