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

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 84 CC 7 SCAR 23.7
CC
7
Cov
0%
as_string
30.0
as_markdown
6.0
as_pod
6.0
CRAP 10.7
1 ##----------------------------------------------------------------------------
2 ## Markdown Parser Only - ~/lib/Markdown/Parser/TableCaption.pm
3 ## Version v0.3.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/08/23
7 ## Modified 2024/08/30
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 our $VERSION = 'v0.3.0';
21 };
22  
23 use strict;
24 use warnings;
25  
26 sub init
27 {
28 my $self = shift( @_ );
29 $self->{position} = 'top';
30 $self->{tag_name} = 'caption';
31 return( $self->SUPER::init( @_ ) );
32 }
33  
34 sub as_markdown
35 {
36 my $self = shift( @_ );
37 return( $self->{_as_markdown} ) if( $self->{_as_markdown} );
38 $self->{_as_markdown} = sprintf( ' [%s]', $self->children->map(sub{ $_->as_markdown })->join( '' )->scalar );
39 return( $self->{_as_markdown} );
40 }
41  
42 sub as_pod
43 {
44 my $self = shift( @_ );
45 return( $self->{_as_pod} ) if( $self->{_as_pod} );
46 $self->{_as_pod} = sprintf( ' [%s]', $self->children->map(sub{ $_->as_pod })->join( '' )->scalar );
47 return( $self->{_as_pod} );
48 }
49  
50 sub as_string
51 {
52 my $self = shift( @_ );
53 my $tag = $self->tag_name;
54 my $tag_open = $tag;
55 my $arr = $self->new_array;
56 $arr->push( "<$tag_open" );
57 my $attr = $self->new_array;
58 $attr->push( $self->format_id ) if( $self->id->length );
59 $attr->push( $self->format_class ) if( $self->class->length );
60 my $attributes = $self->format_attributes;
61 $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
62 $arr->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length );
63 $arr->push( '>' );
64 $arr->push( $self->children->map(sub{ $_->as_string })->join( "\n" )->scalar );
65 $arr->push( "</$tag>" );
66 return( $arr->join( '' )->scalar );
67 }
68  
69 ## 'top' or 'bottom' of the table
70 sub position { return( shift->_set_get_scalar_as_object( 'position', @_ ) ); }
71  
72 1;
73 # NOTE: POD
74 __END__