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

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 92 CC 8 SCAR 27.9
CC
8
Cov
0%
as_string
42.0
as_markdown
12.0
BEGIN
2.0
CRAP 16.2
1 ## -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## Markdown Parser Only - ~/lib/Markdown/Parser/Bold.pm
4 ## Version v0.3.0
5 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
6 ## Author: Jacques Deguest <jack@deguest.jp>
7 ## Created 2021/08/23
8 ## Modified 2024/08/30
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 our $VERSION = 'v0.3.0';
22 };
23  
24 use strict;
25 use warnings;
26  
27 sub init
28 {
29 my $self = shift( @_ );
30 $self->{tag_name} = 'bold';
31 $self->{type} = '';
32 return( $self->SUPER::init( @_ ) );
33 }
34  
35 sub as_markdown
36 {
37 my $self = shift( @_ );
38 my $str = $self->children->map(sub{ $_->as_markdown })->join( '' );
39 my $type = $self->type // '**';
40 $type .= $type if( length( $type ) == 1 );
41 $type = '**' if( $type ne '**' && $type ne '__' );
42 return( "${type}${str}${type}" );
43 }
44  
45 sub as_pod
46 {
47 my $self = shift( @_ );
48 my $str = $self->children->map(sub{ $_->as_pod })->join( '' );
49 return( "B<${str}>" );
50 }
51  
52 sub as_string
53 {
54 my $self = shift( @_ );
55 my $arr = $self->new_array;
56 my $tag = 'strong';
57 my $tag_open = $tag;
58 $arr->push( "<${tag_open}" );
59 my $attr = $self->new_array;
60 $attr->push( $self->format_id ) if( $self->id->length );
61 $attr->push( $self->format_class ) if( $self->class->length );
62 my $attributes = $self->format_attributes;
63 $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
64 $arr->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length );
65 $arr->push( ">" );
66 $arr->push( $self->children->map(sub{ $_->as_string })->list ) if( $self->children->length );
67 $arr->push( "</${tag}>" );
68 return( $arr->join( '' )->scalar );
69 }
70  
71 sub type { return( shift->_set_get_scalar_as_object( 'type', @_ ) ); }
72  
73 1;
74 # NOTE: POD
75 __END__