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

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 89 CC 7 SCAR 27.6
CC
7
Cov
0%
as_string
42.0
as_markdown
6.0
BEGIN
2.0
CRAP 15.8
1 ## -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## Markdown Parser Only - ~/lib/Markdown/Parser/Emphasis.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::Emphasis;
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} = 'em';
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 = '*' if( $type ne '*' && $type ne '_' );
41 return( "${type}${str}${type}" );
42 }
43  
44 sub as_pod
45 {
46 my $self = shift( @_ );
47 my $str = $self->children->map(sub{ $_->as_pod })->join( '' );
48 return( "I<${str}>" );
49 }
50  
51 sub as_string
52 {
53 my $self = shift( @_ );
54 my $arr = $self->new_array;
55 my $tag = 'em';
56 my $tag_open = $tag;
57 $arr->push( "<${tag_open}" );
58 my $attr = $self->new_array;
59 $attr->push( $self->format_id ) if( $self->id->length );
60 $attr->push( $self->format_class ) if( $self->class->length );
61 my $attributes = $self->format_attributes;
62 $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
63 $arr->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length );
64 $arr->push( '>' );
65 $arr->push( $self->children->map(sub{ $_->as_string })->list ) if( $self->children->length );
66 $arr->push( "</${tag}>" );
67 return( $arr->join( '' )->scalar );
68 }
69  
70 sub type { return( shift->_set_get_scalar_as_object( 'type', @_ ) ); }
71  
72 1;
73 # NOTE: POD
74 __END__