D module - encodes data and dumps to standard error

The D module provides utility functions that encode data and dump it to standard error output.

Usage example

The D module is used as follows.

use utf8;
 
# export the du, dw, dn, dustr, dwstr, dnstr functions
use D;
 
# Prepare the data (reference) including the decoded string
my $data = [{name =>'a'}, {name =>'i'}];
 
# Encode the reference data (UTF-8) and dump it to standard error output.
du $data;

# Encode the reference data (cp932) and dump it to standard error output.
dw $data;

# Dump to standard error without encoding reference data.
dn $data;

# A handy Oneliner example.
use D; du $data;
use D; dw $data;
use D; dn $data;

# This is an output example of the du function.
[
  {
    'name' =>'ah'
  },
  {
    'name' =>'I'
  }
] at test.pl line 7.

Features

  • Export functions such as du, dw, dn. These function names are two characters and should not conflict with debug commands such as'p'.
  • The

  • dustr and dwstr functions encode all strings in the reference data.
  • du is an abbreviation for'dump UTF-8'.
  • dw is an abbreviation for'dump Windows cp932'.
  • dn is an abbreviation for'dump no encoding'.
  • Data::Dump the data using Dumper's Dump function.
  • Outputs the line number and file name to the standard error.
  • Sort by hash key of dumped data.
  • Unlike the default of Data::Dumper, it does not output'$VAR1 = '.

Function

du function

Encodes all strings in the reference data to UTF-8 and dumps the reference data to standard error along with the filename and line number.

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

This function will be exported.

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

The example below uses a one-liner. It can be used with all functions.

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

dw function

Encodes all strings in the reference data to cp932 and dumps the reference data along with the filename and line number to standard error output.

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

This function will be exported.

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

dn function

It does not encode all the strings in the reference data and dumps the reference data along with the file name and line number to the standard error output.

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

This function will be exported.

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

duster function

This function returns a UTF-8 encoded string.

This function will be exported.

The following example gets a UTF-8 encoded string.

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

dwstr function

This function returns a cp932 encoded string.

This function will be exported.

The following example is getting a cp932 encoded string.

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

dnstr function

This function returns a string without encoding.

This function will be exported.

The following example is getting an unencoded string.

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

Bug report

https://github.com/YoshiyukiItoh/D

Related items

Original page (meta::cpan)

https://metacpan.org/pod/D

Related Informatrion