1Data::Dumper::Concise::USsuegrarC(o3n)tributed Perl DocuDmaetnat:a:tDiuomnper::Concise::Sugar(3)
2
3
4

NAME

6       Data::Dumper::Concise::Sugar - return Dwarn @return_value
7

SYNOPSIS

9         use Data::Dumper::Concise::Sugar;
10
11         return Dwarn some_call(...)
12
13       is equivalent to:
14
15         use Data::Dumper::Concise;
16
17         if (wantarray) {
18            my @return = some_call(...);
19            warn Dumper(@return);
20            return @return;
21         } else {
22            my $return = some_call(...);
23            warn Dumper($return);
24            return $return;
25         }
26
27       but shorter. If you need to force scalar context on the value,
28
29         use Data::Dumper::Concise::Sugar;
30
31         return DwarnS some_call(...)
32
33       is equivalent to:
34
35         use Data::Dumper::Concise;
36
37         my $return = some_call(...);
38         warn Dumper($return);
39         return $return;
40
41       If you need to force list context on the value,
42
43         use Data::Dumper::Concise::Sugar;
44
45         return DwarnL some_call(...)
46
47       is equivalent to:
48
49         use Data::Dumper::Concise;
50
51         my @return = some_call(...);
52         warn Dumper(@return);
53         return @return;
54
55       If you want to label your output, try DwarnN
56
57         use Data::Dumper::Concise::Sugar;
58
59         return DwarnN $foo
60
61       is equivalent to:
62
63         use Data::Dumper::Concise;
64
65         my @return = some_call(...);
66         warn '$foo => ' . Dumper(@return);
67         return @return;
68
69       If you want to output a reference returned by a method easily, try
70       $Dwarn
71
72        $foo->bar->{baz}->$Dwarn
73
74       is equivalent to:
75
76         my $return = $foo->bar->{baz};
77         warn Dumper($return);
78         return $return;
79
80       If you want to format the output of your data structures, try DwarnF
81
82        my ($a, $c) = DwarnF { "awesome: $_[0] not awesome: $_[1]" } $awesome, $cheesy;
83
84       is equivalent to:
85
86         my @return = ($awesome, $cheesy);
87         warn DumperF { "awesome: $_[0] not awesome: $_[1]" } $awesome, $cheesy;
88         return @return;
89
90       If you want to immediately die after outputting the data structure,
91       every Dwarn subroutine has a paired Ddie version, so just replace the
92       warn with die.  For example:
93
94        DdieL 'foo', { bar => 'baz' };
95

DESCRIPTION

97         use Data::Dumper::Concise::Sugar;
98
99       will import Dwarn, $Dwarn, DwarnL, DwarnN, and DwarnS into your
100       namespace. Using Exporter, so see its docs for ways to make it do
101       something else.
102
103   Dwarn
104         sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
105
106   $Dwarn
107         $Dwarn = \&Dwarn
108
109   $DwarnN
110         $DwarnN = \&DwarnN
111
112   DwarnL
113         sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
114
115   DwarnS
116         sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
117
118   DwarnN
119         sub DwarnN { warn '$argname => ' . Data::Dumper::Concise::Dumper $_[0]; $_[0] }
120
121       Note: this requires Devel::ArgNames to be installed.
122
123   DwarnF
124         sub DwarnF (&@) { my $c = shift; warn &Data::Dumper::Concise::DumperF($c, @_); @_ }
125

TIPS AND TRICKS

127   global usage
128       Instead of always just doing:
129
130         use Data::Dumper::Concise::Sugar;
131
132         Dwarn ...
133
134       We tend to do:
135
136         perl -MData::Dumper::Concise::Sugar foo.pl
137
138       (and then in the perl code:)
139
140         ::Dwarn ...
141
142       That way, if you leave them in and run without the "use
143       Data::Dumper::Concise::Sugar" the program will fail to compile and you
144       are less likely to check it in by accident.  Furthmore it allows that
145       much less friction to add debug messages.
146
147   method chaining
148       One trick which is useful when doing method chaining is the following:
149
150         my $foo = Bar->new;
151         $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
152
153       which is the same as:
154
155         my $foo = Bar->new;
156         (DwarnS $foo->bar->baz)->biff;
157

SEE ALSO

159       You probably want Devel::Dwarn, it's the shorter name for this module.
160
161
162
163perl v5.36.0                      2023-01-20   Data::Dumper::Concise::Sugar(3)
Impressum