| 1 | #! perl | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 92 | ▶ | use v5.26; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 92 | ▶ | use feature qw( signatures ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 92 | ▶ | no warnings qw( experimental::signatures ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 92 | ▶ | use utf8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | package ChordPro::Dumper; | ||||||||||||||
| 9 | |||||||||||||||
| 10 | 92 | ▶ | use Exporter qw(import); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 92 | our @EXPORT = qw(ddp); | |||||||||||||
| 12 | |||||||||||||||
| 13 | use Data::Printer | ||||||||||||||
| 14 | 92 | ▶ | hash_separator => " => ", | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | escape_chars => "nonascii", | ||||||||||||||
| 16 | print_escapes => 1, | ||||||||||||||
| 17 | scalar_quotes => "'", | ||||||||||||||
| 18 | caller_message_newline => 0, | ||||||||||||||
| 19 | string_max => 120, | ||||||||||||||
| 20 | class => { parents => 0, | ||||||||||||||
| 21 | linear_isa => 0, | ||||||||||||||
| 22 | show_methods => "none", | ||||||||||||||
| 23 | show_overloads => 0, | ||||||||||||||
| 24 | 92 | internals => 1 }; | |||||||||||||
| 25 | |||||||||||||||
| 26 | my $filters = [ | ||||||||||||||
| 27 | # Handle binary strings elegantly. | ||||||||||||||
| 28 | 0 | ▶ | { SCALAR => sub( $ref, $ddp ) { | ||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||
| 29 | 0 | ▶ | if ( $$ref =~ /[\000-\010\016-\037]/ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | 0 | my $s = $$ref; | |||||||||||||
| 31 | 0 | ▶ | if ( length($s) > 10 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 0 | $s = substr( $s, 0, 10 ); | |||||||||||||
| 33 | 0 | $s = "'$s...' (" .length($s)." bytes)"; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | else { | ||||||||||||||
| 36 | 0 | $s = qq{'$s'}; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | 0 | $s =~ s/([^[:print:]])/sprintf("\\x{%02x}", ord($1))/ge; | |||||||||||||
| 39 | 0 | return $s; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | 0 | return; | |||||||||||||
| 42 | } }, | ||||||||||||||
| 43 | |||||||||||||||
| 44 | # Try to compact hashes. | ||||||||||||||
| 45 | 0 | ▶ | { HASH => sub( $ref, $ddp ) { | ||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||
| 46 | 0 | my $str = Data::Printer::Filter::HASH::parse($ref, $ddp); | |||||||||||||
| 47 | 0 | ( my $s = $str ) =~ s/\s+/ /g; | |||||||||||||
| 48 | 0 | my $nl = $ddp->newline; | |||||||||||||
| 49 | 0 | ▶ | return length($s)+length($nl) < 80 ? $s : $str; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | } }, | ||||||||||||||
| 51 | |||||||||||||||
| 52 | # Try to compact arrays. | ||||||||||||||
| 53 | 0 | ▶ | { ARRAY => sub( $ref, $ddp ) { | ||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||
| 54 | 0 | my $str = do { | |||||||||||||
| 55 | 0 | Data::Printer::Filter::ARRAY::parse($ref, $ddp); | |||||||||||||
| 56 | }; | ||||||||||||||
| 57 | 0 | my $s = $str; | |||||||||||||
| 58 | 0 | $s =~ s/\n\s+\[\d+\]\s+/ /g; | |||||||||||||
| 59 | 0 | $s =~ s/\s+/ /g; | |||||||||||||
| 60 | 0 | my $nl = $ddp->newline; | |||||||||||||
| 61 | 0 | ▶ | return length($s)+length($nl) < 80 ? $s : $str; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | } }, | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 0 | ▶ | { 'PDF::API2::Resource::XObject::Form::Hybrid' => sub ( $ref, $ddp ) { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 65 | 0 | my @bb = $ref->bbox; | |||||||||||||
| 66 | 0 | return ref($ref) . " [@bb]"; | |||||||||||||
| 67 | } }, | ||||||||||||||
| 68 | |||||||||||||||
| 69 | 0 | ▶ | { 'PDF::API2::Resource::XObject::Image' => sub ( $ref, $ddp ) { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 70 | 0 | return join( "", ref($ref), | |||||||||||||
| 71 | " [", $ref->width, "x", $ref->height, "]", | ||||||||||||||
| 72 | ); | ||||||||||||||
| 73 | } }, | ||||||||||||||
| 74 | 92 | ]; | |||||||||||||
| 75 | |||||||||||||||
| 76 | 0 | ▶ | sub ddp( $ref, %options ) { | ||||||||||||
|
Subroutine
ddp: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 77 | 0 | my %o = ( filters => $filters, %options ); | |||||||||||||
| 78 | 0 | ▶ | if ( $o{as} =~ /^(.*)\n\Z/s ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 79 | 0 | $o{as} = $1; | |||||||||||||
| 80 | 0 | $o{caller_message_newline} = 1; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | defined(wantarray) | ||||||||||||||
| 83 | 0 | ▶ | ? np( $ref, %o ) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 84 | : ( -t STDERR ) | ||||||||||||||
| 85 | ? p( $ref, %o ) | ||||||||||||||
| 86 | : warn( np( $ref, %o ), "\n" ); | ||||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | 92 | 1; | |||||||||||||