| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Data::Printer::Profile::Dumper; | 
| 2 | 1 |  |  | 1 |  | 8 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 36 |  | 
| 3 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 1239 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | sub profile { | 
| 6 |  |  |  |  |  |  | return { | 
| 7 | 3 |  |  | 3 | 0 | 73 | show_tainted => 0, | 
| 8 |  |  |  |  |  |  | show_unicode => 0, | 
| 9 |  |  |  |  |  |  | show_lvalue  => 0, | 
| 10 |  |  |  |  |  |  | print_escapes => 0, | 
| 11 |  |  |  |  |  |  | scalar_quotes => q('), | 
| 12 |  |  |  |  |  |  | escape_chars => 'none', | 
| 13 |  |  |  |  |  |  | string_max => 0, | 
| 14 |  |  |  |  |  |  | unicode_charnames => 0, | 
| 15 |  |  |  |  |  |  | array_max => 0, | 
| 16 |  |  |  |  |  |  | index => 0, | 
| 17 |  |  |  |  |  |  | hash_max => 0, | 
| 18 |  |  |  |  |  |  | hash_separator => ' => ', | 
| 19 |  |  |  |  |  |  | align_hash => 0, | 
| 20 |  |  |  |  |  |  | sort_keys => 0, | 
| 21 |  |  |  |  |  |  | quote_keys => 1, | 
| 22 |  |  |  |  |  |  | name => '$VAR1', | 
| 23 |  |  |  |  |  |  | arrows => 'first', | 
| 24 |  |  |  |  |  |  | return_value => 'dump', | 
| 25 |  |  |  |  |  |  | output => 'stderr', | 
| 26 |  |  |  |  |  |  | indent => 10, | 
| 27 |  |  |  |  |  |  | show_readonly => 0, | 
| 28 |  |  |  |  |  |  | show_tied => 0, | 
| 29 |  |  |  |  |  |  | show_dualvar => 'off', | 
| 30 |  |  |  |  |  |  | show_weak => 0, | 
| 31 |  |  |  |  |  |  | show_refcount => 0, | 
| 32 |  |  |  |  |  |  | show_memsize => 0, | 
| 33 |  |  |  |  |  |  | separator => ',', | 
| 34 |  |  |  |  |  |  | end_separator => 0, | 
| 35 |  |  |  |  |  |  | caller_info => 0, | 
| 36 |  |  |  |  |  |  | colored => 0, | 
| 37 |  |  |  |  |  |  | class_method => undef, | 
| 38 |  |  |  |  |  |  | # Data::Printer doesn't provide a way to directly | 
| 39 |  |  |  |  |  |  | # decorate filters, so we do it ourselves: | 
| 40 |  |  |  |  |  |  | filters => [ | 
| 41 |  |  |  |  |  |  | { | 
| 42 |  |  |  |  |  |  | '-class'  => \&_data_dumper_class_filter, | 
| 43 |  |  |  |  |  |  | 'SCALAR'  => \&_data_dumper_scalar_filter, | 
| 44 |  |  |  |  |  |  | 'LVALUE'  => \&_data_dumper_lvalue_filter, | 
| 45 |  |  |  |  |  |  | 'HASH'    => \&_data_dumper_hash_filter, | 
| 46 |  |  |  |  |  |  | 'ARRAY'   => \&_data_dumper_array_filter, | 
| 47 |  |  |  |  |  |  | 'CODE'    => \&_data_dumper_code_filter, | 
| 48 |  |  |  |  |  |  | 'FORMAT'  => \&_data_dumper_format_filter, | 
| 49 |  |  |  |  |  |  | 'GLOB'    => \&_data_dumper_glob_filter, | 
| 50 |  |  |  |  |  |  | 'REF'     => \&_data_dumper_ref_filter,, | 
| 51 |  |  |  |  |  |  | 'Regexp'  => \&_data_dumper_regexp_filter, | 
| 52 |  |  |  |  |  |  | 'VSTRING' => \&_data_dumper_vstring_filter, | 
| 53 |  |  |  |  |  |  | }, | 
| 54 |  |  |  |  |  |  | ], | 
| 55 |  |  |  |  |  |  | }; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | sub _data_dumper_regexp_filter { | 
| 59 | 1 |  |  | 1 |  | 4 | my ($re, $ddp) = @_; | 
| 60 | 1 |  |  |  |  | 4 | my $v = "$re"; | 
| 61 | 1 |  |  |  |  | 3 | my $mod = ""; | 
| 62 | 1 | 50 |  |  |  | 21 | if ($v =~ /^\(\?\^?([msixpadlun-]*):([\x00-\xFF]*)\)\z/) { | 
| 63 | 1 |  |  |  |  | 7 | $mod = $1; | 
| 64 | 1 |  |  |  |  | 3 | $v = $2; | 
| 65 | 1 |  |  |  |  | 4 | $mod =~ s/-.*//; | 
| 66 |  |  |  |  |  |  | } | 
| 67 | 1 |  |  |  |  | 3 | $v =~ s{/}{\\/}g; | 
| 68 | 1 |  |  |  |  | 7 | return _output_wrapper($ddp, $ddp->maybe_colorize("qr/$v/$mod", 'regex')); | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | sub _data_dumper_glob_filter { | 
| 72 | 1 |  |  | 1 |  | 3 | my ($glob, $ddp) = @_; | 
| 73 | 1 |  |  |  |  | 5 | my $ret = "$$glob"; | 
| 74 | 1 |  |  |  |  | 24 | $ret =~ s|\A\*main:|\*:|; | 
| 75 | 1 |  |  |  |  | 7 | $ret =~ s|\A\*|\\*{'|; | 
| 76 | 1 |  |  |  |  | 3 | $ret .= '\'}'; | 
| 77 | 1 |  |  |  |  | 12 | return _output_wrapper($ddp, $ddp->maybe_colorize($ret, 'glob')); | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | sub _data_dumper_lvalue_filter { | 
| 81 | 1 |  |  | 1 |  | 2 | my (undef, $ddp) = @_; | 
| 82 | 1 |  |  |  |  | 6 | Data::Printer::Common::_warn($ddp, 'cannot handle ref type 10'); | 
| 83 | 1 |  |  |  |  | 4 | return _output_wrapper($ddp, ''); | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | sub _data_dumper_scalar_filter { | 
| 87 | 5 |  |  | 5 |  | 9 | my ($scalar, $ddp) = @_; | 
| 88 | 5 |  |  |  |  | 16 | my $ret = Data::Printer::Filter::SCALAR::parse(@_); | 
| 89 | 5 |  |  |  |  | 14 | return _output_wrapper($ddp, $ret); | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | sub _data_dumper_ref_filter { | 
| 93 | 3 |  |  | 3 |  | 6 | my ($scalar, $ddp) = @_; | 
| 94 | 3 |  |  |  |  | 7 | $ddp->indent; | 
| 95 | 3 |  |  |  |  | 11 | my $ret = Data::Printer::Filter::REF::parse(@_); | 
| 96 | 3 |  |  |  |  | 16 | $ret =~ s{\A[\\]+\s+}{\\}; # DDP's REF filter adds a space after refs. | 
| 97 | 3 |  |  |  |  | 12 | $ddp->outdent; | 
| 98 | 3 |  |  |  |  | 7 | return _output_wrapper($ddp, $ret); | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | sub _data_dumper_vstring_filter { | 
| 102 | 1 |  |  | 1 |  | 3 | my ($scalar, $ddp) = @_; | 
| 103 | 1 |  |  |  |  | 6 | my $ret = Data::Printer::Filter::VSTRING::parse(@_); | 
| 104 | 1 | 50 | 33 |  |  | 7 | if ($] < 5.009 && substr($ret, 0, 7) eq 'VSTRING') { | 
| 105 | 0 |  |  |  |  | 0 | $ret = $ddp->maybe_colorize('', 'vstring'); | 
| 106 |  |  |  |  |  |  | } | 
| 107 | 1 |  |  |  |  | 4 | return _output_wrapper($ddp, $ret); | 
| 108 |  |  |  |  |  |  | } | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | sub _data_dumper_format_filter { | 
| 111 | 1 |  |  | 1 |  | 10 | my (undef, $ddp) = @_; | 
| 112 | 1 |  |  |  |  | 5 | Data::Printer::Common::_warn($ddp, 'cannot handle ref type 14'); | 
| 113 | 1 |  |  |  |  | 6 | return _output_wrapper($ddp, ''); | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | sub _data_dumper_code_filter { | 
| 117 | 1 |  |  | 1 |  | 4 | my (undef, $ddp) = @_; | 
| 118 | 1 |  |  |  |  | 5 | return _output_wrapper($ddp, $ddp->maybe_colorize('sub { "DUMMY" }', 'code')); | 
| 119 |  |  |  |  |  |  | } | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | sub _data_dumper_array_filter { | 
| 122 | 1 |  |  | 1 |  | 3 | my ($hashref, $ddp) = @_; | 
| 123 | 1 |  |  |  |  | 6 | my $ret = Data::Printer::Filter::ARRAY::parse(@_); | 
| 124 | 1 |  |  |  |  | 4 | return _output_wrapper($ddp, $ret); | 
| 125 |  |  |  |  |  |  | } | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | sub _data_dumper_hash_filter { | 
| 128 | 1 |  |  | 1 |  | 3 | my ($hashref, $ddp) = @_; | 
| 129 | 1 |  |  |  |  | 6 | my $ret = Data::Printer::Filter::HASH::parse(@_); | 
| 130 | 1 |  |  |  |  | 3 | return _output_wrapper($ddp, $ret); | 
| 131 |  |  |  |  |  |  | } | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | sub _data_dumper_class_filter { | 
| 134 | 1 |  |  | 1 |  | 3 | my ($obj, $ddp) = @_; | 
| 135 | 1 |  |  |  |  | 5 | require Scalar::Util; | 
| 136 | 1 |  |  |  |  | 4 | my $reftype = Scalar::Util::reftype($obj); | 
| 137 | 1 | 50 |  |  |  | 4 | $reftype = 'Regexp' if $reftype eq 'REGEXP'; | 
| 138 | 1 |  |  |  |  | 4 | my ($parse_prefix, $parse_suffix) = ('', ''); | 
| 139 | 1 | 0 | 33 |  |  | 5 | if ($reftype eq 'SCALAR' || $reftype eq 'REF' || $reftype eq 'VSTRING') { | 
|  |  |  | 33 |  |  |  |  | 
| 140 | 1 |  |  |  |  | 85 | $parse_prefix = 'do{\(my $o = '; | 
| 141 | 1 | 50 |  |  |  | 7 | $parse_prefix .= '\\' if $reftype eq 'REF'; | 
| 142 | 1 |  |  |  |  | 64 | $parse_suffix = ')}'; | 
| 143 |  |  |  |  |  |  | } | 
| 144 | 1 |  |  |  |  | 8 | $ddp->indent; | 
| 145 | 1 |  |  |  |  | 6 | my $ret = $ddp->maybe_colorize('bless( ' . $parse_prefix, 'method') | 
| 146 |  |  |  |  |  |  | . $ddp->parse_as($reftype, $obj) | 
| 147 |  |  |  |  |  |  | . $ddp->maybe_colorize($parse_suffix, 'method') | 
| 148 |  |  |  |  |  |  | . q|, '| . $ddp->maybe_colorize(ref($obj), 'class') . q|'| | 
| 149 |  |  |  |  |  |  | . $ddp->maybe_colorize(' )', 'method') | 
| 150 |  |  |  |  |  |  | ; | 
| 151 | 1 |  |  |  |  | 5 | $ddp->outdent; | 
| 152 |  |  |  |  |  |  |  | 
| 153 | 1 |  |  |  |  | 4 | return _output_wrapper($ddp, $ret); | 
| 154 |  |  |  |  |  |  | } | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | sub _output_wrapper { | 
| 157 | 17 |  |  | 17 |  | 37 | my ($ddp, $output) = @_; | 
| 158 | 17 | 100 |  |  |  | 37 | if ($ddp->current_depth == 0) { | 
| 159 | 1 |  |  |  |  | 3 | $output = '$VAR1 = ' . $output . ';'; | 
| 160 |  |  |  |  |  |  | } | 
| 161 | 17 |  |  |  |  | 57 | return $output; | 
| 162 |  |  |  |  |  |  | } | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | 1; | 
| 165 |  |  |  |  |  |  | __END__ |