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