++ed by:
1 non-PAUSE user
Author image Yoshiyuki Ito
and 1 contributors

NAME

D - Provides utility functions to encode data and dump it to STDERR.

SYNOPSIS

  use utf8;
  
  # Export du, dw, de, dn, dustr, dwstr, destr, dnstr functions
  use D;
  
  # Reference data that contains decoded strings
  my $data = [{name => 'あ'}, {name => 'い'}];
  
  # Encode all strings in reference data to UTF-8 and dump the reference data to STDERR.
  du $data;

  # Encode all strings in reference data to cp932 and dump the reference data to STDERR.
  dw $data;

  # Encode all strings in reference data to EUC-JP and dump the reference data to STDERR.
  de $data;

  # Dump reference data to STDERR without encoding.
  dn $data;

  # Examples of useful oneliner.
  use D;du $data;
  use D;dw $data;
  use D;de $data;
  use D;dn $data;

  # Output example of du function.
  [
    {
      'name' => 'あ'
    },
    {
      'name' => 'い'
    }
  ] at test.pl line 7.

DESCRIPTION

D module provides utility functions to encode data and dump it to STDERR.

FEATURES

  • Export du, dw, de, and dn functions. Don't conflict debug command such as 'p' because these function names are consist of two characters.

  • Encode all strings in reference data in dustr, dwstr, and destr function.

  • du is a short name of "dump UTF-8"

  • dw is a short name of "dump Windows cp932"

  • de is a short name of "dump EUC-JP"

  • dn is a short name of "dump no encoding"

  • Use Dump method of Data::Dumper to dump data

  • Print line number and file name to STDERR

  • Keys of hash of dumped data is sorted.

  • Don't print "$VAR1 =" unlike Data::Dumper default.

FUNCTIONS

du

Encode all strings in reference data to UTF-8 and return string the reference data with file name and line number.

If the argument is not reference data such as a string, it is also dumped in the same way as reference data.

This function is exported.

  use D;
  my $data = [{name => 'あ'}, {name => 'い'}];
  du $data;

Following example is oneliner used. It can be used all functions.

  my $data = [{name => 'あ'}, {name => 'い'}];
  use D;du $data;

dw

Encode all strings in reference data to cp932 and dump the reference data to STDERR with file name and line number.

If the argument is not reference data such as a string, it is also dumped in the same way as reference data.

This function is exported.

  use D;
  my $data = [{name => 'あ'}, {name => 'い'}];
  dw $data;

de

Encode all strings in reference data to EUC-JP and dump the reference data to STDERR with file name and line number.

If the argument is not reference data such as a string, it is also dumped in the same way as reference data.

This function is exported.

  use D;
  my $data = [{name => 'あ'}, {name => 'い'}];
  de $data;

dn

Dump reference data to STDERR without encoding with file name and line number.

If the argument is not reference data such as a string, it is also dumped in the same way as reference data.

This function is exported.

  use D;
  my $data = [{name => 'あ'}, {name => 'い'}];
  dn $data;

dustr

This function is return that UTF-8 encoded string.

This function is exported.

Following example is get the UTF-8 encoded string.

  use D;
  my $data = [{name => 'あ'}, {name => 'い'}];
  my $str = dustr $data;

dwstr

This function is return that cp932 encoded string.

This function is exported.

Following example is get the cp932 encoded string.

  use D;
  my $data = [{name => 'あ'}, {name => 'い'}];
  my $str = dwstr $data;

destr

This function is return that EUC-JP encoded string.

This function is exported.

Following example is get the EUC-JP encoded string.

  use D;
  my $data = [{name => 'あ'}, {name => 'い'}];
  my $str = destr $data;

dnstr

This function is return that without encoded string.

This function is exported.

Following example is get the without encoded string.

  use D;
  my $data = [{name => 'あ'}, {name => 'い'}];
  my $str = dnstr $data;

Bug Report

https://github.com/YoshiyukiItoh/D

SEE ALSO

Data::Dumper, Carp, Data::Recursive::Encode

AUTHOR

Yoshiyuki Ito, <yoshiyuki.ito.biz@gmail.com>

Yuki Kimoto, <kimoto.yuki@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2019 by Yoshiyuki Ito, Yuki Kimoto

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.08.7 or, at your option, any later version of Perl 5 you may have available.