blib/lib/Hash/Tabular/Markdown.pm

filter: Statementstmt 96.6% 58 / 60 Branchbran 75.0% 9 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 92.0% 81 / 88 CC 10 SCAR 10.8
CC
10
Cov
92%
_to_table
5.2
_hash_nest_depth
4.0
tabulate
2.0
CRAP 2.9
↑ Summary
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
BranchTrueFalseTotal
unless ref $value 11 2 13
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
BranchTrueFalseTotal
unless ref $hashref eq "HASH" 0 5 5
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
BranchTrueFalseTotal
if (ref $content eq "HASH") 8 5 13
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
BranchTrueFalseTotal
$max < $new ? : 8 0 8
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
BranchTrueFalseTotal
if (ref $content eq 'HASH' and keys %$content) { } 8 5 13
Condition66%2/3
ref $content eq "HASH" and keys %$content
!ll&&!rl&&r
508
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
ABresult
0X0
100
111
70 8 foreach my $ky ( keys %$content ) {
71 8 ▶ if ($lf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lf) { } 0 8 8
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__
↑ Summary