1Devel::Dwarn(3)       User Contributed Perl Documentation      Devel::Dwarn(3)
2
3
4

NAME

6       Devel::Dwarn - Combine warns and Data::Dumper::Concise
7

SYNOPSIS

9         use Devel::Dwarn;
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 Devel::Dwarn;
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 Devel::Dwarn;
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 Devel::Dwarn;
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 immediately die after outputting the data structure,
81       every Dwarn subroutine has a paired Ddie version, so just replace the
82       warn with die.  For example:
83
84        DdieL 'foo', { bar => 'baz' };
85

TIPS AND TRICKS

87   global usage
88       Instead of always just doing:
89
90         use Devel::Dwarn;
91
92         Dwarn ...
93
94       We tend to do:
95
96         perl -MDevel::Dwarn foo.pl
97
98       (and then in the perl code:)
99
100         ::Dwarn ...
101
102       That way, if you leave them in and run without the "use Devel::Dwarn"
103       the program will fail to compile and you are less likely to check it in
104       by accident.  Furthmore it allows that much less friction to add debug
105       messages.
106
107   method chaining
108       One trick which is useful when doing method chaining is the following:
109
110         my $foo = Bar->new;
111         $foo->bar->baz->Devel::Dwarn::DwarnS->biff;
112
113       which is the same as:
114
115         my $foo = Bar->new;
116         (DwarnS $foo->bar->baz)->biff;
117

SEE ALSO

119       This module is really just a shortcut for Data::Dumper::Concise::Sugar,
120       check it out for more complete documentation.
121
122
123
124perl v5.38.0                      2023-07-20                   Devel::Dwarn(3)
Impressum