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