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

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