| 1 | 1 | ▶ | use 5.012; #package NAME VERSION | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 2 | package Data::CompactDump 0.04; | ||||||||||||||||||||||||||
| 3 | # ABSTRACT: Perl extension for dumping xD structures in compact form | ||||||||||||||||||||||||||
| 4 | 1 | $Data::CompactDump::VERSION = '0.04'; | |||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 7 | 1 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||
| 9 | 1 | our @EXPORT = qw(compact); | |||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||
| 12 | 10 | ▶ | sub compact { | ||||||||||||||||||||||||
|
Subroutine
compact: called CC=7 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||
| 13 | 10 | ▶ | unless (defined (my $q = shift)) { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 14 | 0 | return 'undef'; | |||||||||||||||||||||||||
| 15 | } elsif (not ref $q) { | ||||||||||||||||||||||||||
| 16 | 6 | ▶ | if ($q =~ /^\d+$/) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 17 | 5 | return $q; | |||||||||||||||||||||||||
| 18 | } else { | ||||||||||||||||||||||||||
| 19 | 1 | $q =~ s/\n/\\n/g; $q =~ s/\r/\\r/g; $q =~ s/'/\\'/g; | |||||||||||||||||||||||||
| 20 | 1 | return "\'" . $q . "\'"; | |||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||
| 22 | } elsif ((my $rr = ref $q) eq 'ARRAY') { | ||||||||||||||||||||||||||
| 23 | 4 | return '[ ' . join(', ',map { compact($_); } @$q) . ' ]'; | |||||||||||||||||||||||||
| 24 | } elsif ($rr eq 'SCALAR') { | ||||||||||||||||||||||||||
| 25 | 0 | return '\\' . compact($$q); | |||||||||||||||||||||||||
| 26 | } elsif ($rr eq 'HASH') { | ||||||||||||||||||||||||||
| 27 | 0 | return '{ ' . join(', ',map { $_ . ' => ' . compact($$q{$_}); } | |||||||||||||||||||||||||
| 28 | keys %$q) . ' }'; | ||||||||||||||||||||||||||
| 29 | 0 | } else { return '\?'; } | |||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||
| 32 | 1 | 1; | |||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||
| 34 | __END__ | ||||||||||||||||||||||||||