| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## Markdown Parser Only - ~/lib/Markdown/Parser/Table.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.3.0 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 6 | ## Created 2021/08/23 | ||||||||||||||||||||||||||||
| 7 | ## Modified 2024/08/30 | ||||||||||||||||||||||||||||
| 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::Table; | ||||||||||||||||||||||||||||
| 14 | BEGIN | ||||||||||||||||||||||||||||
| 15 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use constant CHAR2PIXELS => 8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | our $VERSION = 'v0.3.0'; | |||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub init | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 32 | 0 | $self->{bodies} = []; | |||||||||||||||||||||||||||
| 33 | 0 | $self->{caption} = ''; | |||||||||||||||||||||||||||
| 34 | 0 | $self->{headers} = []; | |||||||||||||||||||||||||||
| 35 | 0 | $self->{tag_name} = 'table'; | |||||||||||||||||||||||||||
| 36 | 0 | $self->{use_css_grid} = 0; | |||||||||||||||||||||||||||
| 37 | 0 | return( $self->SUPER::init( @_ ) ); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub as_css_grid | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
as_css_grid: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | return( $self->{_as_css_grid} ) if( $self->{_as_css_grid} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | ## css(9 method is inherited from Markdown::Parser::Element | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $css = $self->css || return( $self->error( "No CSS::Object was set using the css() method. This should be set by Markdown::Parser::parse_table" ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->css || (return $self->error('No CSS::Object was set using the css() method. This should be set by Markdown::Parser::parse_table'))
MC/DC0%0/1
$self->css || (return $self->error('No CSS::Object was set using the css() method. This should be set by Markdown::Parser::parse_table'))
$self->css
Truth table0%0/2
A
A= $self->css
| |||||||||||||||||||||||||||||
| 46 | 0 | my $b = $css->builder; | |||||||||||||||||||||||||||
| 47 | 0 | my $id = Scalar::Util::refaddr( $self ); | |||||||||||||||||||||||||||
| 48 | 0 | my $stat = $self->stat; | |||||||||||||||||||||||||||
| 49 | 0 | my $cols = $self->new_array; | |||||||||||||||||||||||||||
| 50 | 0 | my $total_cols = $stat->{cols}->{total}; | |||||||||||||||||||||||||||
| 51 | 0 | my $total_rows = $stat->{rows}->{total}; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | for( my $i = 0; $i < $total_cols; $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||
| 54 | 0 | $cols->push( sprintf( '%dpx', int( $stat->{cols}->{ $i } ) * 8 ) ) | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | # .grid | ||||||||||||||||||||||||||||
| 57 | # { | ||||||||||||||||||||||||||||
| 58 | # display: grid; | ||||||||||||||||||||||||||||
| 59 | # grid-template-columns: repeat( 4, 1fr ); | ||||||||||||||||||||||||||||
| 60 | # grid-template-rows: repeat( 3, 1fr ); | ||||||||||||||||||||||||||||
| 61 | # gap: 1px 1px; | ||||||||||||||||||||||||||||
| 62 | # } | ||||||||||||||||||||||||||||
| 63 | ## Create the css for this table | ||||||||||||||||||||||||||||
| 64 | 0 | my $grid = $b->select( [".grid-${id}"] ) | |||||||||||||||||||||||||||
| 65 | ->display( 'grid' ) | ||||||||||||||||||||||||||||
| 66 | ->grid_template_columns( $cols->join( ' ' ) ) | ||||||||||||||||||||||||||||
| 67 | ->grid_template_rows( sprintf( 'repeat %d, 1fr', $total_rows ) ) | ||||||||||||||||||||||||||||
| 68 | ->gap( '1px 1px' ); | ||||||||||||||||||||||||||||
| 69 | ## Set the table header css rule | ||||||||||||||||||||||||||||
| 70 | 0 | my $hdr_rule = $css->get_rule_by_selector( '.table-header' ); | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | unless( $hdr_rule ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 0 | $b->select( ['.table-header'] ) | |||||||||||||||||||||||||||
| 74 | ->font_weight( 'bold' ); | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 0 | my $arr = $self->new_array; | |||||||||||||||||||||||||||
| 77 | 0 | my $cap = $self->caption; | |||||||||||||||||||||||||||
| 78 | 0 | my $hdr = $self->header; | |||||||||||||||||||||||||||
| 79 | 0 | my $bodies = $self->bodies; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | $arr->push( $cap->as_css_grid ) if( $cap ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | $arr->push( "<div class=\"grid-${id}\">" ); | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | if( $hdr ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||
| 84 | 0 | $arr->push( $hdr->as_css_grid ); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | $bodies->for(sub | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 88 | 0 | my( $i, $body ) = @_; | |||||||||||||||||||||||||||
| 89 | ## If there is more than one body, we separate them with one blank line | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $arr->push( "\n" ) if( $i > 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | $arr->push( $body->as_css_grid ); | |||||||||||||||||||||||||||
| 92 | 0 | $arr->push( "\n" ); | |||||||||||||||||||||||||||
| 93 | 0 | }); | |||||||||||||||||||||||||||
| 94 | 0 | $arr->push( "</div>" ); | |||||||||||||||||||||||||||
| 95 | 0 | $self->{_as_css_grid} = $arr->join( "\n" )->scalar; | |||||||||||||||||||||||||||
| 96 | 0 | return( $self->{_as_css_grid} ); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub as_markdown | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
as_markdown: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | return( $self->{_as_mardown} ) if( $self->{_as_mardown} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | my $arr = $self->new_array; | |||||||||||||||||||||||||||
| 104 | 0 | my $cap = $self->caption; | |||||||||||||||||||||||||||
| 105 | 0 | my $hdr = $self->header; | |||||||||||||||||||||||||||
| 106 | 0 | my $bodies = $self->bodies; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $arr->push( ' ' . $cap->as_markdown ) if( $cap && $cap->position eq 'top' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cap and $cap->position eq "top"
MC/DC0%0/2
$cap and $cap->position eq "top"
$cap
$cap->position eq "top"
Truth table0%0/3
A and B
A= $capB= $cap->position eq "top"
| |||||||||||||||||||||||||||||
| 109 | 0 | my $tag = $self->tag_name; | |||||||||||||||||||||||||||
| 110 | 0 | my $tag_open = $tag; | |||||||||||||||||||||||||||
| 111 | 0 | my $tmp = $self->new_array; | |||||||||||||||||||||||||||
| 112 | 0 | $tmp->push( "<$tag_open" ); | |||||||||||||||||||||||||||
| 113 | 0 | my $attr = $self->new_array; | |||||||||||||||||||||||||||
| 114 | 0 | ▶ | $attr->push( $self->format_id ) if( $self->id->length ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $attr->push( $self->format_class ) if( $self->class->length ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | my $attributes = $self->format_attributes; | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $tmp->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | $tmp->push( '>' ); | |||||||||||||||||||||||||||
| 120 | 0 | $arr->push( $tmp->join( '' )->scalar ); | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | if( $hdr ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||
| 123 | 0 | $arr->push( $hdr->as_markdown ); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | $arr->push( "\n" ) if( $bodies->length ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | $bodies->for(sub | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 129 | 0 | my( $i, $body ) = @_; | |||||||||||||||||||||||||||
| 130 | ## If there is more than one body, we separate them with one blank line | ||||||||||||||||||||||||||||
| 131 | 0 | ▶ | $arr->push( "\n" ) if( $i > 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | $arr->push( $body->as_markdown ); | |||||||||||||||||||||||||||
| 133 | 0 | $arr->push( "\n" ); | |||||||||||||||||||||||||||
| 134 | 0 | }); | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | $arr->push( ' ' . $cap->as_markdown ) if( $cap && $cap->position eq 'bottom' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cap and $cap->position eq "bottom"
MC/DC0%0/2
$cap and $cap->position eq "bottom"
$cap
$cap->position eq "bottom"
Truth table0%0/3
A and B
A= $capB= $cap->position eq "bottom"
| |||||||||||||||||||||||||||||
| 136 | 0 | $self->{_as_mardown} = $arr->join( '' )->scalar; | |||||||||||||||||||||||||||
| 137 | 0 | return( $self->{_as_mardown} ); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | sub as_pod | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
as_pod: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | return( $self->{_as_pod} ) if( $self->{_as_pod} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | my $arr = $self->new_array; | |||||||||||||||||||||||||||
| 145 | 0 | my $cap = $self->caption; | |||||||||||||||||||||||||||
| 146 | 0 | my $hdr = $self->header; | |||||||||||||||||||||||||||
| 147 | 0 | my $bodies = $self->bodies; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | $arr->push( ' ' . $cap->as_pod ) if( $cap && $cap->position eq 'top' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cap and $cap->position eq "top"
MC/DC0%0/2
$cap and $cap->position eq "top"
$cap
$cap->position eq "top"
Truth table0%0/3
A and B
A= $capB= $cap->position eq "top"
| |||||||||||||||||||||||||||||
| 150 | 0 | my $tag = $self->tag_name; | |||||||||||||||||||||||||||
| 151 | 0 | my $tag_open = $tag; | |||||||||||||||||||||||||||
| 152 | 0 | ▶ | if( $hdr ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||
| 154 | 0 | $arr->push( $hdr->as_pod ); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | $arr->push( "\n" ) if( $bodies->length ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | $bodies->for(sub | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 160 | 0 | my( $i, $body ) = @_; | |||||||||||||||||||||||||||
| 161 | # If there is more than one body, we separate them with one blank line | ||||||||||||||||||||||||||||
| 162 | 0 | ▶ | $arr->push( "\n" ) if( $i > 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 0 | $arr->push( $body->as_pod ); | |||||||||||||||||||||||||||
| 164 | 0 | $arr->push( "\n" ); | |||||||||||||||||||||||||||
| 165 | 0 | }); | |||||||||||||||||||||||||||
| 166 | 0 | ▶ | $arr->push( ' ' . $cap->as_pod ) if( $cap && $cap->position eq 'bottom' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cap and $cap->position eq "bottom"
MC/DC0%0/2
$cap and $cap->position eq "bottom"
$cap
$cap->position eq "bottom"
Truth table0%0/3
A and B
A= $capB= $cap->position eq "bottom"
| |||||||||||||||||||||||||||||
| 167 | 0 | $self->{_as_pod} = $arr->join( '' )->scalar; | |||||||||||||||||||||||||||
| 168 | 0 | return( $self->{_as_pod} ); | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # Ref: https://www.w3schools.com/TAgs/tag_col.asp | ||||||||||||||||||||||||||||
| 172 | sub as_string | ||||||||||||||||||||||||||||
| 173 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 174 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 175 | 0 | ▶ | return( $self->as_css_grid ) if( $self->use_css_grid ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 0 | my $arr = $self->new_array; | |||||||||||||||||||||||||||
| 177 | 0 | my $tag = $self->tag_name; | |||||||||||||||||||||||||||
| 178 | 0 | my $tag_open = $tag; | |||||||||||||||||||||||||||
| 179 | 0 | my $caption = $self->caption; | |||||||||||||||||||||||||||
| 180 | 0 | $arr->push( "<$tag_open>" ); | |||||||||||||||||||||||||||
| 181 | 0 | ▶ | $arr->push( $caption->as_string ) if( $caption ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if( $self->header->children->length ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | { | ||||||||||||||||||||||||||||
| 184 | 0 | $arr->push( $self->header->as_string ); | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if( $self->bodies->length ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||
| 188 | $self->bodies->foreach(sub | ||||||||||||||||||||||||||||
| 189 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 190 | 0 | $arr->push( $_->as_string ); | |||||||||||||||||||||||||||
| 191 | 0 | }); | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | 0 | $arr->push( "</$tag>" ); | |||||||||||||||||||||||||||
| 194 | 0 | return( $arr->join( "\n" )->scalar ); | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | sub add_body | ||||||||||||||||||||||||||||
| 198 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add_body: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 200 | 0 | ▶ | my $val = shift( @_ ) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return)
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 201 | 0 | my $base = $self->base_class; | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | return( $self->error( "Value provided (", overload::StrVal( $val ), ") is not a ${base}::TableBody object" ) ) if( !$self->_is_a( $val, "${base}::TableBody" ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | $val->parent( $self ); | |||||||||||||||||||||||||||
| 204 | 0 | $self->bodies->push( $val ); | |||||||||||||||||||||||||||
| 205 | 0 | return( $val ); | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | sub add_header | ||||||||||||||||||||||||||||
| 209 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add_header: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 210 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 211 | 0 | ▶ | my $val = shift( @_ ) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return)
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 212 | 0 | my $base = $self->base_class; | |||||||||||||||||||||||||||
| 213 | 0 | ▶ | return( $self->error( "Value provided (", overload::StrVal( $val ), ") is not a ${base}::TableHeader object" ) ) if( !$self->_is_a( $val, "${base}::TableHeader" ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 0 | $val->parent( $self ); | |||||||||||||||||||||||||||
| 215 | 0 | $self->headers->push( $val ); | |||||||||||||||||||||||||||
| 216 | 0 | return( $val ); | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub bodies { return( shift->_set_get_object_array_object( 'bodies', 'Markdown::Parser::TableBody', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
bodies: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | # Alias | ||||||||||||||||||||||||||||
| 222 | 0 | ▶ | sub body { return( shift->bodies( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
body: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | sub caption | ||||||||||||||||||||||||||||
| 225 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
caption: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 226 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 227 | 0 | my $base = $self->base_class; | |||||||||||||||||||||||||||
| 228 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||
| 230 | 0 | my $val = shift( @_ ); | |||||||||||||||||||||||||||
| 231 | 0 | ▶ | return( $self->error( "Value provided (", overload::StrVal( $val ), ") is not a ${base}::TableCaption object" ) ) if( !$self->_is_a( $val, "${base}::TableCaption" ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 0 | $val->parent( $self ); | |||||||||||||||||||||||||||
| 233 | 0 | $self->_set_get_object( 'caption', "${base}::TableCaption", $val ); | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | 0 | return( $self->_set_get_object( 'caption', "${base}::TableCaption" ) ); | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | sub header | ||||||||||||||||||||||||||||
| 239 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
header: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 240 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 241 | 0 | my $base = $self->base_class; | |||||||||||||||||||||||||||
| 242 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||
| 244 | 0 | ▶ | my $val = shift( @_ ) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return)
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 245 | 0 | ▶ | return( $self->error( "Value provided (", overload::StrVal( $val ), ") is not a ${base}::TableHeader object" ) ) if( !$self->_is_a( $val, "${base}::TableHeader" ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 0 | $val->parent( $self ); | |||||||||||||||||||||||||||
| 247 | 0 | $self->_set_get_object( 'header', "${base}::TableHeader", $val ); | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | 0 | return( $self->_set_get_object( 'header', "${base}::TableHeader" ) ); | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | sub headers { return( shift->_set_get_object_array_object( 'headers', 'Markdown::Parser::TableHeader', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
headers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | sub remove_body | ||||||||||||||||||||||||||||
| 255 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
remove_body: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 256 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 257 | 0 | ▶ | my $val = shift( @_ ) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return)
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 258 | 0 | my $base = $self->base_class; | |||||||||||||||||||||||||||
| 259 | 0 | ▶ | return( $self->error( "Value provided (", overload::StrVal( $val ), ") is not a ${base}::TableBody object" ) ) if( !$self->_is_a( $val, "${base}::TableBody" ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 0 | my $pos = $self->bodies->pos( $val ); | |||||||||||||||||||||||||||
| 261 | 0 | ▶ | return if( !defined( $pos ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | ## Returned an array object of element removed | ||||||||||||||||||||||||||||
| 263 | 0 | my $removed = $self->bodies->delete( $pos, 1 ); | |||||||||||||||||||||||||||
| 264 | 0 | return( $removed->[0] ); | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | sub reset_stat | ||||||||||||||||||||||||||||
| 268 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
reset_stat: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 269 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 270 | 0 | $self->stat->reset; | |||||||||||||||||||||||||||
| 271 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | # Contains an hash of property and values providing stats on the table and collected upon parsing | ||||||||||||||||||||||||||||
| 275 | # They are used to produce the html table or css grid | ||||||||||||||||||||||||||||
| 276 | # sub stat { return( shift->_set_get_hash_as_mix_object( 'stat', @_ ) ); } | ||||||||||||||||||||||||||||
| 277 | sub stat | ||||||||||||||||||||||||||||
| 278 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
stat: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 279 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 280 | 0 | my $info = $self->_set_get_hash_as_mix_object( 'stat' ); | |||||||||||||||||||||||||||
| 281 | 0 | ▶ | return( $info ) if( $info && $info->length ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$info and $info->length
MC/DC0%0/2
$info and $info->length
$info
$info->length
Truth table0%0/3
A and B
A= $infoB= $info->length
| |||||||||||||||||||||||||||||
| 282 | 0 | my $get_width; | |||||||||||||||||||||||||||
| 283 | $get_width = sub | ||||||||||||||||||||||||||||
| 284 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 285 | 0 | my $row = shift( @_ ); | |||||||||||||||||||||||||||
| 286 | $row->children->for(sub | ||||||||||||||||||||||||||||
| 287 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 288 | 0 | my( $j, $cell ) = @_; | |||||||||||||||||||||||||||
| 289 | 0 | ▶ | $info->{cols} = {} if( !ref( $info->{cols} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 0 | ▶ | return( 1 ) if( length( $info->{cols}->{ $j } ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | ## Cells are merged into 1, so we cannot get an accurate width of each cell | ||||||||||||||||||||||||||||
| 292 | 0 | ▶ | return( 1 ) if( $cell->colspan > 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if( $cell->width ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | { | ||||||||||||||||||||||||||||
| 295 | 0 | $info->{cols}->{ $j } = $cell->width; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | ## Find out the width of the cell based on its content | ||||||||||||||||||||||||||||
| 298 | else | ||||||||||||||||||||||||||||
| 299 | { | ||||||||||||||||||||||||||||
| 300 | 0 | ▶ | my $cell_data = $cell->children->map(sub{ $_->as_markdown }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 301 | ## Find the longest string in each line within this cell | ||||||||||||||||||||||||||||
| 302 | 0 | my $max = 0; | |||||||||||||||||||||||||||
| 303 | $cell_data->foreach(sub | ||||||||||||||||||||||||||||
| 304 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 305 | ## Split the string into lines | ||||||||||||||||||||||||||||
| 306 | 0 | my $lines = $self->new_array( [split( /\n/, $_ )] ); | |||||||||||||||||||||||||||
| 307 | $lines->foreach(sub | ||||||||||||||||||||||||||||
| 308 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 309 | 0 | my $l = shift( @_ ); | |||||||||||||||||||||||||||
| 310 | 0 | ▶ | $max = length( $l ) if( length( $l ) > $max ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | }); | |||||||||||||||||||||||||||
| 312 | 0 | }); | |||||||||||||||||||||||||||
| 313 | ## Add 1 space on each side | ||||||||||||||||||||||||||||
| 314 | 0 | $max += 2; | |||||||||||||||||||||||||||
| 315 | 0 | $info->{cols}->{ $j } = $max; | |||||||||||||||||||||||||||
| 316 | 0 | $cell->width( $max ); | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | 0 | }); | |||||||||||||||||||||||||||
| 319 | 0 | }; | |||||||||||||||||||||||||||
| 320 | ## Or else, collect stats | ||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if( my $hdr = $self->header ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | { | ||||||||||||||||||||||||||||
| 323 | $hdr->children->for(sub | ||||||||||||||||||||||||||||
| 324 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 325 | 0 | my( $i, $row ) = @_; | |||||||||||||||||||||||||||
| 326 | 0 | $get_width->( $row ); | |||||||||||||||||||||||||||
| 327 | 0 | }); | |||||||||||||||||||||||||||
| 328 | ## Number of rows in the header | ||||||||||||||||||||||||||||
| 329 | 0 | $info->{header}->{rows} = $hdr->children->length; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | $self->bodies->foreach(sub | ||||||||||||||||||||||||||||
| 332 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 333 | 0 | my $body = shift( @_ ); | |||||||||||||||||||||||||||
| 334 | $body->children->foreach(sub | ||||||||||||||||||||||||||||
| 335 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 336 | 0 | my $row = shift( @_ ); | |||||||||||||||||||||||||||
| 337 | 0 | $get_width->( $row ); | |||||||||||||||||||||||||||
| 338 | 0 | }); | |||||||||||||||||||||||||||
| 339 | 0 | ▶ | $info->{rows} = {} if( !ref( $info->{rows} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | ## Number of rows in the body | ||||||||||||||||||||||||||||
| 341 | 0 | $info->{rows}->{total} += $body->children->length; | |||||||||||||||||||||||||||
| 342 | 0 | }); | |||||||||||||||||||||||||||
| 343 | 0 | $info->{cols}->{total} = scalar( keys( %{$info->{cols}} ) ); | |||||||||||||||||||||||||||
| 344 | 0 | foreach my $col_n ( keys( %{$info->{cols}} ) ) | |||||||||||||||||||||||||||
| 345 | { | ||||||||||||||||||||||||||||
| 346 | 0 | $info->{table}->{width} += $info->{cols}->{ $col_n }; | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | 0 | return( $info ); | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 0 | ▶ | sub use_css_grid { return( shift->_set_get_boolean( 'use_css_grid', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
use_css_grid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 1 | 1; | |||||||||||||||||||||||||||
| 354 | # NOTE: POD | ||||||||||||||||||||||||||||
| 355 | __END__ | ||||||||||||||||||||||||||||