File Coverage

lib/ChordPro/Dumper.pm
Criterion Covered Total %
statement 17 26 65.3
branch 0 6 0.0
condition n/a
subroutine 6 7 85.7
pod 0 1 0.0
total 23 40 57.5


line stmt bran cond sub pod time code
1             #! perl
2              
3 90     90   1802 use v5.26;
  90         429  
4 90     90   632 use feature qw( signatures );
  90         218  
  90         17276  
5 90     90   708 no warnings qw( experimental::signatures );
  90         186  
  90         5586  
6 90     90   572 use utf8;
  90         217  
  90         833  
7              
8             package ChordPro::Dumper;
9              
10 90     90   5705 use Exporter qw(import);
  90         240  
  90         11704  
11             our @EXPORT = qw(ddp);
12              
13             use Data::Printer
14 90         1432 hash_separator => " => ",
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 90     90   64062 internals => 1 };
  90         5455322  
25              
26             my $filters = [
27             # Handle binary strings elegantly.
28             { SCALAR => sub( $ref, $ddp ) {
29             if ( $$ref =~ /[\000-\010\016-\037]/ ) {
30             my $s = $$ref;
31             if ( length($s) > 10 ) {
32             $s = substr( $s, 0, 10 );
33             $s = "'$s...' (" .length($s)." bytes)";
34             }
35             else {
36             $s = qq{'$s'};
37             }
38             $s =~ s/([^[:print:]])/sprintf("\\x{%02x}", ord($1))/ge;
39             return $s;
40             }
41             return;
42             } },
43              
44             # Try to compact hashes.
45             { HASH => sub( $ref, $ddp ) {
46             my $str = Data::Printer::Filter::HASH::parse($ref, $ddp);
47             ( my $s = $str ) =~ s/\s+/ /g;
48             my $nl = $ddp->newline;
49             return length($s)+length($nl) < 80 ? $s : $str;
50             } },
51              
52             # Try to compact arrays.
53             { ARRAY => sub( $ref, $ddp ) {
54             my $str = do {
55             Data::Printer::Filter::ARRAY::parse($ref, $ddp);
56             };
57             my $s = $str;
58             $s =~ s/\n\s+\[\d+\]\s+/ /g;
59             $s =~ s/\s+/ /g;
60             my $nl = $ddp->newline;
61             return length($s)+length($nl) < 80 ? $s : $str;
62             } },
63              
64             { 'PDF::API2::Resource::XObject::Form::Hybrid' => sub ( $ref, $ddp ) {
65             my @bb = $ref->bbox;
66             return ref($ref) . " [@bb]";
67             } },
68              
69             { 'PDF::API2::Resource::XObject::Image' => sub ( $ref, $ddp ) {
70             return join( "", ref($ref),
71             " [", $ref->width, "x", $ref->height, "]",
72             );
73             } },
74             ];
75              
76 0     0 0   sub ddp( $ref, %options ) {
  0            
  0            
  0            
77 0           my %o = ( filters => $filters, %options );
78 0 0         if ( $o{as} =~ /^(.*)\n\Z/s ) {
79 0           $o{as} = $1;
80 0           $o{caller_message_newline} = 1;
81             }
82             defined(wantarray)
83 0 0         ? np( $ref, %o )
    0          
84             : ( -t STDERR )
85             ? p( $ref, %o )
86             : warn( np( $ref, %o ), "\n" );
87             }
88              
89             1;