Parser/LinkDefinition.pm

filter: Statementstmt 27.7% 20 / 72 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 36.8% 7 / 19 Podpod 100% 8 / 8 totaltotal 21.6% 35 / 162 CC 23 SCAR 39.0
CC
23
Cov
16%
copy_to
132.0
as_string
56.0
as_markdown
20.0
CRAP 49.4
« Parser/Element.pm ↑ Summary Parser/Table.pm »
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
BranchTrueFalseTotal
if $self->title->length 0 0 0
45 0 ▶ if( $self->class->length || $self->id->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->class->length or $self->id->length) 0 0 0
Condition0%0/3
$self->class->length or $self->id->length
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($self->url and $self->title) { } 0 0 0
elsif ($self->url) { } 0 0 0
Condition0%0/3
$self->url and $self->title
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $self->id 0 0 0
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
BranchTrueFalseTotal
if $self->url 0 0 0
77 0 ▶ $arr->push( sprintf( '"%s"', $self->title ) ) if( $self->title );
Branch: 1 branch
BranchTrueFalseTotal
if $self->title 0 0 0
78 0 ▶ if( $self->class->length || $self->id->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->class->length or $self->id->length) 0 0 0
Condition0%0/3
$self->class->length or $self->id->length
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $arr->length 0 0 0
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.'))
l!l
00
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 @_
Aresult
11
00
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
BranchTrueFalseTotal
unless $self->_is_a($obj, "Markdown::Parser::Element") 0 0 0
95 0 ▶ $obj->url( $self->url ) if( $obj->can( 'url' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("url") 0 0 0
96 0 ▶ $obj->title( $self->title ) if( $obj->can( 'title' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("title") 0 0 0
97 0 ▶ $obj->id( $self->id ) if( $obj->can( 'id' ) && $self->id->length );
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("id") and $self->id->length 0 0 0
Condition0%0/3
$obj->can("id") and $self->id->length
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
98 0 ▶ $obj->class( $self->class ) if( $obj->can( 'class' ) && $self->class->length );
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("class") and $self->class->length 0 0 0
Condition0%0/3
$obj->can("class") and $self->class->length
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
99 0 ▶ $obj->attributes( $self->attributes ) if( $obj->can( 'attributes' ) && $self->attributes->length );
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("attributes") and $self->attributes->length 0 0 0
Condition0%0/3
$obj->can("attributes") and $self->attributes->length
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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__
« Parser/Element.pm ↑ Summary Parser/Table.pm »