| 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
| |||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||
| 48 | 0 | $arr->push( sprintf( '[%s]', $self->id ) ); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | ▶ | elsif( $self->uri || $self->title ) | |||||||||||||||||||||||||||
|
Condition0%0/3
$self->uri or $self->title
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
| |||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||
| 52 | 0 | $arr->push( '(' ); | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | $arr->push( sprintf( '%s', $self->uri ) ) if( $self->uri ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $arr->push( ' ' ) if( $self->uri && $self->title ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->uri and $self->title
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||
| 80 | 0 | $arr->push( sprintf( 'alt="%s"', $self->encode_html( 'all', $self->alt ) ) ); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if( $self->title->length ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $attr->push( $self->format_class ) if( $self->class->length ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | my $attributes = $self->format_attributes; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | $arr->push( $attr->join( ' ' )->scalar ) if( $attr->length ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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.'))
MC/DC0%0/1
shift @_ || (return $self->error('No link definition object was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||