lib/Markdown/Parser/LinkDefinition.pm

filter: Statementstmt 30.6% 23 / 75 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 40.0% 8 / 20 Podpod 100% 8 / 8 totaltotal 23.4% 39 / 166 CC 23 SCAR 38.8
CC
23
Cov
18%
copy_to
132.0
as_string
56.0
as_markdown
20.0
CRAP 48.3
« blib/lib/Markdown/Parser/Element.pm ↑ Summary blib/lib/Markdown/Parser/Table.pm »
1 ## -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## Markdown Parser Only - ~/lib/Markdown/Parser/LinkDefinition.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::LinkDefinition;
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->{id} = '';
32 0 $self->{link_id} = '';
33 0 $self->{tag_name} = 'link_def';
34 0 $self->{title} = '';
35 0 $self->{url} = '';
36 0 return( $self->SUPER::init( @_ ) );
37 }
38  
39 # [foo]: http://example.com/ "Optional Title Here"
40 sub as_markdown
41 {
42 0 ▶ my $self = shift( @_ );
Subroutine as_markdown: not called CC=4 SCAR=30.0
Pod documented
43 0 my $arr = $self->new_array;
44 0 $arr->push( sprintf( '[%d]: %s', $self->link_id, $self->url ) );
45 0 ▶ $arr->push( sprintf( ' "%s"', $self->title ) ) if( $self->title->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->title->length 0 0 0
46 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
47 {
48 0 my $def = $self->new_array;
49 0 ▶ $def->push( $self->id->map(sub{ "\#${_}" })->list );
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 ▶ $def->push( $self->class->map(sub{ ".$_" })->list );
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 $arr->push( '{' . $def->join( ' ' )->scalar . '}' );
52 }
53 0 return( $arr->join( '' )->scalar );
54 }
55  
56 sub as_pod
57 {
58 0 ▶ my $self = shift( @_ );
Subroutine as_pod: not called CC=4 SCAR=30.0
Pod documented
59 0 my $arr = $self->new_array;
60 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
61 {
62 0 $arr->push( sprintf( '[%d]: L<%s|%s>', $self->link_id, $self->url, $self->title ) );
63 }
64 elsif( $self->url )
65 {
66 0 $arr->push( sprintf( '[%d]: L<%s>', $self->link_id, $self->url ) );
67 }
68 0 return( $arr->join( '' )->scalar );
69 }
70  
71 sub as_string
72 {
73 0 ▶ my $self = shift( @_ );
Subroutine as_string: not called CC=7 SCAR=40.3
Pod documented
74 0 ▶ return( '' ) if( !$self->id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
75 0 my $arr = $self->new_array;
76 0 $arr->push( sprintf( '[%s]:', $self->link_id ) );
77 0 ▶ $arr->push( $self->url . '' ) if( $self->url );
Branch: 1 branch
BranchTrueFalseTotal
if $self->url 0 0 0
78 0 ▶ $arr->push( sprintf( '"%s"', $self->title ) ) if( $self->title );
Branch: 1 branch
BranchTrueFalseTotal
if $self->title 0 0 0
79 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
80 {
81 0 my $def = $self->new_array;
82 0 ▶ $def->push( $self->id->map(sub{ "\#${_}" })->list );
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 0 ▶ $def->push( $self->class->map(sub{ ".$_" })->list );
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 0 $arr->push( '{' . $def->join( ' ' )->scalar . '}' );
85 }
86 0 ▶ return( $arr->join( ' ' ) ) if( $arr->length );
Branch: 1 branch
BranchTrueFalseTotal
if $arr->length 0 0 0
87 0 return( '' );
88 }
89  
90 ## Copy the link definition information to the target object, such as a Link or an Image
91 sub copy_to
92 {
93 0 ▶ my $self = shift( @_ );
Subroutine copy_to: not called CC=11 SCAR=48.8
Pod documented
94 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
95 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
96 0 ▶ $obj->url( $self->url ) if( $obj->can( 'url' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("url") 0 0 0
97 0 ▶ $obj->title( $self->title ) if( $obj->can( 'title' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("title") 0 0 0
98 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
99 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
100 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
101 ## For chaining
102 0 return( $obj );
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/Element.pm ↑ Summary blib/lib/Markdown/Parser/Table.pm »