doc for _only methods
[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
5054642f 61Sometimes you'll want to C<Dwarn> out part of a result, instead of the entire
62thing; for that we have C<Dwarn_only>:
63
64 # Dwarn the TO_JSON of all the objects in the list
65 my @results = Dwarn_only { map $_->TO_JSON, @_ } some_call(...);
66
67and C<DwarnS_only>:
68
69 # only Dwarn the first item
70 my $data = Dwarn_only { $_->[0] } [ some_call(...) ];
71
01223632 72Another trick that is extremely useful when doing method chaining is the
73following:
74
75 my $foo = Bar->new;
76 $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
77
78which is the same as:
79
80 my $foo = Bar->new;
81 (DwarnS $foo->bar->baz)->biff;
82
ce1f3e8e 83=head1 DESCRIPTION
84
85 use Data::Dumper::Concise::Sugar;
86
87will import Dwarn and DwarnS into your namespace. Using L<Exporter>, so see
88its docs for ways to make it do something else.
89
90=head2 Dwarn
91
92 sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
93
5054642f 94=head2 DwarnS
ce1f3e8e 95
96 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
97
5054642f 98=head2 Dwarn_only
99
100 sub Dwarn_only (&@) {
101 my $only = shift;
102 warn Data::Dumper::Concise::Dumper $only->(@_);
103 @_
104 }
105
106=head2 DwarnS_only
107
108 sub DwarnS_only (&$) {
109 my $only = shift;
110 warn Data::Dumper::Concise::Dumper do { local $_ = $_[0]; $only->($_[0]) };
111 $_[0]
112 }
113
dc06d25b 114=head1 SEE ALSO
115
116You probably want L<Devel::Dwarn>, it's the shorter name for this module.
117
118=cut
ce1f3e8e 119
1201;