File Coverage

blib/lib/Data/Object/Role/Dumpable.pm
Criterion Covered Total %
statement 76 80 95.0
branch n/a
condition n/a
subroutine 13 14 92.8
pod 6 7 85.7
total 95 101 94.0


line stmt bran cond sub pod time code
1             package Data::Object::Role::Dumpable;
2              
3 1     1   36640 use 5.014;
  1         4  
4              
5 1     1   6 use strict;
  1         2  
  1         22  
6 1     1   5 use warnings;
  1         1  
  1         24  
7 1     1   5 use routines;
  1         2  
  1         21  
8              
9 1     1   2741 use Moo::Role;
  1         10107  
  1         7  
10              
11             our $VERSION = '2.02'; # VERSION
12              
13             # METHODS
14              
15 7     7 1 53199 method dump() {
  7         9  
16 7         852 require Data::Dumper;
17              
18 1     1   584 no warnings 'once';
  1         3  
  1         161  
19              
20 7         7188 local $Data::Dumper::Indent = 0;
21 7         16 local $Data::Dumper::Purity = 0;
22 7         11 local $Data::Dumper::Quotekeys = 0;
23 7         12 local $Data::Dumper::Deepcopy = 1;
24 7         11 local $Data::Dumper::Deparse = 1;
25 7         16 local $Data::Dumper::Sortkeys = 1;
26 7         13 local $Data::Dumper::Terse = 1;
27 7         12 local $Data::Dumper::Useqq = 1;
28              
29 7         21 my $data = Data::Dumper::Dumper($self);
30              
31 7         381 $data =~ s/^"|"$//g;
32              
33 7         49 return $data;
34             }
35              
36 7     7 1 14173 method pretty_dump() {
  7         11  
37 7         38 require Data::Dumper;
38              
39 1     1   96 no warnings 'once';
  1         2  
  1         244  
40              
41 7         15 local $Data::Dumper::Indent = 2;
42 7         13 local $Data::Dumper::Trailingcomma = 0;
43 7         12 local $Data::Dumper::Purity = 0;
44 7         10 local $Data::Dumper::Pad = '';
45 7         13 local $Data::Dumper::Varname = 'VAR';
46 7         12 local $Data::Dumper::Useqq = 0;
47 7         11 local $Data::Dumper::Terse = 1;
48 7         12 local $Data::Dumper::Freezer = '';
49 7         11 local $Data::Dumper::Toaster = '';
50 7         13 local $Data::Dumper::Deepcopy = 1;
51 7         10 local $Data::Dumper::Quotekeys = 0;
52 7         11 local $Data::Dumper::Bless = 'bless';
53 7         12 local $Data::Dumper::Pair = ' => ';
54 7         7 local $Data::Dumper::Maxdepth = 0;
55 7         14 local $Data::Dumper::Maxrecurse = 1000;
56 7         9 local $Data::Dumper::Useperl = 0;
57 7         12 local $Data::Dumper::Sortkeys = 1;
58 7         11 local $Data::Dumper::Deparse = 1;
59 7         11 local $Data::Dumper::Sparseseen = 0;
60              
61 7         21 my $data = Data::Dumper::Dumper($self);
62              
63 7         394 $data =~ s/^'|'$//g;
64              
65 7         14 chomp $data;
66              
67 7         51 return $data;
68             }
69              
70 2     2 1 15433 method pretty_print(@args) {
  2         6  
  2         2  
71              
72 2         8 return $self->printer(map &pretty_dump($_), $self, @args);
73             }
74              
75 2     2 1 14785 method pretty_say(@args) {
  2         6  
  2         4  
76              
77 2         8 return $self->printer(map +(&pretty_dump($_), "\n"), $self, @args);
78             }
79              
80 2     2 1 15753 method print(@args) {
  2         6  
  2         4  
81              
82 2         8 return $self->printer(map &dump($_), $self, @args);
83             }
84              
85 0     0 0 0 method printer(@args) {
  0         0  
  0         0  
86              
87 0         0 return CORE::print(@args);
88             }
89              
90 2     2 1 15409 method say(@args) {
  2         6  
  2         4  
91              
92 2         7 return $self->printer(map +(&dump($_), "\n"), $self, @args);
93             }
94              
95             1;
96              
97             =encoding utf8
98              
99             =head1 NAME
100              
101             Data::Object::Role::Dumpable
102              
103             =cut
104              
105             =head1 ABSTRACT
106              
107             Dumpable Role for Perl 5
108              
109             =cut
110              
111             =head1 SYNOPSIS
112              
113             package Example;
114              
115             use Moo;
116              
117             with 'Data::Object::Role::Dumpable';
118              
119             package main;
120              
121             my $example = Example->new;
122              
123             # $example->dump
124              
125             =cut
126              
127             =head1 DESCRIPTION
128              
129             This package provides methods for dumping the object and underlying value.
130              
131             =cut
132              
133             =head1 METHODS
134              
135             This package implements the following methods:
136              
137             =cut
138              
139             =head2 dump
140              
141             dump() : Str
142              
143             The dump method returns a string representation of the underlying data.
144              
145             =over 4
146              
147             =item dump example #1
148              
149             # given: synopsis
150              
151             my $dumped = $example->dump;
152              
153             =back
154              
155             =cut
156              
157             =head2 pretty_dump
158              
159             pretty_dump() : Str
160              
161             The pretty_dump method returns a string representation of the underlying data
162             that is human-readable and useful for debugging.
163              
164             =over 4
165              
166             =item pretty_dump example #1
167              
168             # given: synopsis
169              
170             my $dumped = $example->pretty_dump;
171              
172             =back
173              
174             =cut
175              
176             =head2 pretty_print
177              
178             pretty_print(Any @args) : Int
179              
180             The pretty_print method prints a stringified human-readable representation of
181             the underlying data.
182              
183             =over 4
184              
185             =item pretty_print example #1
186              
187             # given: synopsis
188              
189             my $printed = $example->pretty_print;
190              
191             =back
192              
193             =over 4
194              
195             =item pretty_print example #2
196              
197             # given: synopsis
198              
199             my $printed = $example->pretty_print({1..4});
200              
201             =back
202              
203             =cut
204              
205             =head2 pretty_say
206              
207             pretty_say(Any @args) : Int
208              
209             The pretty_say method prints a stringified human-readable representation of the
210             underlying data, with a trailing newline.
211              
212             =over 4
213              
214             =item pretty_say example #1
215              
216             # given: synopsis
217              
218             my $printed = $example->pretty_say;
219              
220             =back
221              
222             =over 4
223              
224             =item pretty_say example #2
225              
226             # given: synopsis
227              
228             my $printed = $example->pretty_say({1..4});
229              
230             =back
231              
232             =cut
233              
234             =head2 print
235              
236             print(Any @args) : Int
237              
238             The print method prints a stringified representation of the underlying data.
239              
240             =over 4
241              
242             =item print example #1
243              
244             # given: synopsis
245              
246             my $printed = $example->print;
247              
248             =back
249              
250             =over 4
251              
252             =item print example #2
253              
254             # given: synopsis
255              
256             my $printed = $example->print({1..4});
257              
258             =back
259              
260             =cut
261              
262             =head2 say
263              
264             say(Any @args) : Int
265              
266             The say method prints a stringified representation of the underlying data, with
267             a trailing newline.
268              
269             =over 4
270              
271             =item say example #1
272              
273             # given: synopsis
274              
275             my $printed = $example->say;
276              
277             =back
278              
279             =over 4
280              
281             =item say example #2
282              
283             # given: synopsis
284              
285             my $printed = $example->say({1..4});
286              
287             =back
288              
289             =cut
290              
291             =head1 AUTHOR
292              
293             Al Newkirk, C<awncorp@cpan.org>
294              
295             =head1 LICENSE
296              
297             Copyright (C) 2011-2019, Al Newkirk, et al.
298              
299             This is free software; you can redistribute it and/or modify it under the terms
300             of the The Apache License, Version 2.0, as elucidated in the L<"license
301             file"|https://github.com/iamalnewkirk/data-object-role-dumpable/blob/master/LICENSE>.
302              
303             =head1 PROJECT
304              
305             L<Wiki|https://github.com/iamalnewkirk/data-object-role-dumpable/wiki>
306              
307             L<Project|https://github.com/iamalnewkirk/data-object-role-dumpable>
308              
309             L<Initiatives|https://github.com/iamalnewkirk/data-object-role-dumpable/projects>
310              
311             L<Milestones|https://github.com/iamalnewkirk/data-object-role-dumpable/milestones>
312              
313             L<Contributing|https://github.com/iamalnewkirk/data-object-role-dumpable/blob/master/CONTRIBUTE.md>
314              
315             L<Issues|https://github.com/iamalnewkirk/data-object-role-dumpable/issues>
316              
317             =cut