| 1 | ## -*- perl -*- | ||||||||||||||||||||||||||||||||
| 2 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 3 | ## Markdown Parser Only - ~/lib/Markdown/Parser/LinkDefinition.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::LinkDefinition; | ||||||||||||||||||||||||||||||||
| 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->{id} = ''; | |||||||||||||||||||||||||||||||
| 31 | 0 | $self->{link_id} = ''; | |||||||||||||||||||||||||||||||
| 32 | 0 | $self->{tag_name} = 'link_def'; | |||||||||||||||||||||||||||||||
| 33 | 0 | $self->{title} = ''; | |||||||||||||||||||||||||||||||
| 34 | 0 | $self->{url} = ''; | |||||||||||||||||||||||||||||||
| 35 | 0 | return( $self->SUPER::init( @_ ) ); | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | # [foo]: http://example.com/ "Optional Title Here" | ||||||||||||||||||||||||||||||||
| 39 | sub as_markdown | ||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
as_markdown: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||
| 42 | 0 | my $arr = $self->new_array; | |||||||||||||||||||||||||||||||
| 43 | 0 | $arr->push( sprintf( '[%d]: %s', $self->link_id, $self->url ) ); | |||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $arr->push( sprintf( ' "%s"', $self->title ) ) if( $self->title->length ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if( $self->class->length || $self->id->length ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->class->length or $self->id->length
MC/DC0%0/2
$self->class->length or $self->id->length
$self->class->length
$self->id->length
Truth table0%0/3
A or B
A= $self->class->lengthB= $self->id->length
| |||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||
| 47 | 0 | my $def = $self->new_array; | |||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $def->push( $self->id->map(sub{ "\#${_}" })->list ); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $def->push( $self->class->map(sub{ ".$_" })->list ); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 50 | 0 | $arr->push( '{' . $def->join( ' ' )->scalar . '}' ); | |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | 0 | return( $arr->join( '' )->scalar ); | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | sub as_pod | ||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
as_pod: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 57 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||
| 58 | 0 | my $arr = $self->new_array; | |||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if( $self->url && $self->title ) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$self->url and $self->title
MC/DC0%0/2
$self->url and $self->title
$self->url
$self->title
Truth table0%0/3
A and B
A= $self->urlB= $self->title
| |||||||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||||||
| 61 | 0 | $arr->push( sprintf( '[%d]: L<%s|%s>', $self->link_id, $self->url, $self->title ) ); | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | elsif( $self->url ) | ||||||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||||||
| 65 | 0 | $arr->push( sprintf( '[%d]: L<%s>', $self->link_id, $self->url ) ); | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | 0 | return( $arr->join( '' )->scalar ); | |||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | sub as_string | ||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return( '' ) if( !$self->id ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 74 | 0 | my $arr = $self->new_array; | |||||||||||||||||||||||||||||||
| 75 | 0 | $arr->push( sprintf( '[%s]:', $self->link_id ) ); | |||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $arr->push( $self->url . '' ) if( $self->url ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $arr->push( sprintf( '"%s"', $self->title ) ) if( $self->title ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if( $self->class->length || $self->id->length ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->class->length or $self->id->length
MC/DC0%0/2
$self->class->length or $self->id->length
$self->class->length
$self->id->length
Truth table0%0/3
A or B
A= $self->class->lengthB= $self->id->length
| |||||||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||||||
| 80 | 0 | my $def = $self->new_array; | |||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $def->push( $self->id->map(sub{ "\#${_}" })->list ); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $def->push( $self->class->map(sub{ ".$_" })->list ); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 83 | 0 | $arr->push( '{' . $def->join( ' ' )->scalar . '}' ); | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return( $arr->join( ' ' ) ) if( $arr->length ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 86 | 0 | return( '' ); | |||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | ## Copy the link definition information to the target object, such as a Link or an Image | ||||||||||||||||||||||||||||||||
| 90 | sub copy_to | ||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
copy_to: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | my $obj = shift( @_ ) || return( $self->error( "No object was provided to copy the link definition information to." ) ); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return $self->error('No object was provided to copy the link definition information to.'))
MC/DC0%0/1
shift @_ || (return $self->error('No object was provided to copy the link definition information to.'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | return( $self->error( "The object provided \"", overload::StrVal( $obj ), "\" is not an Markdown::Parser::Element object or one of its inheriting modules." ) ) if( !$self->_is_a( $obj, 'Markdown::Parser::Element' ) ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $obj->url( $self->url ) if( $obj->can( 'url' ) ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $obj->title( $self->title ) if( $obj->can( 'title' ) ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $obj->id( $self->id ) if( $obj->can( 'id' ) && $self->id->length ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj->can("id") and $self->id->length
MC/DC0%0/2
$obj->can("id") and $self->id->length
$obj->can("id")
$self->id->length
Truth table0%0/3
A and B
A= $obj->can("id")B= $self->id->length
| |||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $obj->class( $self->class ) if( $obj->can( 'class' ) && $self->class->length ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj->can("class") and $self->class->length
MC/DC0%0/2
$obj->can("class") and $self->class->length
$obj->can("class")
$self->class->length
Truth table0%0/3
A and B
A= $obj->can("class")B= $self->class->length
| |||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $obj->attributes( $self->attributes ) if( $obj->can( 'attributes' ) && $self->attributes->length ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj->can("attributes") and $self->attributes->length
MC/DC0%0/2
$obj->can("attributes") and $self->attributes->length
$obj->can("attributes")
$self->attributes->length
Truth table0%0/3
A and B
A= $obj->can("attributes")B= $self->attributes->length
| |||||||||||||||||||||||||||||||||
| 100 | ## For chaining | ||||||||||||||||||||||||||||||||
| 101 | 0 | return( $obj ); | |||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||