add Dwarn_only and DwarnS_only
[p5sagit/Data-Dumper-Concise.git] / lib / Data / Dumper / Concise / Sugar.pm
CommitLineData
ce1f3e8e 1package Data::Dumper::Concise::Sugar;
2
3use 5.006;
4
5use Exporter ();
6use Data::Dumper::Concise ();
7
8BEGIN { @ISA = qw(Exporter) }
9
10@EXPORT = qw(Dwarn DwarnS);
11
d776e434 12@EXPORT_OK = qw(Dwarn_only DwarnS_only);
13
ce1f3e8e 14sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
15
16sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
17
d776e434 18sub Dwarn_only (&@) {
19 my $only = shift;
20 warn Data::Dumper::Concise::Dumper $only->(@_);
21 @_
22}
23
24sub DwarnS_only (&$) {
25 my $only = shift;
26 warn Data::Dumper::Concise::Dumper do { local $_ = $_[0]; $only->($_[0]) };
27 $_[0]
28}
29
ce1f3e8e 30=head1 NAME
31
32Data::Dumper::Concise::Sugar - return Dwarn @return_value
33
34=head1 SYNOPSIS
35
36 use Data::Dumper::Concise::Sugar;
37
38 return Dwarn some_call(...)
39
40is equivalent to:
41
42 use Data::Dumper::Concise;
43
44 my @return = some_call(...);
45 warn Dumper(@return);
46 return @return;
47
48but shorter. If you need to force scalar context on the value,
49
50 use Data::Dumper::Concise::Sugar;
51
52 return DwarnS some_call(...)
53
54is equivalent to:
55
56 use Data::Dumper::Concise;
57
58 my $return = some_call(...);
59 warn Dumper($return);
60 return $return;
61
01223632 62Another trick that is extremely useful when doing method chaining is the
63following:
64
65 my $foo = Bar->new;
66 $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
67
68which is the same as:
69
70 my $foo = Bar->new;
71 (DwarnS $foo->bar->baz)->biff;
72
ce1f3e8e 73=head1 DESCRIPTION
74
75 use Data::Dumper::Concise::Sugar;
76
77will import Dwarn and DwarnS into your namespace. Using L<Exporter>, so see
78its docs for ways to make it do something else.
79
80=head2 Dwarn
81
82 sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
83
84=head3 DwarnS
85
86 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
87
dc06d25b 88=head1 SEE ALSO
89
90You probably want L<Devel::Dwarn>, it's the shorter name for this module.
91
92=cut
ce1f3e8e 93
941;