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

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 89 CC 5 SCAR 23.7
CC
5
Cov
0%
as_string
30.0
BEGIN
2.0
init
2.0
CRAP 10.8
1 ## -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## Markdown Parser Only - ~/lib/Markdown/Parser/Blockquote.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::Blockquote;
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} = 'blockquote';
31 return( $self->SUPER::init( @_ ) );
32 }
33  
34 sub append { return( shift->_append_text( @_ ) ); }
35  
36 sub as_markdown
37 {
38 my $self = shift( @_ );
39 my $str = $self->children->map(sub{ $_->as_markdown })->join( "\n" );
40 my $lines = $str->split( "\n" );
41 $lines->for(sub
42 {
43 my( $i, $val ) = @_;
44 substr( $lines->[ $i ], 0, 0 ) = '> ';
45 });
46 return( $lines->join( "\n" )->scalar );
47 }
48  
49 sub as_pod
50 {
51 my $self = shift( @_ );
52 my $str = $self->children->map(sub{ $_->as_pod })->join( "\n" );
53 my $lines = $str->split( "\n" );
54 $lines->for(sub
55 {
56 my( $i, $val ) = @_;
57 substr( $lines->[ $i ], 0, 0 ) = ' ';
58 });
59 return( $lines->join( "\n" )->scalar );
60 }
61  
62 sub as_string
63 {
64 my $self = shift( @_ );
65 my $arr = $self->new_array;
66 my $tag = $self->tag_name;
67 my $tag_open = $tag;
68 my $tmp = $self->new_array;
69 $tmp->push( "<$tag_open" );
70 my $attr = $self->new_array;
71 $attr->push( $self->format_id ) if( $self->id->length );
72 $attr->push( $self->format_class ) if( $self->class->length );
73 my $attributes = $self->format_attributes;
74 $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
75 $tmp->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length );
76 $tmp->push( '>' );
77 $arr->push( $tmp->join( '' )->scalar );
78 $arr->push( $self->children->map(sub
79 {
80 $_->as_string;
81 })->list );
82 $arr->push( "</$tag>\n" );
83 return( $arr->join( "\n" )->scalar );
84 }
85  
86 1;
87 # NOTE: POD
88 __END__