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