line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package autobox::dump; |
2
|
|
|
|
|
|
|
# vi: ht=4 sw=4 ts=4 et : |
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
128107
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
138
|
|
5
|
4
|
|
|
4
|
|
29
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
160
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
22
|
use base "autobox"; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
5672
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '20090426.1746'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @options = qw/Indent Terse Useqq Sortkeys Deparse/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub options { |
14
|
|
|
|
|
|
|
#let them call it autobox::dump::options or autobox::dump->options |
15
|
1
|
50
|
|
1
|
0
|
1249
|
shift @_ if $_[0] eq 'autobox::dump'; |
16
|
1
|
|
|
|
|
6
|
@options = @_; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub import { |
20
|
4
|
|
|
4
|
|
39
|
my $class = shift; |
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
|
|
9
|
my $dumper = "autobox::dump::inner"; |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
38
|
$class->SUPER::import( |
25
|
|
|
|
|
|
|
SCALAR => $dumper, |
26
|
|
|
|
|
|
|
ARRAY => $dumper, |
27
|
|
|
|
|
|
|
HASH => $dumper, |
28
|
|
|
|
|
|
|
CODE => $dumper, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
package autobox::dump::inner; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub perl { |
36
|
21
|
|
|
21
|
|
22659
|
require Data::Dumper; |
37
|
|
|
|
|
|
|
#use Test::More; |
38
|
|
|
|
|
|
|
|
39
|
21
|
|
|
|
|
20759
|
my $self = shift; |
40
|
21
|
100
|
|
|
|
102
|
my @options = @_ ? @_ : @autobox::dump::options; |
41
|
|
|
|
|
|
|
|
42
|
21
|
|
|
|
|
103
|
my $dumper = Data::Dumper->new([$self]); |
43
|
|
|
|
|
|
|
|
44
|
21
|
|
|
|
|
562
|
for my $option (@options) { |
45
|
94
|
100
|
|
|
|
652
|
my ($opt, @opt_args) = ref $option ? @$option : ($option, 1); |
46
|
|
|
|
|
|
|
|
47
|
94
|
50
|
|
|
|
514
|
$dumper->$opt(@opt_args) if $dumper->can($opt); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
21
|
|
|
|
|
161
|
return $dumper->Dump; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
autobox::dump - human/perl readable strings from the results of an EXPR |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 VERSION |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Version 20090426.1746 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 SYNOPSIS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
The autobox::dump pragma adds, via the autobox pragma, a method to |
66
|
|
|
|
|
|
|
normal expression (such as scalars, arrays, hashes, math, literals, etc.) |
67
|
|
|
|
|
|
|
that produces a human/perl readable representation of the value of that |
68
|
|
|
|
|
|
|
expression. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
use autobox::dump; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $foo = "foo"; |
74
|
|
|
|
|
|
|
print $foo->perl; # "foo"; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
print +(5*6)->perl; # 30; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my @a = (1..3); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
print @a->perl; |
81
|
|
|
|
|
|
|
# [ |
82
|
|
|
|
|
|
|
# 1, |
83
|
|
|
|
|
|
|
# 2, |
84
|
|
|
|
|
|
|
# 3 |
85
|
|
|
|
|
|
|
# ]; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
print {a=>1, b=>2}->perl; |
88
|
|
|
|
|
|
|
# { |
89
|
|
|
|
|
|
|
# "a" => 1, |
90
|
|
|
|
|
|
|
# "b" => 2 |
91
|
|
|
|
|
|
|
# }; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub func { |
94
|
|
|
|
|
|
|
my ($x, $y) = @_; |
95
|
|
|
|
|
|
|
return $x + $y; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $func = \&func; |
99
|
|
|
|
|
|
|
print $func->perl; |
100
|
|
|
|
|
|
|
#sub { |
101
|
|
|
|
|
|
|
# BEGIN { |
102
|
|
|
|
|
|
|
# $^H{'autobox_scope'} = q(154456408); |
103
|
|
|
|
|
|
|
# $^H{'autobox'} = q(HASH(0x93a3e00)); |
104
|
|
|
|
|
|
|
# $^H{'autobox_leave'} = q(Scope::Guard=ARRAY(0x9435078)); |
105
|
|
|
|
|
|
|
# } |
106
|
|
|
|
|
|
|
# my($x, $y) = @_; |
107
|
|
|
|
|
|
|
# return $x + $y; |
108
|
|
|
|
|
|
|
#} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
You can set Data::Dumper options by passing either arrayrefs of option |
111
|
|
|
|
|
|
|
and value pairs or just keys (in which case the option will be set to |
112
|
|
|
|
|
|
|
1). The default options are C. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
print ["a", 0, 1]->perl([Indent => 3], [Varname => "a"], qw/Useqq/); |
115
|
|
|
|
|
|
|
#$a1 = [ |
116
|
|
|
|
|
|
|
# #0 |
117
|
|
|
|
|
|
|
# "a", |
118
|
|
|
|
|
|
|
# #1 |
119
|
|
|
|
|
|
|
# 0, |
120
|
|
|
|
|
|
|
# #2 |
121
|
|
|
|
|
|
|
# 1 |
122
|
|
|
|
|
|
|
# ]; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
You can also call the class method ->options to set a different default. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
#set Indent to 0, but leave the rest of the options |
127
|
|
|
|
|
|
|
autobox::dump->options([Indent => 0], qw/Terse Useqq Sortkeys Deparse/); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
print ["a", 0, 1]->perl; #["a",0,1] |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 AUTHOR |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Chas. J Owens IV, C<< >> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 BUGS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Has all the issues L has. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Has all the issues L has. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This pragma errs on the side of human readable to the detriment of |
142
|
|
|
|
|
|
|
Perl readable. In particular it uses the terse and deparse options |
143
|
|
|
|
|
|
|
of Data::Dumper by default. These options may create code that cannot |
144
|
|
|
|
|
|
|
be eval'ed. For best eval results, set options to C. |
145
|
|
|
|
|
|
|
Note, this turns off coderef dumping. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
148
|
|
|
|
|
|
|
http://github.com/cowens/autobox-dump/issues |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 SUPPORT |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
perldoc autobox::dump |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Michael Schwern for starting the perl5i pragma which prompted me to add |
159
|
|
|
|
|
|
|
a feature I wanted to autobox. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Copyright 2009 Chas. J Owens IV, all rights reserved. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
166
|
|
|
|
|
|
|
under the same terms as Perl itself. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; # End of autobox::dump |