lib/Markdown/Parser/TableRow.pm

filter: Statementstmt 20.9% 23 / 110 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 40.0% 8 / 20 Podpod 100% 6 / 6 totaltotal 20.1% 37 / 184 CC 22 SCAR 29.4
CC
22
Cov
15%
as_markdown
42.0
as_pod
42.0
as_string
30.0
CRAP 19.0
« blib/lib/Markdown/Parser/Document.pm ↑ Summary blib/lib/Markdown/Parser/List.pm »
1 ##----------------------------------------------------------------------------
2 ## Markdown Parser Only - ~/lib/Markdown/Parser/TableRow.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/08/23
7 ## Modified 2022/09/19
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Markdown::Parser::TableRow;
14 BEGIN
15 {
16 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶ use parent qw( Markdown::Parser::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ our $VERSION = 'v0.2.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 };
23  
24 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 sub init
28 {
29 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
30 0 $self->{cols} = [];
31 0 $self->{height} = '';
32 0 $self->{tag_name} = 'tr';
33 0 $self->{_as_markdown} = '';
34 0 return( $self->SUPER::init( @_ ) );
35 }
36  
37 sub as_css_grid
38 {
39 0 ▶ my $self = shift( @_ );
Subroutine as_css_grid: not called CC=2 SCAR=17.9
Pod documented
40 0 ▶ return( $self->{_as_css_grid} ) if( $self->{_as_css_grid} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_as_css_grid"} 0 0 0
41 ## There is no "row" in css grid. We just get the cells as divs and pass them along
42 0 ▶ my $cells = $self->children->map(sub{ $_->as_css_grid });
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 0 $self->{_as_css_grid} = $cells->join( "\n" );
44 0 return( $self->{_as_css_grid} );
45 }
46  
47 sub as_markdown
48 {
49 0 ▶ my $self = shift( @_ );
Subroutine as_markdown: not called CC=6 SCAR=37.4
Pod documented
50 0 ▶ return( $self->{_as_markdown} ) if( $self->{_as_markdown} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_as_markdown"} 0 0 0
51 0 my $cell_data = $self->new_array;
52 0 my $cells = $self->new_array;
53 $self->children->foreach(sub
54 {
55 0 ▶ my $cell = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
56 0 my $data = $cell->formatted_lines;
57 0 $cell_data->push( $data );
58 0 $cells->push( $cell );
59 # Get the height of the row by taking the highest cell
60 0 ▶ $self->height( $data->length ) if( $data->length > $self->height );
Branch: 1 branch
BranchTrueFalseTotal
if $data->length > $self->height 0 0 0
61 0 });
62 0 my $row_height = $self->height;
63 # $row_height->debug( 3 );
64 0 my $row_data = $self->new_array;
65 0 ▶ for( my $i = 0; $i < $row_height; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $row_height) 0 0 0
66 {
67 # Pipes at start of row
68 0 ▶ if( $i == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) { } 0 0 0
69 {
70 0 $row_data->push( '|' );
71 }
72 else
73 {
74 0 $row_data->push( ':' );
75 }
76 $cell_data->for(sub
77 {
78 0 ▶ my( $j, $data ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
79 0 my $cell = $cells->get( $j );
80 # This cell is bigger or equal to the current height position, push its data
81 0 ▶ if( $data->size >= $i )
Branch: 1 branch
BranchTrueFalseTotal
if ($data->size >= $i) { } 0 0 0
82 {
83 0 $row_data->push( $data->get( $i ) );
84 }
85 # We are processing more new lines than there is in this cell, so we put blanks instead
86 else
87 {
88 0 $row_data->push( ' ' x $cell->width );
89 }
90
91 # Pipes after this cell, possibly multiple pipes for cells spanning multiple cells
92 0 ▶ if( $i == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) { } 0 0 0
93 {
94 0 $row_data->push( '|' x $cell->colspan );
95 }
96 else
97 {
98 0 $row_data->push( ':' x $cell->colspan );
99 }
100 0 });
101 0 ▶ $row_data->push( "\n" ) if( $row_height > 1 && $i < ( $row_height - 1 ) );
Branch: 1 branch
BranchTrueFalseTotal
if $row_height > 1 and $i < $row_height - 1 0 0 0
Condition0%0/3
$row_height > 1 and $i < $row_height - 1
!ll&&!rl&&r
000
MC/DC0%0/2
$row_height > 1 and $i < $row_height - 1
$row_height > 1 $i < $row_height - 1
Truth table0%0/3
A and B
A= $row_height > 1B= $i < $row_height - 1
ABresult
0X0
100
111
102 }
103 0 $self->{_as_markdown} = $row_data->join( '' );
104 0 return( $self->{_as_markdown} );
105 }
106  
107 sub as_pod
108 {
109 0 ▶ my $self = shift( @_ );
Subroutine as_pod: not called CC=6 SCAR=37.4
Pod documented
110 0 ▶ return( $self->{_as_pod} ) if( $self->{_as_pod} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_as_pod"} 0 0 0
111 0 my $cell_data = $self->new_array;
112 0 my $cells = $self->new_array;
113 $self->children->foreach(sub
114 {
115 0 ▶ my $cell = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
116 0 my $data = $cell->formatted_lines( type => 'pod' );
117 0 $cell_data->push( $data );
118 0 $cells->push( $cell );
119 # Get the height of the row by taking the highest cell
120 0 ▶ $self->height( $data->length ) if( $data->length > $self->height );
Branch: 1 branch
BranchTrueFalseTotal
if $data->length > $self->height 0 0 0
121 0 });
122 0 my $row_height = $self->height;
123 0 my $row_data = $self->new_array;
124 0 ▶ for( my $i = 0; $i < $row_height; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $row_height) 0 0 0
125 {
126 # Pipes at start of row
127 0 ▶ if( $i == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) { } 0 0 0
128 {
129 0 $row_data->push( '|' );
130 }
131 else
132 {
133 0 $row_data->push( ':' );
134 }
135 $cell_data->for(sub
136 {
137 0 ▶ my( $j, $data ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
138 0 my $cell = $cells->get( $j );
139 # This cell is bigger or equal to the current height position, push its data
140 0 ▶ if( $data->size >= $i )
Branch: 1 branch
BranchTrueFalseTotal
if ($data->size >= $i) { } 0 0 0
141 {
142 0 $row_data->push( $data->get( $i ) );
143 }
144 # We are processing more new lines than there is in this cell, so we put blanks instead
145 else
146 {
147 0 $row_data->push( ' ' x $cell->width );
148 }
149
150 # Pipes after this cell, possibly multiple pipes for cells spanning multiple cells
151 0 ▶ if( $i == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) { } 0 0 0
152 {
153 0 $row_data->push( '|' x $cell->colspan );
154 }
155 else
156 {
157 0 $row_data->push( ':' x $cell->colspan );
158 }
159 0 });
160 0 ▶ $row_data->push( "\n" ) if( $row_height > 1 && $i < ( $row_height - 1 ) );
Branch: 1 branch
BranchTrueFalseTotal
if $row_height > 1 and $i < $row_height - 1 0 0 0
Condition0%0/3
$row_height > 1 and $i < $row_height - 1
!ll&&!rl&&r
000
MC/DC0%0/2
$row_height > 1 and $i < $row_height - 1
$row_height > 1 $i < $row_height - 1
Truth table0%0/3
A and B
A= $row_height > 1B= $i < $row_height - 1
ABresult
0X0
100
111
161 }
162 0 $self->{_as_pod} = $row_data->join( '' );
163 0 return( $self->{_as_pod} );
164 }
165  
166 sub as_string
167 {
168 0 ▶ my $self = shift( @_ );
Subroutine as_string: not called CC=5 SCAR=34.0
Pod documented
169 0 my $arr = $self->new_array;
170 0 my $tag = $self->tag_name;
171 0 my $tag_open = $tag;
172 0 my $tmp = $self->new_array;
173 0 $tmp->push( "<$tag_open" );
174 0 my $attr = $self->new_array;
175 0 ▶ $attr->push( $self->format_id ) if( $self->id->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->id->length 0 0 0
176 0 ▶ $attr->push( $self->format_class ) if( $self->class->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->class->length 0 0 0
177 0 my $attributes = $self->format_attributes;
178 0 ▶ $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attributes->length 0 0 0
179 0 ▶ $tmp->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attr->length 0 0 0
180 0 $tmp->push( '>' );
181 0 $arr->push( $tmp->join( '' )->scalar );
182 $arr->push( $self->children->map(sub
183 {
184 0 ▶ $_->as_string;
Subroutine __ANON__: not called CC=1 SCAR=6.9
185 0 })->list );
186 0 $arr->push( "</$tag>" );
187 0 return( $arr->join( "\n" )->scalar );
188 }
189  
190 0 ▶sub height { return( shift->_set_get_number( 'height', @_ ) ); }
Subroutine height: not called CC=1 SCAR=6.9
Pod documented
191  
192 1 1;
193 # NOTE: POD
194 __END__
« blib/lib/Markdown/Parser/Document.pm ↑ Summary blib/lib/Markdown/Parser/List.pm »