File Coverage

blib/lib/Test2/Tools/Explain.pm
Criterion Covered Total %
statement 19 19 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 28 29 96.5


line stmt bran cond sub pod time code
1             package Test2::Tools::Explain;
2              
3 2     2   151247 use 5.008001;
  2         7  
4 2     2   8 use strict;
  2         3  
  2         34  
5 2     2   6 use warnings;
  2         4  
  2         109  
6              
7             =head1 NAME
8              
9             Test2::Tools::Explain -- Explain tools for Perl's Test2 framework
10              
11             =head1 VERSION
12              
13             Version 0.02
14              
15             =cut
16              
17             our $VERSION = '0.02';
18              
19 2     2   767 use parent 'Exporter';
  2         453  
  2         8  
20              
21             our @EXPORT_OK = qw(
22             explain
23             );
24              
25             our @EXPORT = @EXPORT_OK;
26              
27             =head1 SYNOPSIS
28              
29             L dropped the C function that had been
30             part of Test::More. For those who miss it in Test2, you can use
31             Test2::Tools::Explain.
32              
33             use Test2::Tools::Explain;
34              
35             my $errors = fleeble_the_whatzit();
36             is( $errors, [], 'Should have no errors from fleebling' ) or diag explain( $errors );
37              
38             =head1 EXPORTS
39              
40             All functions in this module are exported by default.
41              
42             =head1 SUBROUTINES
43              
44             =head2 explain( @things_to_explain )
45              
46             Will convert the contents of any references in a human readable format,
47             and return them as strings. Usually you want to pass this into C
48             or C.
49              
50             Handy for things like:
51              
52             is( $errors, [], 'Should have no errors' ) or diag explain( $errors );
53              
54             Note that C does NOT output anything.
55              
56             =cut
57              
58             sub explain {
59 1     1 1 4640 local ($@, $!);
60 1         536 require Data::Dumper;
61              
62             return map {
63 1         4386 ref $_
64 3 100       49 ? do {
65 2         7 my $dumper = Data::Dumper->new( [$_] );
66 2         37 $dumper->Indent(1)->Terse(1);
67 2 50       31 $dumper->Sortkeys(1) if $dumper->can('Sortkeys');
68 2         7 $dumper->Dump;
69             }
70             : $_
71             } @_;
72             }
73              
74             =head1 AUTHOR
75              
76             Andy Lester, C<< >>
77              
78             =head1 BUGS
79              
80             Please report any bugs or feature requests to
81             L.
82             I will be notified, and then you'll automatically be notified of progress
83             on your bug as I make changes.
84              
85             =head1 SUPPORT
86              
87             You can find documentation for this module with the perldoc command.
88              
89             perldoc Test2::Tools::Explain
90              
91             You can also look for information at:
92              
93             =over 4
94              
95             =item * GitHub project page
96              
97             L
98              
99             =item * Search CPAN
100              
101             L
102              
103             =item * AnnoCPAN: Annotated CPAN documentation
104              
105             L
106              
107             =item * CPAN Ratings
108              
109             L
110              
111             =back
112              
113             =head1 ACKNOWLEDGEMENTS
114              
115             The code for C is originally from C by Michael
116             Schwern, who took it from C by Curtis Poe.
117              
118             =head1 LICENSE AND COPYRIGHT
119              
120             Copyright 2016 Andy Lester.
121              
122             This program is free software; you can redistribute it and/or modify it
123             under the terms of the the Artistic License (2.0). You may obtain a
124             copy of the full license at:
125              
126             L
127              
128             Any use, modification, and distribution of the Standard or Modified
129             Versions is governed by this Artistic License. By using, modifying or
130             distributing the Package, you accept this license. Do not use, modify,
131             or distribute the Package, if you do not accept this license.
132              
133             If your Modified Version has been derived from a Modified Version made
134             by someone other than you, you are nevertheless required to ensure that
135             your Modified Version complies with the requirements of this license.
136              
137             This license does not grant you the right to use any trademark, service
138             mark, tradename, or logo of the Copyright Holder.
139              
140             This license includes the non-exclusive, worldwide, free-of-charge
141             patent license to make, have made, use, offer to sell, sell, import and
142             otherwise transfer the Package with respect to any patent claims
143             licensable by the Copyright Holder that are necessarily infringed by the
144             Package. If you institute patent litigation (including a cross-claim or
145             counterclaim) against any party alleging that the Package constitutes
146             direct or contributory patent infringement, then this Artistic License
147             to you shall terminate on the date that such litigation is filed.
148              
149             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
150             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
151             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
152             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
153             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
154             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
155             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
156             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
157              
158             =cut
159              
160             1; # End of Test2::Tools::Explain