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

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 93 CC 7 SCAR 27.1
CC
7
Cov
0%
as_string
42.0
as_markdown
6.0
BEGIN
2.0
CRAP 15.1
1 ## -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## Markdown Parser Only - ~/lib/Markdown/Parser/Emphasis.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::Emphasis;
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} = 'em';
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 = '*' 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( "I<${str}>" );
50 }
51  
52 sub as_string
53 {
54 my $self = shift( @_ );
55 my $arr = $self->new_array;
56 my $tag = 'em';
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__