| 1 | package Text::AsciidocDown::Refs; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 18 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 18 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 18 | our $VERSION = '0.1.3'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | sub new_index | ||||||||||||||||||||||||||||
| 9 | 99 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new_index: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | return { | ||||||||||||||||||||||||||||
| 11 | 99 | by_id => {}, | |||||||||||||||||||||||||||
| 12 | by_title => {}, | ||||||||||||||||||||||||||||
| 13 | }; | ||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub register_heading | ||||||||||||||||||||||||||||
| 17 | 36 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
register_heading: called CC=7 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 36 | my ($idx, $attrs, $title, $explicit_id, $reftext) = @_; | |||||||||||||||||||||||||||
| 19 | 36 | ▶ | return unless ref($idx) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 36 | my $auto_id = _auto_id($attrs, $title); | |||||||||||||||||||||||||||
| 22 | 36 | ▶ | my $id = defined($explicit_id) && $explicit_id ne '' ? $explicit_id : $auto_id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $explicit_id and $explicit_id ne ""
MC/DC0%0/2
defined $explicit_id and $explicit_id ne ""
defined $explicit_id
$explicit_id ne ""
Truth table33%1/3
A and B
A= defined $explicit_idB= $explicit_id ne ""
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 36 | ▶ | my $entry = { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $reftext and $reftext ne ""
MC/DC0%0/2
defined $reftext and $reftext ne ""
defined $reftext
$reftext ne ""
Truth table33%1/3
A and B
A= defined $reftextB= $reftext ne ""
| |||||||||||||||||||||||||||||
| 25 | id => $id, | ||||||||||||||||||||||||||||
| 26 | auto_id => $auto_id, | ||||||||||||||||||||||||||||
| 27 | title => $title, | ||||||||||||||||||||||||||||
| 28 | reftext => (defined($reftext) && $reftext ne '') ? $reftext : $title, | ||||||||||||||||||||||||||||
| 29 | }; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 36 | $idx->{by_id}{$id} = $entry; | |||||||||||||||||||||||||||
| 32 | 36 | ▶ | $idx->{by_title}{$title} ||= $entry; | ||||||||||||||||||||||||||
|
Condition33%1/3
$idx->{"by_title"}{$title} ||= $entry
MC/DC0%0/2
$idx->{"by_title"}{$title} ||= $entry
$idx->{"by_title"}{$title}
$entry
Truth table33%1/3
A ||= B
A= $idx->{"by_title"}{$title}B= $entry
| |||||||||||||||||||||||||||||
| 33 | 36 | return $entry; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub resolve_target | ||||||||||||||||||||||||||||
| 37 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
resolve_target: called CC=6 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 6 | my ($idx, $target) = @_; | |||||||||||||||||||||||||||
| 39 | 6 | ▶ | return undef unless ref($idx) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 6 | ▶ | return undef unless defined $target && $target ne ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $target and $target ne ""
MC/DC0%0/2
defined $target and $target ne ""
defined $target
$target ne ""
Truth table33%1/3
A and B
A= defined $targetB= $target ne ""
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 6 | ▶ | return $idx->{by_id}{$target} if exists $idx->{by_id}{$target}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 5 | ▶ | return $idx->{by_title}{$target} if exists $idx->{by_title}{$target}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 4 | return undef; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub rewrite_links | ||||||||||||||||||||||||||||
| 48 | 98 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
rewrite_links: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 98 | my ($idx, $markdown) = @_; | |||||||||||||||||||||||||||
| 50 | 98 | ▶ | return '' unless defined $markdown; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 98 | ▶ | return $markdown unless ref($idx) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 98 | $markdown =~ s{\[([^\]]+)\]\(#!([^\)]+)\)}{_rewrite_link($idx, $1, $2)}ge; | |||||||||||||||||||||||||||
| 54 | 98 | return $markdown; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub _rewrite_link | ||||||||||||||||||||||||||||
| 58 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_rewrite_link: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 59 | 6 | my ($idx, $label, $target) = @_; | |||||||||||||||||||||||||||
| 60 | 6 | my $entry = resolve_target($idx, $target); | |||||||||||||||||||||||||||
| 61 | 6 | ▶ | if ($entry) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | 2 | return '[' . $label . '](#' . $entry->{auto_id} . ')'; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 4 | return '[' . $label . '](#' . $target . ')'; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub _auto_id | ||||||||||||||||||||||||||||
| 69 | 36 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_auto_id: called CC=7 SCAR=20.8
| |||||||||||||||||||||||||||||
| 70 | 36 | my ($attrs, $title) = @_; | |||||||||||||||||||||||||||
| 71 | 36 | ▶ | $title = '' unless defined $title; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 36 | ▶ | my $idprefix = ref($attrs) eq 'HASH' ? ($attrs->{idprefix} // '_') : '_'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$attrs->{"idprefix"} // "_"
MC/DC0%0/1
$attrs->{"idprefix"} // "_"
$attrs->{"idprefix"}
Truth table50%1/2
A
A= $attrs->{"idprefix"}
| |||||||||||||||||||||||||||||
| 73 | 36 | ▶ | my $idseparator = ref($attrs) eq 'HASH' ? ($attrs->{idseparator} // '_') : '_'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$attrs->{"idseparator"} // "_"
MC/DC0%0/1
$attrs->{"idseparator"} // "_"
$attrs->{"idseparator"}
Truth table50%1/2
A
A= $attrs->{"idseparator"}
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 36 | my $slug = lc $title; | |||||||||||||||||||||||||||
| 76 | 36 | $slug =~ s/[^a-z0-9]+/ /g; | |||||||||||||||||||||||||||
| 77 | 36 | $slug =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||
| 78 | 36 | $slug =~ s/\s+/$idseparator/g; | |||||||||||||||||||||||||||
| 79 | 36 | ▶ | $slug = 'section' if $slug eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 36 | return $idprefix . $slug; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 18 | 1; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||