| 1 | package Text::YAWikiFormater; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use HTML::Entities qw(encode_entities); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use JSON qw(from_json); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 5 | our $VERSION = '0.51'; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 5 | my %plugins = ( | |||||||||||||||||||||||||||||||
| 13 | toc => \&_handle_toc, | ||||||||||||||||||||||||||||||||
| 14 | image => \&_handle_image, | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | restore_code_block => \&_restore_code_block, | ||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 5 | my %namespaces = ( | |||||||||||||||||||||||||||||||
| 20 | wp => { prefix => 'http://en.wikipedia.org/', category=>':' }, | ||||||||||||||||||||||||||||||||
| 21 | gs => { prefix => 'http://www.google.com/search?q=' }, | ||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | my %closed = ( | ||||||||||||||||||||||||||||||||
| 25 | b => qr{(?:(?<!\s)\*\*|\*\*(?!\s))}msix, | ||||||||||||||||||||||||||||||||
| 26 | i => qr{(?<!:)//}, | ||||||||||||||||||||||||||||||||
| 27 | u => qr{__}, | ||||||||||||||||||||||||||||||||
| 28 | del => qr{(?<!\-)\-\-(?!\-)}, | ||||||||||||||||||||||||||||||||
| 29 | tt => qw{''}, | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | heads => [qr[^(?=!{1,6}\s)]msix, qr[$]msix, \&_header_id, undef,"\n"], | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | code => [qr[^\{\{\{$]msix,qr[^\}\}\}$]msix, \&_escape_code], | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | blockquote => [qr{^>\s}msix, qr{^(?!>)}msix, qr{^>\s}msix, '',"\n"], | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | lists => [qr{^(?=[\*\#]+\s)}msix, qr{(?:^(?![\*\#\s])|\z)}msix, \&_do_lists], | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | links => [qr{(?=\[\[)}, qr{(?<=\]\])},\&_do_links], | ||||||||||||||||||||||||||||||||
| 40 | links2 => [qr{\s(?=http://)}, qr{\s},\&_do_links], | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 19 | ▶ | br => [qr{^[\n\s]*(?=$)}msix, qr[$]msix, sub { "<br/><br/>",'',''}], | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | comments => [qr{/\*}msix, qr{\*/}msix, sub{ '','',''}], | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 5 | my %nonclosed = ( | |||||||||||||||||||||||||||||||
| 48 | hr => qr{^[-\*]{3,}\s*?$}msix, | ||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 5 | my @do_first = qw( code lists ); | |||||||||||||||||||||||||||||||
| 52 | # for consistent order | ||||||||||||||||||||||||||||||||
| 53 | 5 | my @do_second = qw( b i u del tt heads blockquote links links2 br comments ); | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 56 | 4 | my $class = shift; | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 4 | my $self = bless { @_ }, $class; | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 4 | ▶ | die "body is a mandatory parameter" unless $self->{body}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 4 | return $self; | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 4 | ▶ | sub urls { | ||||||||||||||||||||||||||||||
|
Subroutine
urls: called CC=23 SCAR=35.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 66 | 4 | my $self= shift; | |||||||||||||||||||||||||||||||
| 67 | 4 | my $body = $self->{body}; | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | return unless $body; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 4 | my @links = $body =~m{(\[\[(?:[^\|\]]*)(?:\|(?:[^\]]+))?\]\])}g; | |||||||||||||||||||||||||||||||
| 72 | 4 | push @links, $body =~m{\s(https?://\S+)\s}g; | |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 4 | ▶ | my $links = $self->{_links} ||= {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_links"} ||= {}
MC/DC0%0/1
$self->{"_links"} ||= {}
$self->{"_links"}
Truth table50%1/2
A
A= $self->{"_links"}
| |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | LINK: | ||||||||||||||||||||||||||||||||
| 77 | 4 | for my $lnk ( @links ) { | |||||||||||||||||||||||||||||||
| 78 | 20 | ▶ | next if $links->{$lnk}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 20 | ▶ | my $hlnk = $links->{$lnk} ||= {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$links->{$lnk} ||= {}
MC/DC0%0/1
$links->{$lnk} ||= {}
$links->{$lnk}
Truth table50%1/2
A
A= $links->{$lnk}
| |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 20 | ▶ | if ($lnk =~ m{\Ahttps?://}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | 2 | %$hlnk = ( title => $lnk, href => $lnk, _class => 'external' ); | |||||||||||||||||||||||||||||||
| 84 | 2 | next LINK; | |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 18 | ($lnk) = $lnk =~ m{\A\[\[\s*(.*)\s*\]\]\z}g; | |||||||||||||||||||||||||||||||
| 88 | 18 | $lnk=~s{\s*\z}[]g; | |||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 18 | my ($label,$link) = split qr{\s*\|\s*}, $lnk, 2; | |||||||||||||||||||||||||||||||
| 91 | 18 | ▶ | unless ($link) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 92 | 7 | $link = $label; | |||||||||||||||||||||||||||||||
| 93 | 7 | ▶ | if ( $link =~ m{.*[\>\:]\s*([^\>]+)\z} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | 5 | $label = $1; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 18 | $hlnk->{title} = $label; | |||||||||||||||||||||||||||||||
| 99 | 18 | $hlnk->{original_to} = $link; | |||||||||||||||||||||||||||||||
| 100 | 18 | ▶ | if ($link =~ m{\Ahttps?://} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 101 | 1 | $hlnk->{_class} = 'external'; | |||||||||||||||||||||||||||||||
| 102 | 1 | $hlnk->{href} = $link; | |||||||||||||||||||||||||||||||
| 103 | 1 | next LINK; | |||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 17 | my ($base,$categ) = ('','/'); | |||||||||||||||||||||||||||||||
| 107 | 17 | ▶ | if ( $link =~ m{\A(\w+):} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | 2 | my ($namespace,$lnk) = split qr{:}, $link, 2; | |||||||||||||||||||||||||||||||
| 109 | 2 | $link = $lnk; | |||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | if ( my $nmsp = $namespaces{ $namespace } ){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | if (ref $nmsp eq 'HASH' ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 112 | 2 | ▶ | $base = $nmsp->{prefix} if $nmsp->{prefix}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | $categ = $nmsp->{category} if $nmsp->{category}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 114 | } elsif (ref $nmsp eq 'CODE') { | ||||||||||||||||||||||||||||||||
| 115 | 0 | ($base, $categ, $lnk) = $nmsp->($namespace,$link); | |||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( $lnk and $lnk =~ m{\Ahttps?://} ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$lnk and $lnk =~ m[\Ahttps?://]
MC/DC0%0/2
$lnk and $lnk =~ m[\Ahttps?://]
$lnk
$lnk =~ m[\Ahttps?://]
Truth table0%0/3
A and B
A= $lnkB= $lnk =~ m[\Ahttps?://]
| |||||||||||||||||||||||||||||||||
| 117 | 0 | $hlnk->{href} = $lnk; | |||||||||||||||||||||||||||||||
| 118 | 0 | $hlnk->{_class}='external'; | |||||||||||||||||||||||||||||||
| 119 | 0 | next LINK; | |||||||||||||||||||||||||||||||
| 120 | } elsif ( $lnk ) { | ||||||||||||||||||||||||||||||||
| 121 | 0 | $link = $lnk; | |||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | } else { | ||||||||||||||||||||||||||||||||
| 126 | 0 | warn "Unknow namespace: $namespace on $lnk\n"; | |||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 17 | ▶ | if ( $categ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 131 | 17 | $link =~ s{\s*\>\s*}{$categ}g; | |||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | 17 | ▶ | if ( $base ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 134 | 2 | $link = $base.$link; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | 17 | ▶ | unless ( $link =~ m{\Ahttps?://} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | 15 | $link = urify( $link ); | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | 17 | $hlnk->{href} = $link; | |||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 4 | ▶ | return wantarray ? %{$self->{_links}} : $self->{_links}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | 21 | ▶ | sub urify { | ||||||||||||||||||||||||||||||
|
Subroutine
urify: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 146 | 21 | my $link = shift; | |||||||||||||||||||||||||||||||
| 147 | 21 | ▶ | my $reg = shift || "^\\w\\-\\/\\s\\#"; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || '^\\w\\-\\/\\s\\#'
MC/DC100%1/1
shift() || '^\\w\\-\\/\\s\\#'
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 21 | $link =~ s{\s*\z}{}g; | |||||||||||||||||||||||||||||||
| 150 | 21 | ▶ | $link =~ s{\s*>\s*}{/}g unless $link =~ m{/}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 21 | $link = encode_entities( $link, $reg ); | |||||||||||||||||||||||||||||||
| 153 | 21 | $link =~ s{\s+}{-}g; | |||||||||||||||||||||||||||||||
| 154 | 21 | ▶ | while (my ($ent)=$link=~/\&(\#?\w+);/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | my $ec=$ent=~/(acute|grave|circ|uml|ring|slash|tilde|cedil)$/i? | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 156 | substr($ent,0,1):'_'; | ||||||||||||||||||||||||||||||||
| 157 | 0 | $link=~s/\&$ent;/$ec/ig; | |||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||
| 159 | 21 | $link="\L$link"; | |||||||||||||||||||||||||||||||
| 160 | 21 | $link=~s/\_+$//g; | |||||||||||||||||||||||||||||||
| 161 | 21 | $link=~s/\_+/\_/g; | |||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | 21 | return $link; | |||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub set_links { | ||||||||||||||||||||||||||||||
|
Subroutine
set_links: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 167 | 0 | my ($self, $links) = @_; | |||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | 0 | $self->{_links} = $links; | |||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 0 | return; | |||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | 3 | ▶ | sub format { | ||||||||||||||||||||||||||||||
|
Subroutine
format: called CC=23 SCAR=31.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 175 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||
| 176 | 3 | my $body = $self->{body}; | |||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | 3 | delete $self->{__headers}; | |||||||||||||||||||||||||||||||
| 179 | 3 | delete $self->{__toc}; | |||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | 3 | my %done = (); | |||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | 3 | $self->urls(); | |||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | 3 | $body =~ s{&}{&}g; | |||||||||||||||||||||||||||||||
| 186 | 3 | $body =~ s{<}{<}g; | |||||||||||||||||||||||||||||||
| 187 | 3 | $body =~ s{>}{>}g; | |||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | # closed tags | ||||||||||||||||||||||||||||||||
| 190 | 3 | for my $tag ( @do_first, @do_second, keys %closed ) { | |||||||||||||||||||||||||||||||
| 191 | 78 | ▶ | next if $done{ $tag }++; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | my ($re1, $re2, $re3, $re4, $re5, $re6) | ||||||||||||||||||||||||||||||||
| 194 | = ref $closed{ $tag } eq 'ARRAY' | ||||||||||||||||||||||||||||||||
| 195 | 24 | ? @{ $closed{ $tag } } | |||||||||||||||||||||||||||||||
| 196 | 39 | ▶ | : ( $closed{ $tag } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | 39 | ▶ | if (!$re2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 199 | 15 | my $in = 0; | |||||||||||||||||||||||||||||||
| 200 | 15 | ▶ | while ( $body =~ m{$re1}msix ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 201 | 10 | ▶ | my $tg = $in ? "</$tag>" :"<$tag>"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 202 | 10 | $body=~s{$re1}{$tg}msix; | |||||||||||||||||||||||||||||||
| 203 | 10 | $in = 1 - $in; | |||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||
| 205 | 15 | ▶ | $body.="</$tag>" if $in; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 206 | } else { | ||||||||||||||||||||||||||||||||
| 207 | 24 | ▶ | while ($body =~ m{$re1(.*?)$re2}msix) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 208 | 43 | my $in = $1; | |||||||||||||||||||||||||||||||
| 209 | 43 | my ($t1,$t2) = ("<$tag>","</$tag>"); | |||||||||||||||||||||||||||||||
| 210 | 43 | ▶ | if (ref $re3 eq 'Regexp') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 211 | 4 | ▶ | $re4 //= ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$re4 //= ""
MC/DC0%0/1
$re4 //= ""
$re4
Truth table50%1/2
A
A= $re4
| |||||||||||||||||||||||||||||||||
| 212 | 4 | $in =~ s{ $re3 }{$re4}msixg; | |||||||||||||||||||||||||||||||
| 213 | } elsif (ref $re3 eq 'CODE') { | ||||||||||||||||||||||||||||||||
| 214 | 39 | ($t1,$in,$t2) = $re3->($self, $t1, $in, $t2); | |||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||
| 216 | 43 | ▶ | $t1 //= ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$t1 //= ""
MC/DC0%0/1
$t1 //= ""
$t1
Truth table50%1/2
A
A= $t1
| |||||||||||||||||||||||||||||||||
| 217 | 43 | ▶ | $in //= ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$in //= ""
MC/DC0%0/1
$in //= ""
$in
Truth table50%1/2
A
A= $in
| |||||||||||||||||||||||||||||||||
| 218 | 43 | ▶ | $t2 //= ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$t2 //= ""
MC/DC0%0/1
$t2 //= ""
$t2
Truth table50%1/2
A
A= $t2
| |||||||||||||||||||||||||||||||||
| 219 | 43 | ▶ | $re5 //= ''; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$re5 //= ""
MC/DC100%1/1
$re5 //= ""
$re5
Truth table100%2/2
A
A= $re5
| |||||||||||||||||||||||||||||||||
| 220 | 43 | $body =~ s{$re1(.*?)$re2}{$t1$in$t2$re5}smxi; | |||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | 3 | for my $tag ( keys %nonclosed ) { | |||||||||||||||||||||||||||||||
| 226 | 3 | my ($re1) = ($nonclosed{ $tag } ); | |||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | 3 | $body =~ s{ $re1 }{<$tag />}msixg; | |||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | 3 | ▶ | while ($body =~ m[(?<!\{)\{\{(\w+)(?:[:\s](.+))?\}\}(?!\})]msix) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 232 | 2 | my ($plugin, $params) = ($1,$2); | |||||||||||||||||||||||||||||||
| 233 | 2 | $params = _parse_plugin_params($params); | |||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | 2 | my $res = ''; | |||||||||||||||||||||||||||||||
| 236 | 2 | ▶ | if ( $plugins{$plugin} ){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 237 | 2 | ▶ | $res = $plugins{ $plugin }->( $self, $plugin, $params ) // ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$plugins{$plugin}->($self, $plugin, $params) // ""
MC/DC0%0/1
$plugins{$plugin}->($self, $plugin, $params) // ""
$plugins{$plugin}->($self, $plugin, $params)
Truth table50%1/2
A
A= $plugins{$plugin}->($self, $plugin, $params)
| |||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||
| 240 | 2 | $body =~ s[(?<!\{)\{\{(\w+)(?:[:\s](.+))?\}\}(?!\})][$res]msix; | |||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | 3 | ▶ | while ($body =~ m[\/\+\+(\w+)(?:[:\s*](.+))?\+\+\/]msix) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 244 | 1 | my ($plugin, $params) = ($1,$2); | |||||||||||||||||||||||||||||||
| 245 | 1 | $params=~s{\A\s*}{}; | |||||||||||||||||||||||||||||||
| 246 | 1 | my @params = split qr{\s*,\s*}, $params; | |||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | 1 | my $res = ''; | |||||||||||||||||||||||||||||||
| 249 | 1 | ▶ | if ( $plugins{$plugin} ){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 250 | 1 | ▶ | $res = $plugins{ $plugin }->( $self, $plugin, @params ) // ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$plugins{$plugin}->($self, $plugin, @params) // ""
MC/DC0%0/1
$plugins{$plugin}->($self, $plugin, @params) // ""
$plugins{$plugin}->($self, $plugin, @params)
Truth table50%1/2
A
A= $plugins{$plugin}->($self, $plugin, @params)
| |||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | 1 | $body =~ s[\/\+\+(\w+)(?:[:\s*](.+))?\+\+\/][$res]msix; | |||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||
| 256 | 3 | return $body; | |||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | sub register_namespace { | ||||||||||||||||||||||||||||||
|
Subroutine
register_namespace: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 260 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | 0 | my ($namespace, $info, $override) = @_; | |||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | $namespaces{ $namespace } = $info | ||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if $override or !$namespaces{ $namespace }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$override or not $namespaces{$namespace}
MC/DC0%0/2
$override or not $namespaces{$namespace}
$override
not $namespaces{$namespace}
Truth table0%0/3
A or not(B)
A= $overrideB= not $namespaces{$namespace}
| |||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub register_plugin { | ||||||||||||||||||||||||||||||
|
Subroutine
register_plugin: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 269 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | 0 | my ($pluginname, $pluginref, $override) = @_; | |||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | $plugins{ $pluginname } = $pluginref | ||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if $override or !$plugins{ $pluginname }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$override or not $plugins{$pluginname}
MC/DC0%0/2
$override or not $plugins{$pluginname}
$override
not $plugins{$pluginname}
Truth table0%0/3
A or not(B)
A= $overrideB= not $plugins{$pluginname}
| |||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||
| 277 | 6 | ▶ | sub _header_id { | ||||||||||||||||||||||||||||||
|
Subroutine
_header_id: called CC=6 SCAR=18.4
| |||||||||||||||||||||||||||||||||
| 278 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||
| 279 | 6 | ▶ | my $headers = $self->{__headers} ||= {}; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"__headers"} ||= {}
MC/DC100%1/1
$self->{"__headers"} ||= {}
$self->{"__headers"}
Truth table100%2/2
A
A= $self->{"__headers"}
| |||||||||||||||||||||||||||||||||
| 280 | 6 | ▶ | my $headnames = $self->{__headnames} ||= {}; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"__headnames"} ||= {}
MC/DC100%1/1
$self->{"__headnames"} ||= {}
$self->{"__headnames"}
Truth table100%2/2
A
A= $self->{"__headnames"}
| |||||||||||||||||||||||||||||||||
| 281 | 6 | ▶ | my $toc = $self->{__toc} ||= []; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"__toc"} ||= []
MC/DC100%1/1
$self->{"__toc"} ||= []
$self->{"__toc"}
Truth table100%2/2
A
A= $self->{"__toc"}
| |||||||||||||||||||||||||||||||||
| 282 | 6 | my ($t1, $in, $t2) = @_; | |||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 6 | my ($type) = $in =~ m{^(!{1,6})\s}; | |||||||||||||||||||||||||||||||
| 285 | 6 | $in =~ s{^!*\s}{}; | |||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 6 | $t1 = 'h'.length($type); | |||||||||||||||||||||||||||||||
| 288 | 6 | $t2 = "</$t1>"; | |||||||||||||||||||||||||||||||
| 289 | 6 | $t1 = "<$t1>"; | |||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | 6 | my $id = urify($in, "^\\w\\-\\s"); | |||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | 6 | ▶ | if ($headers->{$id}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 294 | 0 | my $cnt = 1; | |||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | $cnt++ while $headers->{"${id}_$cnt"}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 296 | 0 | $id .= "_$cnt"; | |||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||
| 299 | 6 | $headnames->{$id} = $in; | |||||||||||||||||||||||||||||||
| 300 | 6 | $headers->{$id} = substr($t1, 2, 1); | |||||||||||||||||||||||||||||||
| 301 | 6 | push @$toc, $id; | |||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | 6 | substr($t1, -1, 0, " id='$id'"); | |||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||
| 305 | 6 | return $t1, $in, $t2; | |||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | 1 | ▶ | sub _escape_code { | ||||||||||||||||||||||||||||||
|
Subroutine
_escape_code: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 309 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | 1 | my ($t1, $in, $t2) = @_; | |||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||
| 313 | 1 | $in=~s{\n}{<br/>\n}gs; | |||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||
| 315 | 1 | $self->{__codecnt}++; | |||||||||||||||||||||||||||||||
| 316 | 1 | $self->{__codeblock}->{$self->{__codecnt}} = $in; | |||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||
| 318 | 1 | return '',"/++restore_code_block: $self->{__codecnt}++/", ''; | |||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||
| 321 | 2 | ▶ | sub _do_lists { | ||||||||||||||||||||||||||||||
|
Subroutine
_do_lists: called CC=18 SCAR=29.0
| |||||||||||||||||||||||||||||||||
| 322 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||
| 324 | 2 | my ($t1, $in, $t2) = @_; | |||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||
| 326 | 2 | my @lines = split qr{\n}ms, $in; | |||||||||||||||||||||||||||||||
| 327 | 2 | $in = ''; | |||||||||||||||||||||||||||||||
| 328 | 2 | my $cl = ''; | |||||||||||||||||||||||||||||||
| 329 | 2 | my $item; | |||||||||||||||||||||||||||||||
| 330 | 2 | for my $ln (@lines) { | |||||||||||||||||||||||||||||||
| 331 | 12 | ▶ | if ( $ln !~ m{^\s} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 332 | 12 | ▶ | if ($item) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 333 | 10 | $in .= "<li>$item</li>\n"; | |||||||||||||||||||||||||||||||
| 334 | 10 | $item = ''; | |||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||
| 336 | 12 | my ($nl,$l) = $ln =~ m{^([\*\#]+)\s+(.*)$}; | |||||||||||||||||||||||||||||||
| 337 | 12 | $ln = $l; | |||||||||||||||||||||||||||||||
| 338 | 12 | my $close = ''; | |||||||||||||||||||||||||||||||
| 339 | 12 | my $start = -1; | |||||||||||||||||||||||||||||||
| 340 | 12 | ▶ | if ($nl ne $cl) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 341 | 11 | for my $i (0..length($cl)-1) { | |||||||||||||||||||||||||||||||
| 342 | 23 | ▶ | next if !$close and substr($cl,$i,1) eq substr($nl, $i, 1); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $close and substr($cl, $i, 1) eq substr($nl, $i, 1)
MC/DC100%2/2
not $close and substr($cl, $i, 1) eq substr($nl, $i, 1)
not $close
substr($cl, $i, 1) eq substr($nl, $i, 1)
Truth table100%3/3
not(A) and B
A= not $closeB= substr($cl, $i, 1) eq substr($nl, $i, 1)
| |||||||||||||||||||||||||||||||||
| 343 | 4 | ▶ | $start = $i unless $close; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 344 | 4 | ▶ | $close = (substr($cl,$i,1) eq '#' ? "</ol>" : "</ul>").$close; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||
| 346 | 11 | ▶ | $start = length($cl) if $start == -1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 347 | 11 | ▶ | $in.=$close."\n" if $close; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 348 | 11 | for my $i ($start..length($nl)-1) { | |||||||||||||||||||||||||||||||
| 349 | 11 | ▶ | $in.= substr($nl, $i, 1) eq '#'?"<ol>":"<ul>"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||
| 351 | 11 | $cl = $nl; | |||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||
| 354 | 12 | $item .= $ln; | |||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||
| 356 | 2 | ▶ | if ($item) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 357 | 2 | $in .= "<li>$item</li>\n"; | |||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||
| 359 | 2 | ▶ | if ($cl) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 360 | 2 | for my $i (reverse 0..length($cl)-1) { | |||||||||||||||||||||||||||||||
| 361 | 7 | ▶ | $in.=substr($cl,$i,1) eq '#' ? "</ol>" : "</ul>"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||
| 363 | 2 | $in.="\n"; | |||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||
| 366 | 2 | return '',$in,''; | |||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||
| 369 | 11 | ▶ | sub _do_links { | ||||||||||||||||||||||||||||||
|
Subroutine
_do_links: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||
| 370 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||
| 372 | 11 | my (undef, $link, undef) = @_; | |||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||
| 374 | 11 | $link =~s{\>}[>]g; | |||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||
| 376 | 11 | ▶ | $self->urls() unless $self->{_links} and $self->{_links}->{$link}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_links"} and $self->{"_links"}{$link}
MC/DC0%0/2
$self->{"_links"} and $self->{"_links"}{$link}
$self->{"_links"}
$self->{"_links"}{$link}
Truth table33%1/3
A and B
A= $self->{"_links"}B= $self->{"_links"}{$link}
| |||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||
| 378 | 11 | ▶ | my $lnk = $self->{_links}->{$link} || {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_links'}{$link} || {}
MC/DC0%0/1
$self->{'_links'}{$link} || {}
$self->{'_links'}{$link}
Truth table50%1/2
A
A= $self->{'_links'}{$link}
| |||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||
| 380 | 11 | my ($t1,$t2) = ('','</a>'); | |||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||
| 382 | 11 | $t1 = "<a href='$lnk->{href}'"; | |||||||||||||||||||||||||||||||
| 383 | 11 | ▶ | my $class = $lnk->{class} || $lnk->{_class} || ''; | ||||||||||||||||||||||||||||||
|
Condition80%4/5
$lnk->{'class'} || $lnk->{'_class'} || ''
$lnk->{"class"} or $lnk->{"_class"}
MC/DC50%1/2
$lnk->{'class'} || $lnk->{'_class'} || ''
$lnk->{"class"}
$lnk->{"_class"}
Truth table66%2/3
A or B
A= $lnk->{"class"}B= $lnk->{"_class"}
| |||||||||||||||||||||||||||||||||
| 384 | 11 | ▶ | if ( $class ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 385 | 1 | $t1.=" class='$class'"; | |||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||
| 387 | 11 | $t1.='>'; | |||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | 11 | return $t1, $lnk->{title}, $t2; | |||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||
| 392 | 1 | ▶ | sub _handle_toc { | ||||||||||||||||||||||||||||||
|
Subroutine
_handle_toc: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 393 | 1 | my ($self) = shift; | |||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||
| 395 | 1 | my $toc = $self->{__toc}; | |||||||||||||||||||||||||||||||
| 396 | 1 | my $headers = $self->{__headers}; | |||||||||||||||||||||||||||||||
| 397 | 1 | my $headnames = $self->{__headnames}; | |||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||
| 399 | 1 | my $res = "\n"; | |||||||||||||||||||||||||||||||
| 400 | 1 | for my $head (@$toc) { | |||||||||||||||||||||||||||||||
| 401 | 6 | $res.='*'x$headers->{$head}; | |||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||
| 403 | 6 | $res.=' '; | |||||||||||||||||||||||||||||||
| 404 | 6 | $res.='[['.$headnames->{$head}.'|#'.$head."]]\n"; | |||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||
| 406 | 1 | $res.="\n"; | |||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||
| 408 | 1 | my $wf = (ref $self)->new(body => $res); | |||||||||||||||||||||||||||||||
| 409 | 1 | $res = $wf->format(); | |||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||
| 411 | 1 | $res = "<div class='toc'>$res</div>"; | |||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||
| 413 | 1 | return $res; | |||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||
| 416 | 1 | ▶ | sub _handle_image { | ||||||||||||||||||||||||||||||
|
Subroutine
_handle_image: called CC=16 SCAR=42.8
| |||||||||||||||||||||||||||||||||
| 417 | 1 | my ($self, $plugin, $params) = @_; | |||||||||||||||||||||||||||||||
| 418 | 1 | my $src; | |||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||
| 420 | 1 | ▶ | if (ref $params eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 421 | 1 | $src = shift @$params; | |||||||||||||||||||||||||||||||
| 422 | 1 | ▶ | if (@$params and ref $params->[0] eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$params and ref $params->[0] eq "HASH"
MC/DC0%0/2
@$params and ref $params->[0] eq "HASH"
@$params
ref $params->[0] eq "HASH"
Truth table33%1/3
A and B
A= @$paramsB= ref $params->[0] eq "HASH"
| |||||||||||||||||||||||||||||||||
| 423 | 0 | $params = $params->[0]; | |||||||||||||||||||||||||||||||
| 424 | } else { | ||||||||||||||||||||||||||||||||
| 425 | 1 | $params = { @$params }; | |||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||
| 427 | } else { | ||||||||||||||||||||||||||||||||
| 428 | 0 | $src = delete $params->{src}; | |||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||
| 431 | 1 | ▶ | return '<!-- no src - incorrect params? -->' unless $src; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||
| 433 | 1 | ▶ | if ($src =~ m{\Ahttps?://} and $self->{image_filter}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$src =~ m[\Ahttps?://] and $self->{"image_filter"}
MC/DC0%0/2
$src =~ m[\Ahttps?://] and $self->{"image_filter"}
$src =~ m[\Ahttps?://]
$self->{"image_filter"}
Truth table33%1/3
A and B
A= $src =~ m[\Ahttps?://]B= $self->{"image_filter"}
| |||||||||||||||||||||||||||||||||
| 434 | 0 | $src = $self->{image_filter}->($src, $params); | |||||||||||||||||||||||||||||||
| 435 | } elsif ($self->{image_mapper}) { | ||||||||||||||||||||||||||||||||
| 436 | 0 | $src = $self->{image_mapper}->($src, $params); | |||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||
| 439 | 1 | ▶ | return '<!-- image filtered/not mapped -->' unless $src; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||
| 441 | 1 | my $res = "<img src='$src'"; | |||||||||||||||||||||||||||||||
| 442 | 1 | ▶ | if ( $params->{size} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 443 | 0 | my ($w,$h) = $params->{size} =~ m{\A\d+x\d+\z}; | |||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if ($w and $h) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w and $h
MC/DC0%0/2
$w and $h
$w
$h
Truth table0%0/3
A and B
A= $wB= $h
| |||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | $params->{width} ||= $w; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$params->{"width"} ||= $w
MC/DC0%0/2
$params->{"width"} ||= $w
$params->{"width"}
$w
Truth table0%0/3
A ||= B
A= $params->{"width"}B= $w
| |||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | $params->{height} ||= $h; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$params->{"height"} ||= $h
MC/DC0%0/2
$params->{"height"} ||= $h
$params->{"height"}
$h
Truth table0%0/3
A ||= B
A= $params->{"height"}B= $h
| |||||||||||||||||||||||||||||||||
| 448 | 0 | delete $params->{size}; | |||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||
| 451 | 1 | for my $attr ( qw(alt title heigth width) ) { | |||||||||||||||||||||||||||||||
| 452 | 4 | ▶ | next unless $params->{ $attr }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 453 | 0 | my $av = $params->{ $attr }; | |||||||||||||||||||||||||||||||
| 454 | 0 | $av =~ s{&}{&}g; | |||||||||||||||||||||||||||||||
| 455 | 0 | $av =~ s{<}{>}g; | |||||||||||||||||||||||||||||||
| 456 | 0 | $av =~ s{>}{<}g; | |||||||||||||||||||||||||||||||
| 457 | 0 | $av =~ s{'}{'}g; | |||||||||||||||||||||||||||||||
| 458 | 0 | $res.=" $attr='$av'"; | |||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||
| 461 | 1 | $res.=' />'; | |||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||
| 463 | #MAYBETODO: support for caption, to allow to frame the images | ||||||||||||||||||||||||||||||||
| 464 | # and add a legend under the image. | ||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||
| 466 | 1 | return $res; | |||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||
| 469 | 1 | ▶ | sub _restore_code_block { | ||||||||||||||||||||||||||||||
|
Subroutine
_restore_code_block: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 470 | 1 | my ($self, $plugin, $block) = @_; | |||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||
| 472 | 1 | my $res = $self->{__codeblock}->{$block}; | |||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||
| 474 | 1 | return "<code>$res</code>"; | |||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||
| 477 | 2 | ▶ | sub _parse_plugin_params { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_plugin_params: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||
| 478 | 2 | my $paramstr = shift; | |||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||
| 480 | 2 | ▶ | return [] unless $paramstr; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||
| 482 | 1 | ▶ | unless ($paramstr =~ m(\A\s*[\{\[]) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 483 | 1 | $paramstr = '['.$paramstr.']'; | |||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||
| 486 | 1 | ▶ | my $params = eval { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 487 | 1 | from_json( $paramstr, { utf8 => 1 }) | |||||||||||||||||||||||||||||||
| 488 | } or do print STDERR "Error Parsing params: $paramstr ==> $@\n"; | ||||||||||||||||||||||||||||||||
| 489 | #MAYBETODO: export this error somehow? silent it? | ||||||||||||||||||||||||||||||||
| 490 | # exporting it may be useful - specially while previewing | ||||||||||||||||||||||||||||||||
| 491 | # the result. | ||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||
| 493 | 1 | return $params; | |||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||
| 496 | 5 | 1; | |||||||||||||||||||||||||||||||
| 497 | __END__ | ||||||||||||||||||||||||||||||||