lib/Markdown/Parser/Image.pm

filter: Statementstmt 31.5% 23 / 73 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 47.0% 8 / 17 Podpod 100% 9 / 9 totaltotal 29.8% 40 / 134 CC 15 SCAR 33.0
CC
15
Cov
22%
as_markdown
56.0
as_string
56.0
copy_from
12.0
CRAP 27.1
« blib/lib/Markdown/Parser/TableCell.pm ↑ Summary blib/lib/Markdown/Parser/ListItem.pm »
1 ## -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## Markdown Parser Only - ~/lib/Markdown/Parser/Image.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::Image;
15 BEGIN
16 {
17 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶ use parent qw( Markdown::Parser::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶ our $VERSION = 'v0.2.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 };
24  
25 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 sub init
29 {
30 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
31 0 $self->{alt} = '';
32 0 $self->{id} = [];
33 0 $self->{link_id} = '';
34 0 $self->{tag_name} = 'img';
35 0 $self->{title} = '';
36 0 $self->{url} = '';
37 0 return( $self->SUPER::init( @_ ) );
38 }
39  
40 0 ▶sub alt { return( shift->_set_get_scalar_as_object( 'alt', @_ ) ); }
Subroutine alt: not called CC=1 SCAR=6.9
Pod documented
41  
42 sub as_markdown
43 {
44 0 ▶ my $self = shift( @_ );
Subroutine as_markdown: not called CC=7 SCAR=40.3
Pod documented
45 0 my $arr = $self->new_array;
46 0 $arr->push( sprintf( '![%s]', $self->alt ) );
47 0 ▶ if( $self->id )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->id) { } 0 0 0
elsif ($self->uri or $self->title) { } 0 0 0
48 {
49 0 $arr->push( sprintf( '[%s]', $self->id ) );
50 }
51 ▶ elsif( $self->uri || $self->title )
Condition0%0/3
$self->uri or $self->title
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->uri or $self->title
$self->uri $self->title
Truth table0%0/3
A or B
A= $self->uriB= $self->title
ABresult
1X1
011
000
52 {
53 0 $arr->push( '(' );
54 0 ▶ $arr->push( sprintf( '%s', $self->uri ) ) if( $self->uri );
Branch: 1 branch
BranchTrueFalseTotal
if $self->uri 0 0 0
55 0 ▶ $arr->push( ' ' ) if( $self->uri && $self->title );
Branch: 1 branch
BranchTrueFalseTotal
if $self->uri and $self->title 0 0 0
Condition0%0/3
$self->uri and $self->title
!ll&&!rl&&r
000
MC/DC0%0/2
$self->uri and $self->title
$self->uri $self->title
Truth table0%0/3
A and B
A= $self->uriB= $self->title
ABresult
0X0
100
111
56 0 $arr->push( sprintf( '"%s"', $self->title ) );
57 0 $arr->push( ')' );
58 }
59 0 return( $arr->join( '' )->scalar );
60 }
61  
62 sub as_pod
63 {
64 0 ▶ my $self = shift( @_ );
Subroutine as_pod: not called CC=1 SCAR=6.9
Pod documented
65 0 my $arr = $self->new_array;
66 0 $arr->push( "=begin html\n" );
67 0 $arr->push( $self->as_string );
68 0 $arr->push( "\n=end html" );
69 0 return( $arr->join( "\n" )->scalar );
70 }
71  
72 sub as_string
73 {
74 0 ▶ my $self = shift( @_ );
Subroutine as_string: not called CC=7 SCAR=40.3
Pod documented
75 0 my $arr = $self->new_array;
76 0 my $tag = 'img';
77 0 my $tag_open = $tag;
78 0 $arr->push( "<${tag_open} src=\"" . $self->url . "\"" );
79 0 ▶ if( $self->alt->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->alt->length) 0 0 0
80 {
81 0 $arr->push( sprintf( 'alt="%s"', $self->encode_html( 'all', $self->alt ) ) );
82 }
83 0 ▶ if( $self->title->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->title->length) 0 0 0
84 {
85 0 $arr->push( sprintf( 'title="%s"', $self->encode_html( 'all', $self->title ) ) );
86 }
87 0 my $attr = $self->new_array;
88 0 ▶ $attr->push( $self->format_id ) if( $self->id->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->id->length 0 0 0
89 0 ▶ $attr->push( $self->format_class ) if( $self->class->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->class->length 0 0 0
90 0 my $attributes = $self->format_attributes;
91 0 ▶ $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attributes->length 0 0 0
92 0 ▶ $arr->push( $attr->join( ' ' )->scalar ) if( $attr->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attr->length 0 0 0
93 0 $arr->push( '/>' );
94 0 return( $arr->join( ' ' )->scalar );
95 }
96  
97 sub copy_from
98 {
99 0 ▶ my $self = shift( @_ );
Subroutine copy_from: not called CC=3 SCAR=24.8
Pod documented
100 0 ▶ my $def = shift( @_ ) || return( $self->error( "No link definition object was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No link definition object was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No link definition object was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
101 0 ▶ return( $self->error( "Link definition object provided to copy information from \"", overload::StrVal( $def ), "\" is not a Markdown::Parser::LinkDefinition object." ) ) if( !$self->_is_a( $def, 'Markdown::Parser::LinkDefinition' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($def, "Markdown::Parser::LinkDefinition") 0 0 0
102 0 return( $def->copy_to( $self ) );
103 }
104  
105 0 ▶sub link_id { return( shift->_set_get_scalar_as_object( 'link_id', @_ ) ); }
Subroutine link_id: not called CC=1 SCAR=6.9
Pod documented
106  
107 0 ▶sub title { return( shift->_set_get_scalar_as_object( 'title', @_ ) ); }
Subroutine title: not called CC=1 SCAR=6.9
Pod documented
108  
109 0 ▶sub url { return( shift->_set_get_uri( 'url', @_ ) ); }
Subroutine url: not called CC=1 SCAR=6.9
Pod documented
110  
111 1 1;
112 # NOTE: POD
113 __END__
« blib/lib/Markdown/Parser/TableCell.pm ↑ Summary blib/lib/Markdown/Parser/ListItem.pm »