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

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 88 CC 7 SCAR 23.2
CC
7
Cov
0%
as_string
30.0
as_markdown
6.0
as_pod
6.0
CRAP 10.2
1 ##----------------------------------------------------------------------------
2 ## Markdown Parser Only - ~/lib/Markdown/Parser/TableCaption.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/08/23
7 ## Modified 2022/09/19
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Markdown::Parser::TableCaption;
14 BEGIN
15 {
16 use strict;
17 use warnings;
18 use parent qw( Markdown::Parser::Element );
19 use vars qw( $VERSION );
20 use Devel::Confess;
21 our $VERSION = 'v0.2.0';
22 };
23  
24 use strict;
25 use warnings;
26  
27 sub init
28 {
29 my $self = shift( @_ );
30 $self->{position} = 'top';
31 $self->{tag_name} = 'caption';
32 return( $self->SUPER::init( @_ ) );
33 }
34  
35 sub as_markdown
36 {
37 my $self = shift( @_ );
38 return( $self->{_as_markdown} ) if( $self->{_as_markdown} );
39 $self->{_as_markdown} = sprintf( ' [%s]', $self->children->map(sub{ $_->as_markdown })->join( '' )->scalar );
40 return( $self->{_as_markdown} );
41 }
42  
43 sub as_pod
44 {
45 my $self = shift( @_ );
46 return( $self->{_as_pod} ) if( $self->{_as_pod} );
47 $self->{_as_pod} = sprintf( ' [%s]', $self->children->map(sub{ $_->as_pod })->join( '' )->scalar );
48 return( $self->{_as_pod} );
49 }
50  
51 sub as_string
52 {
53 my $self = shift( @_ );
54 my $tag = $self->tag_name;
55 my $tag_open = $tag;
56 my $arr = $self->new_array;
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 })->join( "\n" )->scalar );
66 $arr->push( "</$tag>" );
67 return( $arr->join( '' )->scalar );
68 }
69  
70 ## 'top' or 'bottom' of the table
71 sub position { return( shift->_set_get_scalar_as_object( 'position', @_ ) ); }
72  
73 1;
74 # NOTE: POD
75 __END__