line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::Tabular::Markdown; |
2
|
2
|
|
|
2
|
|
12880
|
use 5.008001; |
|
2
|
|
|
|
|
4
|
|
3
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
28
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
32
|
|
5
|
2
|
|
|
2
|
|
962
|
use Data::Dumper; |
|
2
|
|
|
|
|
10124
|
|
|
2
|
|
|
|
|
760
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $Delimit = "|"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $DataDumperFunciton = sub { |
12
|
|
|
|
|
|
|
my ($value) = @_; |
13
|
|
|
|
|
|
|
return $value unless (ref($value)); |
14
|
|
|
|
|
|
|
{ |
15
|
|
|
|
|
|
|
local $Data::Dumper::Terse = 1; |
16
|
|
|
|
|
|
|
local $Data::Dumper::Indent = 0; |
17
|
|
|
|
|
|
|
return Data::Dumper::Dumper($value); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub tabulate { |
22
|
5
|
|
|
5
|
1
|
3831
|
my ($class, $hashref) = @_; |
23
|
|
|
|
|
|
|
|
24
|
5
|
50
|
|
|
|
12
|
return "require hash ref." unless ( ref($hashref) eq 'HASH' ); |
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
|
|
6
|
my $md = _to_md($hashref); |
27
|
5
|
|
|
|
|
6
|
return $md; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _to_md { |
31
|
5
|
|
|
5
|
|
6
|
my ($content) = @_; |
32
|
|
|
|
|
|
|
|
33
|
5
|
|
|
|
|
8
|
my $dth = _hash_nest_depth( $content, 0 ); |
34
|
5
|
|
|
|
|
5
|
my $md; |
35
|
5
|
|
|
|
|
3
|
my $delimit = $Delimit; |
36
|
5
|
|
|
|
|
9
|
$md .= $delimit . $delimit x $dth . "\n"; |
37
|
5
|
|
|
|
|
9
|
$md .= $delimit . ":--$delimit" x $dth . "\n"; |
38
|
5
|
|
|
|
|
6
|
my $nest = [$delimit]; |
39
|
5
|
|
|
|
|
10
|
_to_table( $content, \$md, $nest ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# $md =~ s/\n\n+/\n/g; |
42
|
5
|
|
|
|
|
8
|
return $md; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _hash_nest_depth { |
46
|
13
|
|
|
13
|
|
12
|
my ( $content, $dth ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
13
|
|
|
|
|
9
|
my $max = $dth; |
49
|
13
|
|
|
|
|
8
|
$max++; |
50
|
13
|
|
|
|
|
7
|
$dth++; |
51
|
13
|
100
|
|
|
|
19
|
if ( ref($content) eq 'HASH' ) { |
52
|
8
|
|
|
|
|
14
|
foreach my $ky ( keys %$content ) { |
53
|
8
|
|
|
|
|
12
|
my $new = _hash_nest_depth( $content->{$ky}, $dth ); |
54
|
8
|
50
|
|
|
|
16
|
$max = $max < $new ? $new : $max; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
13
|
|
|
|
|
11
|
return $max; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _dump { |
61
|
13
|
|
|
13
|
|
10
|
my ($content) = @_; |
62
|
13
|
|
|
|
|
15
|
return $DataDumperFunciton->($content); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _to_table { |
66
|
13
|
|
|
13
|
|
7
|
my ( $content, $md, $nest ) = @_; |
67
|
|
|
|
|
|
|
|
68
|
13
|
|
|
|
|
11
|
my $lf; |
69
|
13
|
100
|
66
|
|
|
35
|
if ( ref($content) eq 'HASH' && keys(%$content)) { |
70
|
8
|
|
|
|
|
11
|
foreach my $ky ( keys %$content ) { |
71
|
8
|
50
|
|
|
|
9
|
if ($lf) { |
72
|
0
|
|
|
|
|
0
|
$$md .= join( '', @$nest ) . _dump($ky); |
73
|
0
|
|
|
|
|
0
|
$lf = undef; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else { |
76
|
8
|
|
|
|
|
11
|
$$md .= $nest->[0] . _dump($ky); |
77
|
|
|
|
|
|
|
} |
78
|
8
|
|
|
|
|
11
|
push @$nest, $nest->[0]; |
79
|
8
|
|
|
|
|
12
|
$lf = _to_table( $content->{$ky}, $md, $nest ); |
80
|
8
|
|
|
|
|
8
|
pop @$nest; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
5
|
|
|
|
|
6
|
$$md .= "|" . _dump($content); |
85
|
5
|
|
|
|
|
206
|
$$md .= "\n"; |
86
|
5
|
|
|
|
|
7
|
return 1; |
87
|
|
|
|
|
|
|
} |
88
|
8
|
|
|
|
|
8
|
return $lf; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
__END__ |