1 package Data::Dumper::Concise::Sugar;
6 use Data::Dumper::Concise ();
8 BEGIN { @ISA = qw(Exporter) }
10 @EXPORT = qw(Dwarn DwarnS Dwarn_only DwarnS_only);
13 sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
15 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
19 warn Data::Dumper::Concise::Dumper $only->(@_);
23 sub DwarnS_only (&$) {
25 warn Data::Dumper::Concise::Dumper do { local $_ = $_[0]; $only->($_[0]) };
31 Data::Dumper::Concise::Sugar - return Dwarn @return_value
35 use Data::Dumper::Concise::Sugar;
37 return Dwarn some_call(...)
41 use Data::Dumper::Concise;
43 my @return = some_call(...);
47 but shorter. If you need to force scalar context on the value,
49 use Data::Dumper::Concise::Sugar;
51 return DwarnS some_call(...)
55 use Data::Dumper::Concise;
57 my $return = some_call(...);
61 Sometimes you'll want to C<Dwarn> out part of a result, instead of the entire
62 thing; for that we have C<Dwarn_only>:
64 # Dwarn the TO_JSON of all the objects in the list
65 my @results = Dwarn_only { map $_->TO_JSON, @_ } some_call(...);
69 # only Dwarn the first item
70 my $data = DwarnS_only { $_->[0] } [ some_call(...) ];
72 Another trick that is extremely useful when doing method chaining is the
76 $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
81 (DwarnS $foo->bar->baz)->biff;
85 use Data::Dumper::Concise::Sugar;
87 will import Dwarn and DwarnS into your namespace. Using L<Exporter>, so see
88 its docs for ways to make it do something else.
92 sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
96 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
100 sub Dwarn_only (&@) {
102 warn Data::Dumper::Concise::Dumper $only->(@_);
108 sub DwarnS_only (&$) {
110 warn Data::Dumper::Concise::Dumper do { local $_ = $_[0]; $only->($_[0]) };
116 You probably want L<Devel::Dwarn>, it's the shorter name for this module.