lib/Markdown/Parser/TableHeader.pm

filter: Statementstmt 24.7% 23 / 93 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 38.1% 8 / 21 Podpod 100% 6 / 6 totaltotal 26.4% 37 / 140 CC 11 SCAR 23.8
CC
11
Cov
20%
as_string
42.0
as_css_grid
6.0
as_markdown
6.0
CRAP 10.8
« lib/Markdown/Parser/TableBody.pm ↑ Summary blib/lib/Markdown/Parser/Paragraph.pm »
1 ##----------------------------------------------------------------------------
2 ## Markdown Parser Only - ~/lib/Markdown/Parser/TableHeader.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::TableHeader;
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->{rows} = [];
31 0 $self->{tag_name} = 'thead';
32 0 $self->{_as_markdown} = '';
33 0 return( $self->SUPER::init( @_ ) );
34 }
35  
36 sub as_css_grid
37 {
38 0 ▶ my $self = shift( @_ );
Subroutine as_css_grid: not called CC=2 SCAR=17.9
Pod documented
39 0 ▶ return( $self->{_as_css_grid} ) if( $self->{_as_css_grid} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_as_css_grid"} 0 0 0
40 0 my $row_data = $self->new_array;
41 ## Check each row
42 $self->children->for(sub
43 {
44 0 ▶ my( $i, $row ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 ## Set the class header for cell of the header row
46 0 ▶ $row->children->map(sub{ $_->class( 'table-header' ) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 $row_data->push( $row->as_css_grid->scalar );
48 0 });
49 0 $self->{_as_css_grid} = $row_data->join( "\n" )->scalar;
50 0 return( $self->{_as_css_grid} );
51 }
52  
53 sub as_markdown
54 {
55 0 ▶ my $self = shift( @_ );
Subroutine as_markdown: not called CC=2 SCAR=17.9
Pod documented
56 0 ▶ return( $self->{_as_markdown} ) if( $self->{_as_markdown} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_as_markdown"} 0 0 0
57 0 my $row_data = $self->new_array;
58 # Check each row
59 $self->children->for(sub
60 {
61 0 ▶ my( $i, $row ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
62 0 my $sep = $self->new_array;
63 0 $sep->push( '+' );
64 $row->children->foreach(sub
65 {
66 0 ▶ my $cell = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 $sep->push( ( '-' x $cell->width ) . '+' );
68 0 });
69 # Push top horizontal line if this is the first upper line
70 0 ▶ $row_data->push( $sep->join( '' )->scalar ) if( $i == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 0 0 0
71 0 my $row_str = $row->as_markdown;
72 0 $row_data->push( $row_str->scalar );
73 0 $row_data->push( $sep->join( '' )->scalar );
74 0 });
75 0 $self->{_as_markdown} = $row_data->join( "\n" )->scalar;
76 0 return( $self->{_as_markdown} );
77 }
78  
79 sub as_pod
80 {
81 0 ▶ my $self = shift( @_ );
Subroutine as_pod: not called CC=2 SCAR=17.9
Pod documented
82 0 ▶ return( $self->{_as_pod} ) if( $self->{_as_pod} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_as_pod"} 0 0 0
83 0 my $row_data = $self->new_array;
84 # Check each row
85 $self->children->for(sub
86 {
87 0 ▶ my( $i, $row ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
88 0 my $sep = $self->new_array;
89 0 $sep->push( '+' );
90 $row->children->foreach(sub
91 {
92 0 ▶ my $cell = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
93 0 $sep->push( ( '-' x $cell->width ) . '+' );
94 0 });
95 # Push top horizontal line if this is the first upper line
96 0 ▶ $row_data->push( $sep->join( '' )->scalar ) if( $i == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 0 0 0
97 0 my $row_str = $row->as_pod;
98 0 $row_data->push( $row_str->scalar );
99 0 $row_data->push( $sep->join( '' )->scalar );
100 0 });
101 0 $self->{_as_pod} = $row_data->join( "\n" )->scalar;
102 0 return( $self->{_as_pod} );
103 }
104  
105 sub as_string
106 {
107 0 ▶ my $self = shift( @_ );
Subroutine as_string: not called CC=6 SCAR=37.4
Pod documented
108 0 ▶ return( $self->{_as_string} ) if( $self->{_as_string} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_as_string"} 0 0 0
109 0 my $arr = $self->new_array;
110 0 my $tag = $self->tag_name;
111 0 my $tag_open = $tag;
112 0 my $tmp = $self->new_array;
113 0 $tmp->push( "<$tag_open" );
114 0 my $attr = $self->new_array;
115 0 ▶ $attr->push( $self->format_id ) if( $self->id->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->id->length 0 0 0
116 0 ▶ $attr->push( $self->format_class ) if( $self->class->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->class->length 0 0 0
117 0 my $attributes = $self->format_attributes;
118 0 ▶ $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attributes->length 0 0 0
119 0 ▶ $tmp->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attr->length 0 0 0
120 0 $tmp->push( '>' );
121 0 $arr->push( $tmp->join( '' )->scalar );
122 $arr->push( $self->children->map(sub
123 {
124 0 ▶ $_->as_string;
Subroutine __ANON__: not called CC=1 SCAR=6.9
125 0 })->list );
126 0 $arr->push( "</$tag>" );
127 0 $self->{_as_string} = $arr->join( "\n" )->scalar;
128 0 return( $self->{_as_string} );
129 }
130  
131 sub reset
132 {
133 0 ▶ my $self = shift( @_ );
Subroutine reset: not called CC=1 SCAR=6.9
Pod documented
134 0 delete( @$self{ qw( _as_css_grid _as_markdown _as_string ) } );
135 0 return( $self );
136 }
137  
138 1 1;
139 # NOTE: POD
140 __END__
« lib/Markdown/Parser/TableBody.pm ↑ Summary blib/lib/Markdown/Parser/Paragraph.pm »