lib/Markdown/Parser/Document.pm

filter: Statementstmt 22.3% 136 / 608 Branchbran 1.6% 8 / 480 Conditioncond 0.0% 0 / 126 MC/DCmcdc 0.0% 0 / 62 Subroutinesub 47.3% 44 / 93 Podpod 100% 38 / 38 totaltotal 16.0% 226 / 1407 CC 287 SCAR 84.5
CC
287
Cov
12%
add_css_link
8870.4
add_js_link
8870.4
__ANON__
270.4
CRAP 4662.2
« lib/Markdown/Parser.pm ↑ Summary blib/lib/Markdown/Parser.pm »
1 ##----------------------------------------------------------------------------
2 ## Markdown Parser Only - ~/lib/Markdown/Parser/Document.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/08/23
7 ## Modified 2022/09/19
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Markdown::Parser::Document;
14 BEGIN
15 {
16 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ use parent qw( Markdown::Parser::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶ use Nice::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶ use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶ our $VERSION = 'v0.2.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶ use constant MERMAID_RSRC_URI => 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶ use constant MERMAID_INIT => "mermaid.initialize({startOnLoad:true});";
Subroutine BEGIN: called CC=1 SCAR=0.0
27 # https://katex.org/
28 2 ▶ use constant KATEX_CSS_URI => 'https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶ use constant KATEX_JS_URI => 'https://cdn.jsdelivr.net/npm/katex/dist/katex.min.js';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶ use constant KATEX_AUTO_RENDERER => 'https://cdn.jsdelivr.net/npm/katex/dist/contrib/auto-render.min.js';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶ use constant KATEX_FONT_URI => 'https://cdn.jsdelivr.net/npm/webfontloader/webfontloader.js';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 };
33  
34 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 sub init
38 {
39 1 ▶ my $self = shift( @_ );
Subroutine init: called CC=1 SCAR=0.0
Pod documented
40 1 $self->{abbreviation_case_sensitive} = 0;
41 1 $self->{bolds} = {};
42 1 $self->{default_email} = '';
43 1 $self->{dict} = {};
44 1 $self->{email_obfuscate_class} = 'courriel';
45 1 $self->{email_obfuscate_data_host} = 'host';
46 1 $self->{email_obfuscate_data_user} = 'user';
47 1 $self->{emphasis} = {};
48 ## All footnotes objects ordered
49 1 $self->{footnotes} = [];
50 ## Footnotes hash id => object
51 1 $self->{footnotes_dict} = {};
52 1 $self->{katex_delimiter} = ['$$','$$','$','$','\[','\]','\(','\)'];
53 1 $self->{links} = {};
54 1 $self->{objects} = {};
55 1 $self->{tag_name} = '';
56 1 return( $self->SUPER::init( @_ ) );
57 }
58  
59 1 ▶sub abbreviation_case_sensitive { return( shift->_set_get_scalar( 'abbreviation_case_sensitive', @_ ) ); }
Subroutine abbreviation_case_sensitive: called CC=1 SCAR=0.0
Pod documented
60  
61 sub add_css_link
62 {
63 0 ▶ my $self = shift( @_ );
Subroutine add_css_link: not called CC=99 SCAR=90.9
Pod documented
64 0 ▶ my $url = shift( @_ ) || return( $self->error( "No css link uri provided" ) );
Condition0%0/2
shift @_ || (return $self->error('No css link uri provided'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No css link uri provided'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
65 0 my $opts = {};
66 0 ▶ $opts = shift( @_ ) if( $self->_is_hash( $_[-1] ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_hash($_[-1]) 0 0 0
67 0 my $uri;
68 0 ▶ try
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 3 branches
BranchTrueFalseTotal
unless defined $Nice::Try::NEED_TO_RETURN 0 0 0
if ($INC{"threads.pm"} and not exists $INC{"forks.pm"}) 0 0 0
wantarray ? : 0 0 0
Condition0%0/3
$INC{"threads.pm"} and not exists $INC{"forks.pm"}
!ll&&!rl&&r
000
MC/DC0%0/2
$INC{"threads.pm"} and not exists $INC{"forks.pm"}
$INC{"threads.pm"} not exists $INC{"forks.pm"}
Truth table0%0/3
A and not(B)
A= $INC{"threads.pm"}B= not exists $INC{"forks.pm"}
ABresult
0X0
100
111
69 0 ▶ {
Subroutine __ANON__: not called CC=17 SCAR=56.0
70 0 $uri = URI->new( $url );
71 }
72 2 ▶ catch( $e )
Subroutine BEGIN: called CC=1 SCAR=6.3
Subroutine BEGIN: called CC=1 SCAR=6.3
Subroutine __ANON__: not called CC=1 SCAR=6.3
Subroutine __ANON__: not called CC=1 SCAR=6.3
Branch: 34 branches
BranchTrueFalseTotal
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
&$Nice::Try::TRY ? : 0 0 0
if scalar @Nice::Try::VOID 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 0 0
elsif (defined $Nice::Try::WANTARRAY) { } 0 0 0
if defined $Nice::Try::LAST_VAL 0 0 0
length $@ ? : 0 0 0
unless builtin::blessed($@) 0 0 0
if ($Nice::Try::DIED) 0 0 0
if ($Nice::Try::HAS_CATCH) 0 0 0
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 0 0
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 0 0
elsif (defined $Nice::Try::WANTARRAY) { } 0 0 0
Condition0%0/8
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
!ll
00
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/1
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
not defined $Nice::Try::WANTARRAY
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table0%0/2
not(A)
A= not defined $Nice::Try::WANTARRAY
Aresult
00
11
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
73 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.0
74 0 return( $self->error( "Bad uri provided for this css link: '$url'" ) );
75 2 ▶ }
Subroutine BEGIN: called CC=1 SCAR=6.3
Subroutine BEGIN: called CC=1 SCAR=6.3
Subroutine BEGIN: called CC=1 SCAR=6.3
Branch: 56 branches
BranchTrueFalseTotal
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
&$Nice::Try::CATCH ? : 0 0 0
if scalar @Nice::Try::VOID 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 0 0
elsif (defined $Nice::Try::WANTARRAY) { } 0 0 0
if $@ 0 0 0
if (defined $Nice::Try::CATCH_DIED) 0 0 0
if (defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq 'return' and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa('Nice::Try::SENTINEL')) { } 0 0 0
elsif (scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa('Nice::Try::SENTINEL')) { } 0 0 0
if defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return" 0 0 0
if (not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return") 0 0 0
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
if (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__NEXT__') { } 0 0 0
elsif (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__LAST__') { } 0 0 0
elsif (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__REDO__') { } 0 0 0
elsif (defined $Nice::Try::BREAK and $Nice::Try::BREAK eq 'return') { } 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::WANTARRAY ? : 0 0 0
$Nice::Try::WANTARRAY ? : 0 0 0
scalar @Nice::Try::VOID > 1 ? : 0 0 0
if (defined $Nice::Try::BREAK) 0 0 0
if ($Nice::Try::BREAK eq 'next') { } 0 0 0
elsif ($Nice::Try::BREAK eq 'last') { } 0 0 0
elsif ($Nice::Try::BREAK eq 'redo') { } 0 0 0
scalar @Nice::Try::LAST_VAL > 1 ? : 0 0 0
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 0 0
Condition0%0/50
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq "return" and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
000
defined $Nice::Try::WANTARRAY or defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
000
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
not builtin::blessed($Nice::Try::RETVAL[0]) or builtin::blessed($Nice::Try::RETVAL[0]) and not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
l!l&&r!l&&!r
000
builtin::blessed($Nice::Try::RETVAL[0]) and not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
000
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
000
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__NEXT__"
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__LAST__"
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__REDO__"
!ll&&!rl&&r
000
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
000
not builtin::blessed($Nice::Try::VOID[0]) or builtin::blessed($Nice::Try::VOID[0]) and not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
l!l&&r!l&&!r
000
builtin::blessed($Nice::Try::VOID[0]) and not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
000
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
!ll
00
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/6
defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq "return" and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
defined $Nice::Try::WANTARRAY defined $Nice::Try::BREAK $Nice::Try::BREAK eq "return" not builtin::blessed($Nice::Try::RETVAL[0]) builtin::blessed($Nice::Try::RETVAL[0]) not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
MC/DC0%0/2
not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return"
not defined $Nice::Try::BREAK $Nice::Try::BREAK eq "return"
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__NEXT__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__NEXT__"
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__LAST__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__LAST__"
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__REDO__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__REDO__"
MC/DC0%0/4
scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
scalar @Nice::Try::VOID not builtin::blessed($Nice::Try::VOID[0]) builtin::blessed($Nice::Try::VOID[0]) not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
MC/DC0%0/1
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
not defined $Nice::Try::WANTARRAY
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table0%0/10
A or B and C and not(D) or E and not(F)
A= defined $Nice::Try::WANTARRAYB= defined $Nice::Try::BREAKC= $Nice::Try::BREAK eq "return"D= not builtin::blessed($Nice::Try::RETVAL[0])E= builtin::blessed($Nice::Try::RETVAL[0])F= not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
ABCDEFresult
00XXXX0
010XXX0
1XX00X0
1XX0100
01100X0
0110100
1XX1XX1
1XX0111
0111XX1
0110111
Truth table0%0/3
not(A) or B
A= not defined $Nice::Try::BREAKB= $Nice::Try::BREAK eq "return"
ABresult
1X1
011
000
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__NEXT__"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__LAST__"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__REDO__"
ABresult
0X0
100
111
Truth table0%0/5
A and not(B) or C and not(D)
A= scalar @Nice::Try::VOIDB= not builtin::blessed($Nice::Try::VOID[0])C= builtin::blessed($Nice::Try::VOID[0])D= not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
Truth table0%0/2
not(A)
A= not defined $Nice::Try::WANTARRAY
Aresult
00
11
76 0 my $found;
77 $self->css_links->foreach(sub
78 {
79 0 ▶ my $ref = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
80 0 ▶ if( $ref->{uri} eq $uri )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{"uri"} eq $uri) 0 0 0
81 {
82 0 $found++;
83 0 return;
84 }
85 0 });
86 0 ▶ return( $uri ) if( $found );
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
87 0 $opts->{uri} = $uri;
88 0 $self->css_links->push( $opts );
89 0 return( $self );
90 }
91  
92 sub add_js_data
93 {
94 0 ▶ my $self = shift( @_ );
Subroutine add_js_data: not called CC=2 SCAR=17.9
Pod documented
95 0 my $js = shift( @_ );
96 # unless( $self->js_data->exists( $js ) )
97 # {
98 # $self->js_data->push( $js );
99 # }
100 0 my $found;
101 $self->js_data->foreach(sub
102 {
103 0 ▶ if( $_ eq $js )
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq $js) 0 0 0
104 {
105 0 $found++;
106 0 return;
107 }
108 0 });
109 0 ▶ $self->js_data->push( $js ) if( !$found );
Branch: 1 branch
BranchTrueFalseTotal
unless $found 0 0 0
110 0 return( $self );
111 }
112  
113 sub add_js_link
114 {
115 0 ▶ my $self = shift( @_ );
Subroutine add_js_link: not called CC=99 SCAR=90.9
Pod documented
116 0 ▶ my $url = shift( @_ ) || return( $self->error( "No JavaScript link uri provided" ) );
Condition0%0/2
shift @_ || (return $self->error('No JavaScript link uri provided'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No JavaScript link uri provided'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
117 0 my $opts = {};
118 0 ▶ $opts = shift( @_ ) if( $self->_is_hash( $_[-1] ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_hash($_[-1]) 0 0 0
119 0 my $uri;
120 0 ▶ try
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 3 branches
BranchTrueFalseTotal
unless defined $Nice::Try::NEED_TO_RETURN 0 0 0
if ($INC{"threads.pm"} and not exists $INC{"forks.pm"}) 0 0 0
wantarray ? : 0 0 0
Condition0%0/3
$INC{"threads.pm"} and not exists $INC{"forks.pm"}
!ll&&!rl&&r
000
MC/DC0%0/2
$INC{"threads.pm"} and not exists $INC{"forks.pm"}
$INC{"threads.pm"} not exists $INC{"forks.pm"}
Truth table0%0/3
A and not(B)
A= $INC{"threads.pm"}B= not exists $INC{"forks.pm"}
ABresult
0X0
100
111
121 0 ▶ {
Subroutine __ANON__: not called CC=17 SCAR=56.0
122 0 $uri = URI->new( $url );
123 }
124 2 ▶ catch( $e )
Subroutine BEGIN: called CC=1 SCAR=6.3
Subroutine BEGIN: called CC=1 SCAR=6.3
Subroutine __ANON__: not called CC=1 SCAR=6.3
Branch: 34 branches
BranchTrueFalseTotal
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
&$Nice::Try::TRY ? : 0 0 0
if scalar @Nice::Try::VOID 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 0 0
elsif (defined $Nice::Try::WANTARRAY) { } 0 0 0
if defined $Nice::Try::LAST_VAL 0 0 0
length $@ ? : 0 0 0
unless builtin::blessed($@) 0 0 0
if ($Nice::Try::DIED) 0 0 0
if ($Nice::Try::HAS_CATCH) 0 0 0
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 0 0
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 0 0
elsif (defined $Nice::Try::WANTARRAY) { } 0 0 0
Condition0%0/8
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
!ll
00
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/1
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
not defined $Nice::Try::WANTARRAY
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table0%0/2
not(A)
A= not defined $Nice::Try::WANTARRAY
Aresult
00
11
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
125 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.0
126 0 return( $self->error( "Bad uri provided for this JavaScript link: '$url'" ) );
127 2 ▶ }
Subroutine BEGIN: called CC=1 SCAR=6.3
Subroutine BEGIN: called CC=1 SCAR=6.3
Subroutine BEGIN: called CC=1 SCAR=6.3
Branch: 56 branches
BranchTrueFalseTotal
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
&$Nice::Try::CATCH ? : 0 0 0
if scalar @Nice::Try::VOID 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 0 0
elsif (defined $Nice::Try::WANTARRAY) { } 0 0 0
if $@ 0 0 0
if (defined $Nice::Try::CATCH_DIED) 0 0 0
if (defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq 'return' and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa('Nice::Try::SENTINEL')) { } 0 0 0
elsif (scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa('Nice::Try::SENTINEL')) { } 0 0 0
if defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return" 0 0 0
if (not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return") 0 0 0
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
if (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__NEXT__') { } 0 0 0
elsif (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__LAST__') { } 0 0 0
elsif (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__REDO__') { } 0 0 0
elsif (defined $Nice::Try::BREAK and $Nice::Try::BREAK eq 'return') { } 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::WANTARRAY ? : 0 0 0
$Nice::Try::WANTARRAY ? : 0 0 0
scalar @Nice::Try::VOID > 1 ? : 0 0 0
if (defined $Nice::Try::BREAK) 0 0 0
if ($Nice::Try::BREAK eq 'next') { } 0 0 0
elsif ($Nice::Try::BREAK eq 'last') { } 0 0 0
elsif ($Nice::Try::BREAK eq 'redo') { } 0 0 0
scalar @Nice::Try::LAST_VAL > 1 ? : 0 0 0
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 0 0
Condition0%0/50
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq "return" and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
000
defined $Nice::Try::WANTARRAY or defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
000
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
not builtin::blessed($Nice::Try::RETVAL[0]) or builtin::blessed($Nice::Try::RETVAL[0]) and not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
l!l&&r!l&&!r
000
builtin::blessed($Nice::Try::RETVAL[0]) and not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
000
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
000
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__NEXT__"
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__LAST__"
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__REDO__"
!ll&&!rl&&r
000
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
000
not builtin::blessed($Nice::Try::VOID[0]) or builtin::blessed($Nice::Try::VOID[0]) and not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
l!l&&r!l&&!r
000
builtin::blessed($Nice::Try::VOID[0]) and not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
000
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
!ll
00
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/6
defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq "return" and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
defined $Nice::Try::WANTARRAY defined $Nice::Try::BREAK $Nice::Try::BREAK eq "return" not builtin::blessed($Nice::Try::RETVAL[0]) builtin::blessed($Nice::Try::RETVAL[0]) not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
MC/DC0%0/2
not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return"
not defined $Nice::Try::BREAK $Nice::Try::BREAK eq "return"
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__NEXT__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__NEXT__"
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__LAST__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__LAST__"
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__REDO__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__REDO__"
MC/DC0%0/4
scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
scalar @Nice::Try::VOID not builtin::blessed($Nice::Try::VOID[0]) builtin::blessed($Nice::Try::VOID[0]) not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
MC/DC0%0/1
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
not defined $Nice::Try::WANTARRAY
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table0%0/10
A or B and C and not(D) or E and not(F)
A= defined $Nice::Try::WANTARRAYB= defined $Nice::Try::BREAKC= $Nice::Try::BREAK eq "return"D= not builtin::blessed($Nice::Try::RETVAL[0])E= builtin::blessed($Nice::Try::RETVAL[0])F= not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
ABCDEFresult
00XXXX0
010XXX0
1XX00X0
1XX0100
01100X0
0110100
1XX1XX1
1XX0111
0111XX1
0110111
Truth table0%0/3
not(A) or B
A= not defined $Nice::Try::BREAKB= $Nice::Try::BREAK eq "return"
ABresult
1X1
011
000
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__NEXT__"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__LAST__"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__REDO__"
ABresult
0X0
100
111
Truth table0%0/5
A and not(B) or C and not(D)
A= scalar @Nice::Try::VOIDB= not builtin::blessed($Nice::Try::VOID[0])C= builtin::blessed($Nice::Try::VOID[0])D= not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
Truth table0%0/2
not(A)
A= not defined $Nice::Try::WANTARRAY
Aresult
00
11
128 0 my $found;
129 $self->js_links->foreach(sub
130 {
131 0 ▶ my $ref = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
132 0 ▶ if( $ref->{uri} eq $uri )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{"uri"} eq $uri) 0 0 0
133 {
134 0 $found++;
135 0 return;
136 }
137 0 });
138 0 ▶ return( $uri ) if( $found );
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
139 0 $opts->{uri} = $uri;
140 0 $self->js_links->push( $opts );
141 0 return( $self );
142 }
143  
144 sub add_object
145 {
146 0 ▶ my $self = shift( @_ );
Subroutine add_object: not called CC=3 SCAR=24.8
Pod documented
147 0 my $obj = shift( @_ );
148 0 ▶ return if( !ref( $obj ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $obj 0 0 0
149 0 ▶ return if( !$self->_is_a( $obj, 'Markdown::Parser::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($obj, "Markdown::Parser::Element") 0 0 0
150 0 my $id = $obj->object_id;
151 0 $self->objects->set( $id => $obj );
152 0 return( $id );
153 }
154  
155 sub as_markdown
156 {
157 1 ▶ my $self = shift( @_ );
Subroutine as_markdown: called CC=4 SCAR=18.9
Pod documented
158 1 ▶ my $str = $self->children->map(sub{ $_->as_markdown })->join( '' );
Subroutine __ANON__: called CC=1 SCAR=0.0
159 1 ▶ if( $self->links->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->links->length) 0 1 1
160 {
161 0 $str .= "\n\n";
162 0 ▶ $str .= $self->links->map_array(sub{ $_[1]->as_markdown })->join( "\n" );
Subroutine __ANON__: not called CC=1 SCAR=6.9
163 }
164 1 ▶ if( $self->dict->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dict->length) 0 1 1
165 {
166 0 $str .= "\n\n";
167 0 ▶ $str .= $self->dict->map_array(sub{ $_[1]->as_markdown })->join( "\n" );
Subroutine __ANON__: not called CC=1 SCAR=6.9
168 }
169 1 ▶ if( $self->footnotes->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->footnotes->length) 0 1 1
170 {
171 0 $str .= "\n\n";
172 0 ▶ $str .= $self->footnotes->map_array(sub{ $_[1]->as_markdown })->join( "\n" );
Subroutine __ANON__: not called CC=1 SCAR=6.9
173 }
174 1 return( $str );
175 }
176  
177 sub as_pod
178 {
179 0 ▶ my $self = shift( @_ );
Subroutine as_pod: not called CC=3 SCAR=24.8
Pod documented
180 0 ▶ my $str = $self->children->map(sub{ $_->as_pod })->join( '' );
Subroutine __ANON__: not called CC=1 SCAR=6.9
181 0 ▶ if( $self->dict->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dict->length) 0 0 0
182 {
183 0 $str .= "\n\n";
184 0 ▶ $str .= $self->dict->map_array(sub{ $_[1]->as_pod })->join( "\n" );
Subroutine __ANON__: not called CC=1 SCAR=6.9
185 }
186 0 ▶ if( $self->footnotes->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->footnotes->length) 0 0 0
187 {
188 0 $str .= "\n\n";
189 0 ▶ $str .= $self->footnotes->map_array(sub{ $_[1]->as_pod })->join( "\n" );
Subroutine __ANON__: not called CC=1 SCAR=6.9
190 }
191 0 return( $str );
192 }
193  
194 sub as_string
195 {
196 0 ▶ my $self = shift( @_ );
Subroutine as_string: not called CC=3 SCAR=24.8
Pod documented
197 0 my $arr = $self->new_array;
198 0 my $css_style;
199 0 my $css = $self->css;
200 0 my $temp_buffer = $self->new_array;
201 ## We need to set this temporary buffer because calling our children's as_string method does some set-ups that affects us
202 0 ▶ $temp_buffer->push( $self->children->map(sub{ $_->as_string })->join( "\n" )->scalar );
Subroutine __ANON__: not called CC=1 SCAR=6.9
203
204 0 $arr->push( <<EOT );
205 <!DOCTYPE html>
206 <html lang="en-GB">
207 <head>
208 <meta charset="utf-8" />
209 <title></title>
210 EOT
211 $self->css_links->foreach(sub
212 {
213 0 ▶ my $ref = shift( @_ );
Subroutine __ANON__: not called CC=4 SCAR=30.0
214 0 my $e = $self->new_array( ['link'] );
215 0 ▶ $ref->{rel} = 'stylesheet' unless( length( $ref->{rel} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $ref->{"rel"} 0 0 0
216 0 ▶ $ref->{type} = 'text/css' unless( length( $ref->{type} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $ref->{"type"} 0 0 0
217 0 $ref->{href} = delete( $ref->{uri} );
218 0 foreach my $k ( sort( keys( %$ref ) ) )
219 {
220 0 $e->push( sprintf( '%s="%s"', $k, $ref->{ $k } ) );
221 }
222 0 $arr->push( '<' . $e->join( ' ' )->scalar . ' />' );
223 0 });
224 0 ▶ if( $css->elements->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($css->elements->length > 0) 0 0 0
225 {
226 0 $css_style = $css->as_string;
227 0 $arr->push( <<EOT );
228 <style>
229 ${css_style}
230 </style>
231 EOT
232 }
233 $self->js_links->foreach(sub
234 {
235 0 ▶ my $ref = shift( @_ );
Subroutine __ANON__: not called CC=5 SCAR=34.0
236 0 my $e = $self->new_array( ['script'] );
237 0 $ref->{src} = delete( $ref->{uri} );
238 0 ▶ $ref->{language} = 'JavaScript' unless( length( $ref->{language} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $ref->{"language"} 0 0 0
239 0 ▶ $ref->{type} = 'text/javascript' unless( length( $ref->{type} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $ref->{"type"} 0 0 0
240 0 ▶ $e->push( 'defer' ) if( delete( $ref->{defer} ) );
Branch: 1 branch
BranchTrueFalseTotal
if delete $ref->{"defer"} 0 0 0
241 0 foreach my $k ( sort( keys( %$ref ) ) )
242 {
243 0 $e->push( sprintf( '%s="%s"', $k, $ref->{ $k } ) );
244 }
245 0 $arr->push( '<' . $e->join( ' ' )->scalar . '></script>' );
246 0 });
247 $self->js_data->foreach(sub
248 {
249 0 ▶ my $js = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
250 0 ▶ return( 1 ) if( !length( $js ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $js 0 0 0
251 0 $arr->push( '<script type="text/javascript" language="JavaScript">' );
252 0 $arr->push( $js );
253 0 $arr->push( '</script>' );
254 0 });
255 0 $arr->push( <<EOT );
256 </head>
257 <body>
258 EOT
259 ## $arr->push( $self->children->map(sub{ $_->as_string })->join( "\n" )->scalar );
260 0 $arr->push( $temp_buffer->list );
261 0 ▶ if( $self->footnotes->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->footnotes->length) 0 0 0
262 {
263 0 my $fn = $self->new_array;
264 0 $fn->push( '<div class="footnotes" role="doc-endnotes">' );
265 0 $fn->push( '<hr />' );
266 0 $fn->push( '<ol>' );
267 # $fn->push( $self->footnotes->map_array(sub{ $_[1]->as_string })->join( "\n" )->scalar );
268 0 ▶ my $fn_str = $self->footnotes->map(sub{ $_->as_string })->join( "\n" )->scalar;
Subroutine __ANON__: not called CC=1 SCAR=6.9
269 0 $fn->push( $fn_str );
270 0 $fn->push( '</ol>' );
271 0 $arr->push( $fn->join( "\n" )->scalar );
272 }
273 0 $arr->push( <<EOT );
274 </body>
275 </html>
276 EOT
277 0 return( $arr->join( "\n" )->scalar );
278 }
279  
280 0 ▶sub bolds { return( shift->_set_get_hash_as_mix_object( 'bolds', @_ ) ); }
Subroutine bolds: not called CC=1 SCAR=6.9
Pod documented
281  
282 1 ▶sub css { return( shift->_set_get_object( 'css', 'CSS::Object', @_ ) ); }
Subroutine css: called CC=1 SCAR=0.0
Pod documented
283  
284 0 ▶sub css_links { return( shift->_set_get_array_as_object( 'css_links', @_ ) ); }
Subroutine css_links: not called CC=1 SCAR=6.9
Pod documented
285  
286 1 ▶sub default_email { return( shift->_set_get_scalar_as_object( 'default_email', @_ ) ); }
Subroutine default_email: called CC=1 SCAR=0.0
Pod documented
287  
288 ## Ex: $self->dict->some_word( "Some value" );
289 ## Uses Module::Generic::Hash hash object
290 1 ▶sub dict { return( shift->_set_get_hash_as_mix_object( 'dict', @_ ) ); }
Subroutine dict: called CC=1 SCAR=0.0
Pod documented
291  
292 ## Alias
293 0 ▶sub dictionary { return( shift->_set_get_hash_as_mix_object( 'dict', @_ ) ); }
Subroutine dictionary: not called CC=1 SCAR=6.9
Pod documented
294  
295 1 ▶sub email_obfuscate_class { return( shift->_set_get_scalar_as_object( 'email_obfuscate_class', @_ ) ); }
Subroutine email_obfuscate_class: called CC=1 SCAR=0.0
Pod documented
296  
297 sub email_obfuscate_data_host
298 {
299 1 ▶ my $self = shift( @_ );
Subroutine email_obfuscate_data_host: called CC=3 SCAR=12.7
Pod documented
300 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
301 {
302 1 ▶ if( $_[0] =~ /^[a-zA-Z]\w+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^[a-zA-Z]\w+$/) { } 1 0 1
303 {
304 1 return( $self->_set_get_scalar_as_object( 'email_obfuscate_data_host', @_ ) );
305 }
306 else
307 {
308 0 return( $self->error( "Invalid value \"$_[0]\" for the email obfuscation data-host attribute name." ) );
309 }
310 }
311 0 return( $self->_set_get_scalar_as_object( 'email_obfuscate_data_host' ) );
312 }
313  
314 sub email_obfuscate_data_user
315 {
316 1 ▶ my $self = shift( @_ );
Subroutine email_obfuscate_data_user: called CC=3 SCAR=12.7
Pod documented
317 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
318 {
319 1 ▶ if( $_[0] =~ /^[a-zA-Z]\w+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^[a-zA-Z]\w+$/) { } 1 0 1
320 {
321 1 return( $self->_set_get_scalar_as_object( 'email_obfuscate_data_user', @_ ) );
322 }
323 else
324 {
325 0 return( $self->error( "Invalid value \"$_[0]\" for the email obfuscation data-user attribute name." ) );
326 }
327 }
328 0 return( $self->_set_get_scalar_as_object( 'email_obfuscate_data_user' ) );
329 }
330  
331 0 ▶sub emphasis { return( shift->_set_get_hash_as_mix_object( 'emphasis', @_ ) ); }
Subroutine emphasis: not called CC=1 SCAR=6.9
Pod documented
332  
333 1 ▶sub footnotes { return( shift->_set_get_array_as_object( 'footnotes', @_ ) ); }
Subroutine footnotes: called CC=1 SCAR=0.0
Pod documented
334  
335 0 ▶sub footnotes_dict { return( shift->_set_get_hash_as_mix_object( 'footnotes_dict', @_ ) ); }
Subroutine footnotes_dict: not called CC=1 SCAR=6.9
Pod documented
336  
337 sub get_abbreviation
338 {
339 0 ▶ my $self = shift( @_ );
Subroutine get_abbreviation: not called CC=4 SCAR=30.0
Pod documented
340 0 my $name = shift( @_ );
341 0 ▶ return if( !length( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 0 0 0
342 0 ▶ $name = lc( $name ) unless( $self->abbreviation_case_sensitive );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->abbreviation_case_sensitive 0 0 0
343 0 ▶ return if( !$self->dict->exists( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dict->exists($name) 0 0 0
344 0 my $elem = $self->dict->{ $name };
345 0 return( $elem );
346 }
347  
348 sub get_footnote
349 {
350 0 ▶ my $self = shift( @_ );
Subroutine get_footnote: not called CC=3 SCAR=24.8
Pod documented
351 0 my $id = shift( @_ );
352 0 ▶ return if( !length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $id 0 0 0
353 0 ▶ return if( !$self->footnotes_dict->exists( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->footnotes_dict->exists($id) 0 0 0
354 0 my $elem = $self->footnotes_dict->{ $id };
355 0 return( $elem );
356 }
357  
358 ## This method only make sense when called on the top most element, so we bubble up until we hit it
359 sub get_link_by_id
360 {
361 0 ▶ my $self = shift( @_ );
Subroutine get_link_by_id: not called CC=3 SCAR=24.8
Pod documented
362 0 my $id = shift( @_ );
363 0 ▶ return if( !length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $id 0 0 0
364 0 $id = lc( $id );
365 0 ▶ return if( !$self->links->exists( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->links->exists($id) 0 0 0
366 0 my $elem = $self->links->{ $id };
367 0 return( $elem );
368 }
369  
370 0 ▶sub is_email_obfuscation_setup { return( shift->_set_get_boolean( 'is_email_obfuscation_setup', @_ ) ); }
Subroutine is_email_obfuscation_setup: not called CC=1 SCAR=6.9
Pod documented
371  
372 0 ▶sub is_katex_setup { return( shift->_set_get_boolean( 'is_katex_setup', @_ ) ); }
Subroutine is_katex_setup: not called CC=1 SCAR=6.9
Pod documented
373  
374 0 ▶sub is_mermaid_setup { return( shift->_set_get_boolean( 'is_mermaid_setup', @_ ) ); }
Subroutine is_mermaid_setup: not called CC=1 SCAR=6.9
Pod documented
375  
376 0 ▶sub js_data { return( shift->_set_get_array_as_object( 'js_data', @_ ) ); }
Subroutine js_data: not called CC=1 SCAR=6.9
Pod documented
377  
378 0 ▶sub js_links { return( shift->_set_get_array_as_object( 'js_links', @_ ) ); }
Subroutine js_links: not called CC=1 SCAR=6.9
Pod documented
379  
380 1 ▶sub katex_delimiter { return( shift->_set_get_array_as_object( 'katex_delimiter', @_ ) ); }
Subroutine katex_delimiter: called CC=1 SCAR=0.0
Pod documented
381  
382 1 ▶sub links { return( shift->_set_get_hash_as_mix_object( 'links', @_ ) ); }
Subroutine links: called CC=1 SCAR=0.0
Pod documented
383  
384 0 ▶sub objects { return( shift->_set_get_hash_as_mix_object( 'objects', @_ ) ); }
Subroutine objects: not called CC=1 SCAR=6.9
Pod documented
385  
386 sub register_abbreviation
387 {
388 0 ▶ my $self = shift( @_ );
Subroutine register_abbreviation: not called CC=6 SCAR=37.4
Pod documented
389 0 my $elem = shift( @_ );
390 0 my $opts = {};
391 0 ▶ $opts = shift( @_ ) if( $self->_is_hash( $opts ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_hash($opts) 0 0 0
392 0 ▶ return( $self->error( "No abbreviation definition was provided to register it." ) ) if( !length( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $elem 0 0 0
393 0 my $base = $self->base_class;
394 0 ▶ return( $self->error( "Element provided \"$elem\" is not an ${base}::Abbr object." ) ) if( !$self->_is_a( $elem, "${base}::Abbr" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($elem, "${base}::Abbr") 0 0 0
395 0 my $name = $elem->name;
396 0 ▶ $name = lc( $name ) if( !$opts->{abbreviation_case_sensitive} );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"abbreviation_case_sensitive"} 0 0 0
397 0 ▶ return( $self->error( "No name is set for this abbreviation." ) ) if( !length( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 0 0 0
398 0 $self->dict->set( $name => $elem );
399 0 return( $self );
400 }
401  
402 sub register_footnote
403 {
404 0 ▶ my $self = shift( @_ );
Subroutine register_footnote: not called CC=4 SCAR=30.0
Pod documented
405 0 my $elem = shift( @_ );
406 0 ▶ return( $self->error( "No link definition was provided to register it." ) ) if( !length( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $elem 0 0 0
407 0 my $base = $self->base_class;
408 0 ▶ return( $self->error( "Element provided \"$elem\" is not an ${base}::Footnote object." ) ) if( !$self->_is_a( $elem, "${base}::Footnote" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($elem, "${base}::Footnote") 0 0 0
409 0 my $id = $elem->id;
410 0 ▶ return( $self->error( "No id is set for this footnote." ) ) if( !length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $id 0 0 0
411 0 $self->footnotes_dict->set( lc( $id ) => $elem );
412 0 $self->footnotes->push( $elem );
413 0 return( $self );
414 }
415  
416 sub register_link_definition
417 {
418 0 ▶ my $self = shift( @_ );
Subroutine register_link_definition: not called CC=4 SCAR=30.0
Pod documented
419 0 my $elem = shift( @_ );
420 0 ▶ return( $self->error( "No link definition was provided to register it." ) ) if( !length( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $elem 0 0 0
421 0 my $base = $self->base_class;
422 0 ▶ return( $self->error( "Element provided \"$elem\" is not an ${base}::LinkDefinition object." ) ) if( !$self->_is_a( $elem, "${base}::LinkDefinition" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($elem, "${base}::LinkDefinition") 0 0 0
423 0 my $id = $elem->link_id;
424 0 ▶ return( $self->error( "No id is set for this link definition." ) ) if( !length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $id 0 0 0
425 0 $self->links->set( lc( $id ) => $elem );
426 0 return( $self );
427 }
428  
429 sub setup_email_obfuscation
430 {
431 0 ▶ my $self = shift( @_ );
Subroutine setup_email_obfuscation: not called CC=5 SCAR=34.0
Pod documented
432 0 ▶ return( $self ) if( $self->is_email_obfuscation_setup );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_email_obfuscation_setup 0 0 0
433 0 $self->is_email_obfuscation_setup( 1 );
434 0 my $b = $self->css->builder;
435 0 ▶ my $class = $self->email_obfuscate_class->length > 0 ? $self->email_obfuscate_class->scalar : 'courriel';
Branch: 1 branch
BranchTrueFalseTotal
$self->email_obfuscate_class->length > 0 ? : 0 0 0
436 0 ▶ my $data_host = $self->email_obfuscate_data_host->length > 0 ? $self->email_obfuscate_data_host->scalar : 'data-host';
Branch: 1 branch
BranchTrueFalseTotal
$self->email_obfuscate_data_host->length > 0 ? : 0 0 0
437 0 ▶ my $data_user = $self->email_obfuscate_data_user->length > 0 ? $self->email_obfuscate_data_user->scalar : 'data-user';
Branch: 1 branch
BranchTrueFalseTotal
$self->email_obfuscate_data_user->length > 0 ? : 0 0 0
438 ## Credits for the css part: https://stackoverflow.com/a/21421949/4814971
439 0 $b->select( [".${class}:before"] )->
440 content( sprintf( 'attr(data-%s) "\0040" attr(data-%s)', $data_host, $data_user ) )->
441 unicode_bidi( 'bidi-override' )->
442 direction( 'rtl' );
443 0 $self->add_js_data( <<EOT );
444 (function()
445 {
446 var docLoaded = setInterval(function()
447 {
448 if( document.readyState !== "complete" ) return;
449 clearInterval( docLoaded );
450 document.querySelectorAll('.${class}').forEach( item =>
451 {
452 item.addEventListener('click', event =>
453 {
454 if( !event.target.dataset.decoded )
455 {
456 event.preventDefault();
457 function decode(a, r)
458 {
459 return a.split( '' ).reverse().join( '' );
460 };
461 var y = decode( event.target.dataset.${data_user} ) + '\@' + decode( event.target.dataset.${data_host} );
462 var enc = encodeURI( y );
463 enc = enc.replace( '?', '%3F' );
464 // console.log( "Final e-mail is: " + enc );
465 event.target.setAttribute( 'href', 'mai' + 'lto:' + enc );
466 event.target.dataset.decoded = true;
467 // console.log( "Redirecting to " + enc );
468 window.location.href = 'mai' + 'lto:' + enc;
469 return( false );
470 }
471 });
472 });
473 });
474 })();
475 EOT
476 0 return( $self );
477 }
478  
479 sub setup_katex
480 {
481 0 ▶ my $self = shift( @_ );
Subroutine setup_katex: not called CC=4 SCAR=30.0
Pod documented
482 0 ▶ return( $self ) if( $self->is_katex_setup );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_katex_setup 0 0 0
483 0 $self->add_css_link( KATEX_CSS_URI, { crossorigin => 'anonymous' });
484 0 $self->add_js_link( KATEX_JS_URI, { crossorigin => 'anonymous' } );
485 0 $self->add_js_link( KATEX_AUTO_RENDERER, { crossorigin => 'anonymous', defer => 1, onload => 'renderMathInElement(document.body);' });
486 0 $self->add_js_data( <<'EOT' );
487 window.WebFontConfig =
488 {
489 custom:
490 {
491 families: ['KaTeX_AMS', 'KaTeX_Caligraphic:n4,n7', 'KaTeX_Fraktur:n4,n7',
492 'KaTeX_Main:n4,n7,i4,i7', 'KaTeX_Math:i4,i7', 'KaTeX_Script',
493 'KaTeX_SansSerif:n4,n7,i4', 'KaTeX_Size1', 'KaTeX_Size2', 'KaTeX_Size3',
494 'KaTeX_Size4', 'KaTeX_Typewriter'],
495 },
496 };
497 EOT
498 0 $self->add_js_link( KATEX_FONT_URI, { crossorigin => 'anonymous', defer => 1 });
499 0 my $map =
500 {
501 '$$$$' => 'true',
502 '$$' => 'false',
503 '\[\]' => 'true',
504 '\(\)' => 'false',
505 };
506 0 my $delim = $self->new_array;
507 0 my $d = $self->katex_delimiter;
508 0 ▶ for( my $i = 0; $i < $d->length; $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $d->length) 0 0 0
509 {
510 0 my $k = join( '', @$d[$i..$i+1] );
511 0 ▶ $delim->push( sprintf( ' {left: "%s", right: "%s", display: %s},', $d->[$i], $d->[$i+1], $map->{ $k } ) ) if( exists( $map->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $map->{$k} 0 0 0
512 }
513 0 my $delim_specs = $delim->join( "\n" )->scalar;
514 0 $self->add_js_data( <<EOT );
515 document.addEventListener("DOMContentLoaded", function()
516 {
517 renderMathInElement(document.body,
518 {
519 delimiters:
520 [
521 ${delim_specs}
522 ]
523 });
524 });
525 EOT
526 0 $self->is_katex_setup( 1 );
527 0 return( $self );
528 }
529  
530 sub setup_mermaid
531 {
532 0 ▶ my $self = shift( @_ );
Subroutine setup_mermaid: not called CC=2 SCAR=17.9
Pod documented
533 0 ▶ return( $self ) if( $self->is_mermaid_setup );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_mermaid_setup 0 0 0
534 0 $self->add_js_link( MERMAID_RSRC_URI );
535 0 $self->add_js_data( MERMAID_INIT );
536 0 $self->is_mermaid_setup( 1 );
537 0 return( $self );
538 }
539  
540 2 1;
541 # NOTE: POD
542 __END__
« lib/Markdown/Parser.pm ↑ Summary blib/lib/Markdown/Parser.pm »