lib/Markdown/Parser/List.pm

filter: Statementstmt 33.3% 26 / 78 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 45.0% 9 / 20 Podpod 100% 6 / 6 totaltotal 32.0% 41 / 128 CC 13 SCAR 26.4
CC
13
Cov
25%
as_string
42.0
__ANON__
20.0
__ANON__
20.0
CRAP 14.0
« blib/lib/Markdown/Parser/TableBody.pm ↑ Summary lib/Markdown/Parser/Subscript.pm »
1 ##----------------------------------------------------------------------------
2 ## Markdown Parser Only - ~/lib/Markdown/Parser/List.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::List;
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 ▶ use constant TAB_SPACES => ' ';
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->{indent} = '';
32 0 $self->{order} = '';
33 0 $self->{tag_name} = 'list';
34 0 return( $self->SUPER::init( @_ ) );
35 }
36  
37 sub as_markdown
38 {
39 0 ▶ my $self = shift( @_ );
Subroutine as_markdown: not called CC=1 SCAR=6.9
Pod documented
40 0 my $base_class = $self->base_class;
41 0 my $order_list = $self->order;
42 0 my $n = 0;
43 $self->children->foreach(sub
44 {
45 0 ▶ my $li = shift( @_ );
Subroutine __ANON__: not called CC=4 SCAR=30.0
46 # Skip unless this child it a list item
47 0 ▶ return(1) unless( $li->isa( "${base_class}::ListItem" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $li->isa("${base_class}::ListItem") 0 0 0
48 0 $n++;
49 0 ▶ if( $order_list )
Branch: 2 branches
BranchTrueFalseTotal
if ($order_list) { } 0 0 0
elsif (not $li->type->length) { } 0 0 0
50 {
51 0 $li->type( "${n}." );
52 }
53 elsif( !$li->type->length )
54 {
55 0 $li->type( '*' );
56 }
57 0 });
58 0 ▶ return( $self->children->map(sub{ $_->as_markdown })->join( "\n" )->scalar );
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 }
60  
61 # Basically same as markdown
62 sub as_pod
63 {
64 0 ▶ my $self = shift( @_ );
Subroutine as_pod: not called CC=2 SCAR=17.9
Pod documented
65 0 my $base_class = $self->base_class;
66 0 my $order_list = $self->order;
67 0 my $n = 0;
68 $self->children->foreach(sub
69 {
70 0 ▶ my $li = shift( @_ );
Subroutine __ANON__: not called CC=4 SCAR=30.0
71 # Skip unless this child it a list item
72 0 ▶ return(1) unless( $li->isa( "${base_class}::ListItem" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $li->isa("${base_class}::ListItem") 0 0 0
73 0 $n++;
74 0 ▶ if( $order_list )
Branch: 2 branches
BranchTrueFalseTotal
if ($order_list) { } 0 0 0
elsif (not $li->type->length) { } 0 0 0
75 {
76 0 $li->type( "${n}." );
77 }
78 elsif( !$li->type->length )
79 {
80 0 $li->type( '*' );
81 }
82 0 });
83 0 my $indent = $self->indent;
84 0 ▶ $indent = 4 unless( $indent > 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless $indent > 0 0 0 0
85 0 ▶ return( "=over ${indent}\n\n" . $self->children->map(sub{ $_->as_pod })->join( "\n\n" )->scalar . "\n\n=back" );
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 }
87  
88 sub as_string
89 {
90 0 ▶ my $self = shift( @_ );
Subroutine as_string: not called CC=6 SCAR=37.4
Pod documented
91 0 my $arr = $self->new_array;
92 0 ▶ my $tag = $self->order ? 'ol' : 'ul';
Branch: 1 branch
BranchTrueFalseTotal
$self->order ? : 0 0 0
93 0 my $tag_open = $tag;
94 0 my $tmp = $self->new_array( [ "<$tag_open" ] );
95 0 my $attr = $self->new_array;
96 0 ▶ $attr->push( $self->format_id ) if( $self->id->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->id->length 0 0 0
97 0 ▶ $attr->push( $self->format_class ) if( $self->class->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->class->length 0 0 0
98 0 my $attributes = $self->format_attributes;
99 0 ▶ $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attributes->length 0 0 0
100 0 ▶ $tmp->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attr->length 0 0 0
101 0 $tmp->push( '>' );
102
103 0 $arr->push( ( TAB_SPACES x $self->indent ) . $tmp->join( '' )->scalar );
104 # my $ct = $self->new_array;
105 $arr->push( $self->children->map(sub
106 {
107 0 ▶ $_->as_string;
Subroutine __ANON__: not called CC=1 SCAR=6.9
108 0 })->list );
109 0 $arr->push( ( TAB_SPACES x $self->indent ) . "</$tag>" );
110 0 return( $arr->join( "\n" )->scalar );
111 }
112  
113 0 ▶sub indent { return( shift->_set_get_number_as_object( 'indent', @_ ) ); }
Subroutine indent: not called CC=1 SCAR=6.9
Pod documented
114  
115 0 ▶sub order { return( shift->_set_get_boolean( 'order', @_ ) ); }
Subroutine order: not called CC=1 SCAR=6.9
Pod documented
116  
117 1 1;
118 # NOTE: POD
119 __END__
« blib/lib/Markdown/Parser/TableBody.pm ↑ Summary lib/Markdown/Parser/Subscript.pm »