blib/lib/Markdown/Parser/Bold.pm untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 96 CC 8 SCAR 27.4
CC
8
Cov
0%
as_string
42.0
as_markdown
12.0
BEGIN
2.0
CRAP 15.5
1 ## -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## Markdown Parser Only - ~/lib/Markdown/Parser/Bold.pm
4 ## Version v0.2.0
5 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
6 ## Author: Jacques Deguest <jack@deguest.jp>
7 ## Created 2021/08/23
8 ## Modified 2022/09/19
9 ## All rights reserved
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package Markdown::Parser::Bold;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 use parent qw( Markdown::Parser::Element );
20 use vars qw( $VERSION );
21 use Devel::Confess;
22 our $VERSION = 'v0.2.0';
23 };
24  
25 use strict;
26 use warnings;
27  
28 sub init
29 {
30 my $self = shift( @_ );
31 $self->{tag_name} = 'bold';
32 $self->{type} = '';
33 return( $self->SUPER::init( @_ ) );
34 }
35  
36 sub as_markdown
37 {
38 my $self = shift( @_ );
39 my $str = $self->children->map(sub{ $_->as_markdown })->join( '' );
40 my $type = $self->type // '**';
41 $type .= $type if( length( $type ) == 1 );
42 $type = '**' if( $type ne '**' && $type ne '__' );
43 return( "${type}${str}${type}" );
44 }
45  
46 sub as_pod
47 {
48 my $self = shift( @_ );
49 my $str = $self->children->map(sub{ $_->as_pod })->join( '' );
50 return( "B<${str}>" );
51 }
52  
53 sub as_string
54 {
55 my $self = shift( @_ );
56 my $arr = $self->new_array;
57 my $tag = 'strong';
58 my $tag_open = $tag;
59 $arr->push( "<${tag_open}" );
60 my $attr = $self->new_array;
61 $attr->push( $self->format_id ) if( $self->id->length );
62 $attr->push( $self->format_class ) if( $self->class->length );
63 my $attributes = $self->format_attributes;
64 $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
65 $arr->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length );
66 $arr->push( ">" );
67 $arr->push( $self->children->map(sub{ $_->as_string })->list ) if( $self->children->length );
68 $arr->push( "</${tag}>" );
69 return( $arr->join( '' )->scalar );
70 }
71  
72 sub type { return( shift->_set_get_scalar_as_object( 'type', @_ ) ); }
73  
74 1;
75 # NOTE: POD
76 __END__