lib/Markdown/Parser/Header.pm

filter: Statementstmt 33.8% 23 / 68 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.1% 8 / 19 Podpod 100% 7 / 7 totaltotal 33.6% 38 / 113 CC 9 SCAR 28.2
CC
9
Cov
27%
as_string
56.0
init
12.0
append
2.0
CRAP 16.8
« lib/Markdown/Parser/Bold.pm ↑ Summary blib/lib/Markdown/Parser/Insertion.pm »
1 ##----------------------------------------------------------------------------
2 ## Markdown Parser Only - ~/lib/Markdown/Parser/Header.pm
3 ## Version v0.2.1
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/08/23
7 ## Modified 2022/09/22
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::Header;
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.1';
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=3 SCAR=24.8
Pod documented
30 0 $self->{id} = [];
31 0 $self->{level} = 0;
32 0 $self->{tag_name} = 'header';
33 0 $self->SUPER::init( @_ );
34 # If the header level is not set yet and we have some raw data, let's guess it from the raw data provided
35 0 ▶ if( !$self->level && $self->raw->length )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->level and $self->raw->length) 0 0 0
Condition0%0/3
not $self->level and $self->raw->length
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->level and $self->raw->length
not $self->level $self->raw->length
Truth table0%0/3
not(A) and B
A= not $self->levelB= $self->raw->length
ABresult
0X0
100
111
36 {
37 # # is level 1, ## is level 2, etc...
38 0 my $raw = $self->raw;
39 0 $self->level( length( ( $raw =~ /^(\#+)/ )[0] ) );
40 }
41 0 return( $self );
42 }
43  
44 0 ▶sub append { return( shift->_append_text( @_ ) ); }
Subroutine append: not called CC=1 SCAR=6.9
Pod documented
45  
46 sub as_markdown
47 {
48 0 ▶ my $self = shift( @_ );
Subroutine as_markdown: not called CC=1 SCAR=6.9
Pod documented
49 0 ▶ my $str = $self->children->map(sub{ $_->as_markdown })->join( '' );
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 my $level = $self->level;
51 0 my $marker = '#' x $level;
52 0 return( "${marker} ${str}" );
53 }
54  
55 sub as_pod
56 {
57 0 ▶ my $self = shift( @_ );
Subroutine as_pod: not called CC=1 SCAR=6.9
Pod documented
58 0 ▶ my $str = $self->children->map(sub{ $_->as_pod })->join( '' );
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 0 my $level = $self->level;
60 0 my $marker = '=head' . $level;
61 0 return( "${marker} ${str}\n" );
62 }
63  
64 sub as_string
65 {
66 0 ▶ my $self = shift( @_ );
Subroutine as_string: not called CC=7 SCAR=40.3
Pod documented
67 0 my $arr = $self->new_array;
68 0 my $tag = 'h' . $self->level;
69 0 my $tag_open = $tag;
70 0 ▶ if( $self->id->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->id->length) 0 0 0
71 {
72 0 ▶ $tag_open .= ' ' . $self->id->map(sub{ sprintf( 'id="%s"', $_ ) })->join( ' ' )->scalar;
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 }
74 0 ▶ if( $self->class->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->class->length) 0 0 0
75 {
76 0 $tag_open .= ' class="' . $self->class->join( ' ' )->scalar . '"';
77 }
78 0 $arr->push( "<$tag_open" );
79 0 my $attr = $self->new_array;
80 0 ▶ $attr->push( $self->format_id ) if( $self->id->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->id->length 0 0 0
81 0 ▶ $attr->push( $self->format_class ) if( $self->class->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->class->length 0 0 0
82 0 my $attributes = $self->format_attributes;
83 0 ▶ $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attributes->length 0 0 0
84 0 ▶ $arr->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attr->length 0 0 0
85 0 $arr->push( '>' );
86 $arr->push( $self->children->map(sub
87 {
88 0 ▶ $_->as_string;
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 0 })->list );
90 0 $arr->push( "</$tag>" );
91 0 return( $arr->join( '' )->scalar );
92 }
93  
94 0 ▶sub id { return( shift->_set_get_array_as_object( 'id', @_ ) ); }
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
95  
96 0 ▶sub level { return( shift->_set_get_number_as_object( 'level', @_ ) ); }
Subroutine level: not called CC=1 SCAR=6.9
Pod documented
97  
98 1 1;
99 # NOTE: POD
100 __END__
« lib/Markdown/Parser/Bold.pm ↑ Summary blib/lib/Markdown/Parser/Insertion.pm »