lib/Markdown/Parser/TableCell.pm

filter: Statementstmt 25.0% 26 / 104 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 37.5% 9 / 24 Podpod 100% 10 / 10 totaltotal 25.2% 45 / 178 CC 20 SCAR 31.2
CC
20
Cov
18%
as_css_grid
56.0
as_string
42.0
formatted_lines
30.0
CRAP 22.7
« blib/lib/Markdown/Parser/LinkDefinition.pm ↑ Summary lib/Markdown/Parser/ListItem.pm »
1 ##----------------------------------------------------------------------------
2 ## Markdown Parser Only - ~/lib/Markdown/Parser/TableCell.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::TableCell;
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 POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶ our $VERSION = 'v0.2.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 };
24  
25 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 sub init
29 {
30 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
31 0 $self->{tag_name} = 'td';
32 0 return( $self->SUPER::init( @_ ) );
33 }
34  
35 0 ▶sub align { return( shift->_set_get_scalar_as_object( 'align', @_ ) ); }
Subroutine align: not called CC=1 SCAR=6.9
Pod documented
36  
37 sub as_css_grid
38 {
39 0 ▶ my $self = shift( @_ );
Subroutine as_css_grid: not called CC=7 SCAR=40.3
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 0 my $css = $self->css_inline;
42 ## Dummy rule container to contain all the inline rules
43 0 my $sel = $css->builder->select( ['#dummy'] );
44 0 my $arr = $self->new_array;
45 0 my $span = $self->colspan;
46 0 my $align = $self->align;
47 0 my $tag;
48 0 ▶ if( $span > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($span > 1) 0 0 0
49 {
50 0 $sel->grid_column( "span $span" );
51 }
52 0 ▶ if( $align eq 'center' )
Branch: 2 branches
BranchTrueFalseTotal
if ($align eq 'center') { } 0 0 0
elsif ($align eq 'right') { } 0 0 0
53 {
54 0 $sel->justify_self( 'center' );
55 }
56 elsif( $align eq 'right' )
57 {
58 0 $sel->justify_self( 'right' );
59 }
60
61 0 my $elem = $self->new_array( [qw( <div )] );
62 0 ▶ if( $sel->elements->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($sel->elements->length) 0 0 0
63 {
64 0 my $style = $css->builder->as_string;
65 0 $elem->push( "style=\"$style\"" );
66 }
67 0 ▶ if( $self->class->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->class->length > 0) 0 0 0
68 {
69 0 $elem->push( sprintf( 'class="%s"', $self->class->join( ' ' ) ) );
70 }
71 0 $elem->push( '>' );
72
73 0 $arr->push( $elem->join( ' ' ) );
74 0 ▶ $arr->push( $self->children->map(sub{ $_->as_markdown })->join( "\n" )->scalar );
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 $arr->push( "</div>" );
76 0 $self->{_as_css_grid} = $arr->join( "\n" )->scalar;
77 0 return( $self->{_as_css_grid} );
78 }
79  
80 0 ▶sub as_markdown { return( shift->formatted_lines->join( "\n" ) ); }
Subroutine as_markdown: not called CC=1 SCAR=6.9
Pod documented
81  
82 0 ▶sub as_pod { return( shift->formatted_lines( type => 'pod' )->join( "\n" ) ); }
Subroutine as_pod: not called CC=1 SCAR=6.9
Pod documented
83  
84 sub as_string
85 {
86 0 ▶ my $self = shift( @_ );
Subroutine as_string: not called CC=6 SCAR=37.4
Pod documented
87 0 ▶ return( $self->{_as_string} ) if( $self->{_as_string} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_as_string"} 0 0 0
88 0 my $tag = $self->tag_name;
89 0 my $tag_open = $tag;
90 0 my $arr = $self->new_array;
91 0 $arr->push( "<$tag_open" );
92 0 my $attr = $self->new_array;
93 0 ▶ $attr->push( $self->format_id ) if( $self->id->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->id->length 0 0 0
94 0 ▶ $attr->push( $self->format_class ) if( $self->class->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->class->length 0 0 0
95 0 my $attributes = $self->format_attributes;
96 0 ▶ $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attributes->length 0 0 0
97 0 ▶ $arr->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attr->length 0 0 0
98 0 $arr->push( '>' );
99 0 ▶ $arr->push( $self->children->map(sub{ $_->as_string })->join( "\n" )->scalar );
Subroutine __ANON__: not called CC=1 SCAR=6.9
100 0 $arr->push( "</$tag>" );
101 0 $self->{_as_string} = $arr->join( '' )->scalar;
102 0 return( $self->{_as_string} );
103 }
104  
105 0 ▶sub class { return( shift->_set_get_array_as_object( 'class', @_ ) ); }
Subroutine class: not called CC=1 SCAR=6.9
Pod documented
106  
107 0 ▶sub colspan { return( shift->_set_get_number( 'colspan', @_ ) ); }
Subroutine colspan: not called CC=1 SCAR=6.9
Pod documented
108  
109 # For Markdown formatting
110 sub formatted_lines
111 {
112 0 ▶ my $self = shift( @_ );
Subroutine formatted_lines: not called CC=5 SCAR=34.0
Pod documented
113 0 my $opts = $self->_get_args_as_hash( @_ );
114 0 ▶ $opts->{type} //= 'markdown';
Condition0%0/2
$opts->{"type"} //= "markdown"
l!l
00
MC/DC0%0/1
$opts->{"type"} //= "markdown"
$opts->{"type"}
Truth table0%0/2
A
A= $opts->{"type"}
Aresult
11
00
115 0 my $content;
116 0 ▶ if( $opts->{type} eq 'pod' )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'type'} eq 'pod') { } 0 0 0
117 {
118 0 ▶ $content = $self->children->map(sub{ $_->as_pod })->join( "\n" )->split( "\n" );
Subroutine __ANON__: not called CC=1 SCAR=6.9
119 }
120 else
121 {
122 0 ▶ $content = $self->children->map(sub{ $_->as_markdown })->join( "\n" )->split( "\n" );
Subroutine __ANON__: not called CC=1 SCAR=6.9
123 }
124 0 ▶ my $align = $self->align || 'left';
Condition0%0/2
$self->align || 'left'
l!l
00
MC/DC0%0/1
$self->align || 'left'
$self->align
Truth table0%0/2
A
A= $self->align
Aresult
11
00
125 0 my $width = $self->width;
126 0 my $colspan = $self->colspan;
127 # We need to make room for the additional pipes for colspan
128 # Those space in width were added upon parsing, so now, we need to give it back
129 0 ▶ $width -= ( $colspan > 1 ? ( $colspan - 1 ) : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$colspan > 1 ? : 0 0 0
130 0 my $cell_data = $self->new_array;
131 $content->foreach(sub
132 {
133 0 ▶ my $l = shift( @_ );
Subroutine __ANON__: not called CC=5 SCAR=34.0
134 0 ▶ if( length( $l ) == 0 )
Branch: 4 branches
BranchTrueFalseTotal
if (length $l == 0) { } 0 0 0
elsif ($align eq 'left') { } 0 0 0
elsif ($align eq 'right') { } 0 0 0
elsif ($align eq 'center') { } 0 0 0
135 {
136 0 $cell_data->push( '' );
137 }
138 elsif( $align eq 'left' )
139 {
140 0 $cell_data->push( ' ' . $l . ( ' ' x ( $width - ( length( $l ) + 1 ) ) ) );
141 }
142 elsif( $align eq 'right' )
143 {
144 ## Remove 1 from the width to leave a blank space on the right hand side before the column pip separator
145 0 $cell_data->push( ( ' ' x ( ( $width - 1 ) - length( $l ) ) ) . $l . ' ' );
146 }
147 elsif( $align eq 'center' )
148 {
149 0 my $remain = $width - length( $l );
150 0 my $left = POSIX::round( $remain / 2 );
151 0 my $right = $remain - $left;
152 0 $cell_data->push( ( ' ' x $left ) . $l . ( ' ' x $right ) );
153 }
154 0 });
155 0 return( $cell_data );
156 }
157  
158 0 ▶sub width { return( shift->_set_get_number( 'width', @_ ) ); }
Subroutine width: not called CC=1 SCAR=6.9
Pod documented
159  
160 1 1;
161 # NOTE: POD
162 __END__
« blib/lib/Markdown/Parser/LinkDefinition.pm ↑ Summary lib/Markdown/Parser/ListItem.pm »