blib/lib/Acme/CPANModules/DumpingDataForDebugging.pm

filter: Statementstmt 100% 6 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 6 / 6 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary
1 package Acme::CPANModules::DumpingDataForDebugging;
2  
3 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4 1 our $DATE = '2020-02-07'; # DATE
5 1 our $DIST = 'Acme-CPANModules-DumpingDataForDebugging'; # DIST
6 1 our $VERSION = '0.001'; # VERSION
7  
8 1 our $LIST = {
9 summary => 'Some modules and tips when dumping data structures for debugging',
10 description => <<'_',
11  
12 This list catalogs some of the modules you can you to dump your data structures
13 for debugging purposes, so the modules will be judged mostly by the
14 appropriateness of its output for human viewing (instead of other criteria like
15 speed, footprint, etc).
16  
17 _
18 entries => [
19 {
20 module=>'Data::Dumper',
21 tags => ['perl'],
22 description => <<'_',
23  
24 Everybody knows this module and it's core so sometimes it's the only appropriate
25 choice. However, the default setting is not really optimized for viewing by
26 human. I suggest you tweak these before dumping your data:
27  
28 * Set $Data::Dumper::Useqq to 1.
29  
30 By default, <pm:Data::Dumper> quotes strings using single-quotes and does not
31 quote things like "\n" and "\b" making it difficult to spot special characters.
32  
33  
34 _
35 },
36  
37 {
38 module=>'Data::Dump',
39 tags => ['perl'],
40 description => <<'_',
41  
42 A data dumper that produces nicer Perl code output, with features like vertical
43 alignment of "=>" when dumping hashes, compacting sequences like 1,2,3,4,5,6 to
44 1..6, compacting repeating characters in string like "ccccccccccccccccccccc" to
45 ("c" x 21), and so on.
46  
47 It tries harder to produce Perl code that generates the original data structure,
48 particularly with circular references. But with interlinked references like
49 trees, Data::Dumper might be more helpful in showing you which references get
50 mentioned where. For example this data:
51  
52 $tree = {children=>[{children=>[{}]}, {children=>[]}]};
53 $tree->{children}[0]{parent}=$tree;
54 $tree->{children}[1]{parent}=$tree;
55 $tree->{children}[0]{children}[0]{parent} = $tree->{children}[0];
56  
57 Data::Dump will produce:
58  
59 do {
60 my $a = {
61 children => [
62 { children => [{ parent => 'fix' }], parent => 'fix' },
63 { children => [], parent => 'fix' },
64 ],
65 };
66 $a->{children}[0]{children}[0]{parent} = $a->{children}[0];
67 $a->{children}[0]{parent} = $a;
68 $a->{children}[1]{parent} = $a;
69 $a;
70 }
71  
72 while Data::Dumper will produce:
73  
74 $VAR1 = {
75 'children' => [
76 {
77 'children' => [
78 {
79 'parent' => $VAR1->{'children'}[0]
80 }
81 ],
82 'parent' => $VAR1
83 },
84 {
85 'parent' => $VAR1,
86 'children' => []
87 }
88 ]
89 };
90  
91 _
92 },
93  
94 {
95 module=>'Data::Dump::Color',
96 tags => ['perl'],
97 description => <<'_',
98  
99 A modification to Data::Dump which adds color (and color theme) support, as well
100 as other visual aids like depth and array index/hash pair count indicator. It's
101 usually my go-to module for debugging.
102  
103 _
104 },
105  
106 {
107 module=>'Data::Dumper::Compact',
108 tags => ['perl'],
109 description => <<'_',
110  
111 A relatively recent module by MSTROUT. I will need to use this more to see if I
112 really like the output, but so far I do.
113  
114 _
115 },
116  
117 {
118 module=>'XXX',
119 tags => ['perl'],
120 description => <<'_',
121  
122 A nice little dumper module from the creator of YAML. Obviously, it uses YAML
123 output by default but it's configurable to dump in other formats. For example:
124  
125 PERL_XXX_DUMPER=Data::Dump::Color
126  
127 It's main selling point is that the dumper function returns the original
128 arguments so the dumping can be done in various places in code, making it more
129 convenient. More (if not all) dumpers should do this too.
130  
131 _
132 },
133  
134 {
135 module=>'Data::Printer',
136 tags => ['perlish'],
137 description => <<'_',
138  
139 Favorites among many Perl programmers, it sports colors, array index indicator,
140 as well as nice object dumper showing methods and inheritance information. It's
141 also very customizable. It uses its own format though, and my preference for
142 dumping is the Perl format (with additional informations/hints as comments) so
143 I've never used it in my daily coding activities. I probably should though.
144  
145 _
146 },
147  
148 {
149 module=>'JSON::Color',
150 tags => ['json'],
151 description => <<'_',
152  
153 JSON is a limited format; it cannot represent many things that Perl supports
154 e.g. globs, circular references, or even ASCII NUL. But if you are working only
155 with JSON-able data, this JSON dumping module adds color output.
156  
157 _
158 },
159  
160 {
161 module=>'YAML::Tiny::Color',
162 tags => ['yaml'],
163 description => <<'_',
164  
165 _
166 },
167 ],
168 };
169  
170 1 1;
171 # ABSTRACT: Some modules and tips when dumping data structures for debugging
172  
173 __END__
↑ Summary