Parser/Image.pm

filter: Statementstmt 28.5% 20 / 70 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 43.7% 7 / 16 Podpod 100% 9 / 9 totaltotal 27.6% 36 / 130 CC 15 SCAR 33.3
CC
15
Cov
20%
as_markdown
56.0
as_string
56.0
copy_from
12.0
CRAP 28.0
« Parser/Table.pm ↑ Summary Parser/TableCell.pm »
1 ## -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## Markdown Parser Only - ~/lib/Markdown/Parser/Image.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::Image;
15 BEGIN
16 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
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 our $VERSION = 'v0.3.0';
22 };
23  
24 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 sub init
28 0 ▶{
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
29 0 my $self = shift( @_ );
30 0 $self->{alt} = '';
31 0 $self->{id} = [];
32 0 $self->{link_id} = '';
33 0 $self->{tag_name} = 'img';
34 0 $self->{title} = '';
35 0 $self->{url} = '';
36 0 return( $self->SUPER::init( @_ ) );
37 }
38  
39 0 ▶sub alt { return( shift->_set_get_scalar_as_object( 'alt', @_ ) ); }
Subroutine alt: not called CC=1 SCAR=6.9
Pod documented
40  
41 sub as_markdown
42 0 ▶{
Subroutine as_markdown: not called CC=7 SCAR=40.3
Pod documented
43 0 my $self = shift( @_ );
44 0 my $arr = $self->new_array;
45 0 $arr->push( sprintf( '![%s]', $self->alt ) );
46 0 ▶ if( $self->id )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->id) { } 0 0 0
elsif ($self->uri or $self->title) { } 0 0 0
47 {
48 0 $arr->push( sprintf( '[%s]', $self->id ) );
49 }
50 ▶ 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
51 {
52 0 $arr->push( '(' );
53 0 ▶ $arr->push( sprintf( '%s', $self->uri ) ) if( $self->uri );
Branch: 1 branch
BranchTrueFalseTotal
if $self->uri 0 0 0
54 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
55 0 $arr->push( sprintf( '"%s"', $self->title ) );
56 0 $arr->push( ')' );
57 }
58 0 return( $arr->join( '' )->scalar );
59 }
60  
61 sub as_pod
62 0 ▶{
Subroutine as_pod: not called CC=1 SCAR=6.9
Pod documented
63 0 my $self = shift( @_ );
64 0 my $arr = $self->new_array;
65 0 $arr->push( "=begin html\n" );
66 0 $arr->push( $self->as_string );
67 0 $arr->push( "\n=end html" );
68 0 return( $arr->join( "\n" )->scalar );
69 }
70  
71 sub as_string
72 0 ▶{
Subroutine as_string: not called CC=7 SCAR=40.3
Pod documented
73 0 my $self = shift( @_ );
74 0 my $arr = $self->new_array;
75 0 my $tag = 'img';
76 0 my $tag_open = $tag;
77 0 $arr->push( "<${tag_open} src=\"" . $self->url . "\"" );
78 0 ▶ if( $self->alt->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->alt->length) 0 0 0
79 {
80 0 $arr->push( sprintf( 'alt="%s"', $self->encode_html( 'all', $self->alt ) ) );
81 }
82 0 ▶ if( $self->title->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->title->length) 0 0 0
83 {
84 0 $arr->push( sprintf( 'title="%s"', $self->encode_html( 'all', $self->title ) ) );
85 }
86 0 my $attr = $self->new_array;
87 0 ▶ $attr->push( $self->format_id ) if( $self->id->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->id->length 0 0 0
88 0 ▶ $attr->push( $self->format_class ) if( $self->class->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->class->length 0 0 0
89 0 my $attributes = $self->format_attributes;
90 0 ▶ $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attributes->length 0 0 0
91 0 ▶ $arr->push( $attr->join( ' ' )->scalar ) if( $attr->length );
Branch: 1 branch
BranchTrueFalseTotal
if $attr->length 0 0 0
92 0 $arr->push( '/>' );
93 0 return( $arr->join( ' ' )->scalar );
94 }
95  
96 sub copy_from
97 0 ▶{
Subroutine copy_from: not called CC=3 SCAR=24.8
Pod documented
98 0 my $self = shift( @_ );
99 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
100 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
101 0 return( $def->copy_to( $self ) );
102 }
103  
104 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
105  
106 0 ▶sub title { return( shift->_set_get_scalar_as_object( 'title', @_ ) ); }
Subroutine title: not called CC=1 SCAR=6.9
Pod documented
107  
108 0 ▶sub url { return( shift->_set_get_uri( 'url', @_ ) ); }
Subroutine url: not called CC=1 SCAR=6.9
Pod documented
109  
110 1 1;
111 # NOTE: POD
112 __END__
« Parser/Table.pm ↑ Summary Parser/TableCell.pm »