| 1 | package MojoMojo::Formatter::Wiki; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 37 | ▶ | use parent qw/MojoMojo::Formatter/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 37 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 37 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 37 | ▶ | use MojoMojo::Formatter::TOC; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | MojoMojo::Formatter::Wiki - Handle interpage linking. | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | This formatter handles intra-Wiki links specified between double square brackets | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | or parentheses: [[wiki link]] or ((another wiki link)). It will also indicate | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | missing links with a question mark and a link to the edit page. Links can be | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | implicit (like the two above), where the path is derived from the link text | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | by replacing spaces with underscores (<a href="wiki_link">wiki link</a>), or | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | explicit, where the path is specified before a '|' sign: | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | [[/explicit/path|Link text goes here]] | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | Note that external links have a different syntax: [Link text](http://foo.com). | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | =head2 format_content_order | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | Format order can be 1-99. The Wiki formatter runs on 10. | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 620 | ▶ | sub format_content_order { 10 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_content_order: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ## list of start-end delimiter pairs | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 37 | my @explicit_delims = (qw{ \[\[ \]\] \(\( \)\) }); | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 37 | my $explicit_separator = '\|'; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 37 | my $wikiword_escape = qr{\\}; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 74 | ▶ | sub _explicit_start_delims { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_explicit_start_delims: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 74 | my %delims = @explicit_delims; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 74 | return keys %delims; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 111 | ▶ | sub _explicit_end_delims { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_explicit_end_delims: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 111 | my %delims = @explicit_delims; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 111 | return values %delims; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 37 | ▶ | sub _generate_explicit_start { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_explicit_start: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 37 | my $delims = join '|', _explicit_start_delims(); | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 37 | return qr{(?: $delims )}x; # non-capturing match | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 37 | ▶ | sub _generate_explicit_end { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_explicit_end: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 37 | my $delims = join '|', _explicit_end_delims(); | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 37 | return qr{(?: $delims )}x; # non-capturing match | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 37 | ▶ | sub _generate_explicit_path { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_explicit_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # non-greedily match characters that don't match the start-end and text delimiters | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 37 | my $not_an_end_delimiter_or_separator = '(?:(?!' . (join '|', _explicit_end_delims(), $explicit_separator) . ').)'; # produces (?: (?! ]] | \)\) | \| ) .) # a character in a place where neither a ]], nor a )), nor a | is | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 37 | return qr{$not_an_end_delimiter_or_separator+?}; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 37 | ▶ | sub _generate_explicit_text { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_explicit_text: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # non-greedily match characters that don't match the start-end delimiters | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 37 | my $not_an_end_delimiter = '(?:(?!' . ( join '|', _explicit_end_delims() ) . ').)'; # produces (?: (?! ]] | \)\) ) .) # a character in a place where neither a ]] nor a )) starts | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 37 | return qr{$not_an_end_delimiter+?}; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 37 | my $explicit_start = _generate_explicit_start(); | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 37 | my $explicit_end = _generate_explicit_end(); | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 37 | my $explicit_path = _generate_explicit_path(); | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 37 | my $explicit_text = _generate_explicit_text(); | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 37 | ▶ | sub _generate_non_wikiword_check { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_non_wikiword_check: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # FIXME: this evaluates incorrectly to a regexp that's clearly mistaken: (?x-ism:( ?<! [\[\[\(\((?-xism:\\)\/\?] )) | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # we include '\/' to avoid wikiwords that are parts of urls | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # but why the question mark ('\?') at the end? | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 37 | my $non_wikiword_chars = | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | ( join '', _explicit_start_delims() ) . $wikiword_escape . '\/' . '\?'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 37 | return qr{(?<! [$non_wikiword_chars])}x; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 37 | my $non_wikiword_check = _generate_non_wikiword_check(); | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | =head2 strip_pre | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | Replace <pre ... with a placeholder | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 159 | ▶ | sub strip_pre { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strip_pre: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 159 | my $content = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 159 | my ( @parts, $res ); | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 159 | $res = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 159 | ▶ | while ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | my ($part) = | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | $$content =~ m{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ^(.+?) | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | <\s*pre\b[^>]*>}sx | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # $$content =~ s{^.+?<\s*pre\b[^>]*>}{}sx; | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 17 | $$content =~ s{^.+?<\s*pre(?:\s+lang=['"]*(.*?)['"]*")?>}{}sx; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 17 | ▶ | my $lang = $1 || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$1 || ''
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 17 | my ($inner) = $$content =~ m{^(.+?)<\s*/pre\s*>}sx; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 17 | ▶ | unless ($inner) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $res .= $part; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 17 | push @parts, $inner; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 17 | $res .= $part . "<!--pre_placeholder::$lang-->"; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 17 | $$content =~ s{^.+?<\s*/pre\s*>}{}sx; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 159 | $res .= $$content; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 159 | return $res, @parts; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | =head2 reinsert_pre | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | Put pre and lang back into place. | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 159 | ▶ | sub reinsert_pre { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reinsert_pre: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 159 | my ( $content, @parts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 159 | foreach my $part (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 17 | $$content =~ s{<!--pre_placeholder::(.*?)-->}{<pre lang="$1">$part</pre>}sx; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 159 | return $$content; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | =head2 format_content | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | Calls the formatter. Takes a ref to the content as well as the | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | context object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # FIXME: should ACCEPT_CONTEXT? | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 149 | ▶ | sub format_content { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_content: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 149 | my ( $class, $content, $c, $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # Extract wikiwords, avoiding escaped and part of urls | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 149 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 149 | ( $$content, @parts ) = strip_pre($content); | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # Do explicit links, e.g. [[ /path/to/page | link text ]] | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 149 | $$content =~ s{ | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | $non_wikiword_check | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | $explicit_start | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | \s* | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ($explicit_path) | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | \s* | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | $explicit_separator | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | \s* | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | ($explicit_text) | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | \s* | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | )? | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | $explicit_end | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 109 | }{ $class->format_link($c, $1, $c->req->base, $2) }gex; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 149 | $$content =~ s{ | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | $non_wikiword_check | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | $explicit_start | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | \s* | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | $explicit_path | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | \s* | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | $explicit_separator | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | \s* | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | $explicit_text | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | \s* | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | )? | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | $explicit_end | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | }{ $1 }gx; | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # Remove escapes on escaped wikiwords. The escape means | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # that this wikiword is NOT a link to a wiki page. | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 149 | $$content =~ s{$wikiword_escape($explicit_start)}{$1}g; | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 149 | $$content = reinsert_pre( $content, @parts ); | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | =head2 format_link <c> <wikilink> <base> [<link_text>] | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | Format a wikilink as an HTML hyperlink with the given link_text. If the wikilink | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | doesn't exist, it will be rendered as a hyperlink to an .edit page ready to be | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | created. | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | Since there is no difference in syntax between new and existing links, some | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | abiguities my occur when it comes to characters that are invalid in URLs. For | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | example, | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | * [[say "NO" to #8]] should be rendered as C<< <a href="say_%22NO%22_to_%238">say "NO" to #8</a> >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | * [[100% match]] should be rendered as C<< <a href="100%25_match>100% match</a> >>, URL-escaping the '%' | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | * but what about a user pasting an existing link, C<[[say_%22NO%22_to_%238]]>? We shouldn't URL-escape the '%' or '#' here. | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | * for links with explicit link text, we should definitiely not URL-escape the link: C<[[say_%22NO%22_to_%238|say "NO" to #8]]> | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | This is complicated by the fact that '#' can delimit the start of the anchor portion of a link. | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | * C<[[Mambo #5]]> - URL-escape '#' => Mambo_%235 | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | * C<[[Mambo#origins]]> - do not URL-escape | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | * C<[[existing/link#Introduction|See the Introduction]]> - definitely do not URL-escape | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | Since escaping is somewhat magic and therefore potentially counter-intuitive, | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | we will: | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | * only URL-escape '#' if it follows a whitespace directly | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | * always URL-escape '%' unless it is followed by two uppercase hex digits | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | * always escape other characters that are invalid in URLs | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 171 | ▶ | sub format_link { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_link: called CC=27 SCAR=33.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | #FIXME: why both base and $c? | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 171 | my ( $class, $c, $wikilink, $base, $link_text, $action) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | 171 | ▶ | $base ||= $c->req->base; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$base ||= $c->req->base
MC/DC0%0/2
$base ||= $c->req->base
$base
$c->req->base
Truth table33%1/3
A ||= B
A= $baseB= $c->req->base
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # The following control structures are used to build the wikilink | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # from the stashed path and $wikilink passed to this function. | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # May as well smoke the page stash from MojoMojo.pm since we got it eh? | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 171 | my $stashed_path = $c->stash->{path}; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # If the wikilink starts with a slash the pass it on through | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 171 | my $pass_wikilink_through; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | 171 | ▶ | if ( $wikilink =~ m{^/} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 85 | $pass_wikilink_through = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # Make sure the $stashed_path starts with a bang, uh I mean slash. | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | elsif ( $stashed_path ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 69 | ▶ | $stashed_path = '/' . $stashed_path if $stashed_path !~ m{^/}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 17 | else { $stashed_path = '/'; } | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # Handle sibling case by making look it like the rest. | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 171 | ▶ | if ( my ($sibling) = $wikilink =~ m'^\.\./(.*)$' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | my ($parent) = $stashed_path =~ m'(.*)/.*$'; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 3 | $wikilink = $parent . '/' . $sibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | elsif ( !$pass_wikilink_through ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 83 | $wikilink = $stashed_path . '/' . $wikilink; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # Old School Method: | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # $wikilink = ( blessed $c->stash->{page} ? $c->stash->{page}->path : $c->stash->{page}->{path} ). '/' . $wikilink | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # unless $wikilink =~ m'^(\.\.)?/'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 171 | ▶ | $c = MojoMojo->context unless ref $c; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # keep the original wikilink for display, stripping leading slashes | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 171 | my $orig_wikilink = $wikilink; | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | 171 | ▶ | if ( $orig_wikilink =~ m|^ \s* /+ \s* $|x ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 14 | $orig_wikilink = '/'; | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 157 | $orig_wikilink =~ s/.*\///; | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 171 | my $fragment = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 269 | 171 | for ($wikilink) { | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | 171 | s/(?<!\s)#(.*)/$fragment = $1, ''/e; # trim the anchor (fragment) portion away, in preparation for the page search below, and save it in $fragment | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | 171 | s/\s/_/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # MojoMojo doesn't support periods in wikilinks because they conflict with actions ('.edit', '.info' etc.); | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # actions are a finite set apparently, but it's possible to add new actions from formatter plugins (e.g. Comment). | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # At the same time, parent links (../sibling) or (../../nephew) should be left alone, but any other '.' should be replaced by '_' | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 171 | s'^(\.\./)+'MOJOMOJO_RESERVED_TREE_CROSSING_LINK'g; | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | 171 | s/\./_/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | 171 | s'MOJOMOJO_RESERVED_TREE_CROSSING_LINK'../'g; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | # if there's no link text, URL-escape characters in the wikilink that are not valid in URLs | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 171 | ▶ | if (!defined $link_text or $link_text eq '') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $link_text or $link_text eq ""
MC/DC50%1/2
not defined $link_text or $link_text eq ""
not defined $link_text
$link_text eq ""
Truth table66%2/3
not(A) or B
A= not defined $link_textB= $link_text eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 111 | s/%(?![0-9A-F]{2}) # escape '%' unless it's followed by two uppercase hex digits | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | | (?<=_)\# # escape '#' only if it directly follows a whitespace (which had been replaced by a '_') | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | | [":<=>?{|}] # escape all other characters that are invalid in URLs | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 6 | /sprintf('%%%02X', ord($&))/egx; # all other characters in the 0x21..0x7E range are OK in URLs; see the conflicting guidelines at http://www.ietf.org/rfc/rfc1738.txt and http://labs.apache.org/webarch/uri/rfc/rfc3986.html#reserved | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # if the fragment was not properly formatted as a fragment (per the rules explained in MojoMojo::Formatter::TOC::assembleAnchorName, i.e. i has an invalid character), convert it, unless it contains escaped characters already (.[0-9A-F]{2}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 171 | ▶ | if(MojoMojo::Formatter::TOC->module_loaded){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 171 | ▶ | $fragment = MojoMojo::Formatter::TOC::assembleAnchorName(undef, undef, undef, undef, $fragment) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$fragment ne "" and $fragment =~ /[^A-Za-z0-9_:.-]/ || !($fragment =~ /\.[0-9A-F]{2}/)
$fragment =~ /[^A-Za-z0-9_:.-]/ or not $fragment =~ /\.[0-9A-F]{2}/
MC/DC100%3/3
$fragment ne "" and $fragment =~ /[^A-Za-z0-9_:.-]/ || !($fragment =~ /\.[0-9A-F]{2}/)
$fragment ne ""
$fragment =~ /[^A-Za-z0-9_:.-]/
not $fragment =~ /\.[0-9A-F]{2}/
Truth table100%4/4
A and B or not(C)
A= $fragment ne ""B= $fragment =~ /[^A-Za-z0-9_:.-]/C= not $fragment =~ /\.[0-9A-F]{2}/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | if $fragment ne '' and ($fragment =~ /[^A-Za-z0-9_:.-]/ or $fragment !~ /\.[0-9A-F]{2}/); | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 171 | ▶ | my $formatted = $link_text || $class->expand_wikilink($orig_wikilink); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$link_text || $class->expand_wikilink($orig_wikilink)
MC/DC0%0/2
$link_text || $class->expand_wikilink($orig_wikilink)
$link_text
$class->expand_wikilink($orig_wikilink)
Truth table66%2/3
A || B
A= $link_textB= $class->expand_wikilink($orig_wikilink)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # convert relative paths to absolute paths | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 171 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
$c->stash->{"page"} and ref $c->stash->{"page"} eq "MojoMojo::Model::DBIC::Page" and not $wikilink =~ m[^/]
$c->stash->{"page"} and ref $c->stash->{"page"} eq "MojoMojo::Model::DBIC::Page"
MC/DC0%0/3
$c->stash->{"page"} and ref $c->stash->{"page"} eq "MojoMojo::Model::DBIC::Page" and not $wikilink =~ m[^/]
$c->stash->{"page"}
ref $c->stash->{"page"} eq "MojoMojo::Model::DBIC::Page"
not $wikilink =~ m[^/]
Truth table50%2/4
A and B and not(C)
A= $c->stash->{"page"}B= ref $c->stash->{"page"} eq "MojoMojo::Model::DBIC::Page"C= not $wikilink =~ m[^/]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | $c->stash->{page} | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | && | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # drop spaces | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | ref $c->stash->{page} eq 'MojoMojo::Model::DBIC::Page' && $wikilink !~ m|^/| | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $wikilink = URI->new_abs( $wikilink, $c->stash->{page}->path . "/" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | ▶ | elsif ( $c->stash->{page_path} && $wikilink !~ m|^/| ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$c->stash->{"page_path"} and not $wikilink =~ m[^/]
MC/DC0%0/2
$c->stash->{"page_path"} and not $wikilink =~ m[^/]
$c->stash->{"page_path"}
not $wikilink =~ m[^/]
Truth table66%2/3
A and not(B)
A= $c->stash->{"page_path"}B= not $wikilink =~ m[^/]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $wikilink = URI->new_abs( $wikilink, $c->stash->{page_path} . "/" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # make sure that base URL has no trailing slash, since the page path will have a leading slash | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 171 | my $url = $base; | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | 171 | $url =~ s/[\/]+$//; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # remove http://host/ from url | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 171 | $url =~ s!^https?://[^/]+!!; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # use the normalized path string returned by path_pages: | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 171 | my ( $path_pages, $proto_pages ) = $c->model('DBIC::Page')->path_pages($wikilink); | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | 171 | ▶ | if ( defined $proto_pages && @$proto_pages ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $proto_pages and @$proto_pages
MC/DC100%2/2
defined $proto_pages and @$proto_pages
defined $proto_pages
@$proto_pages
Truth table100%3/3
A and B
A= defined $proto_pagesB= @$proto_pages
| |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 63 | my $proto_page = pop @$proto_pages; | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | 63 | $url .= $proto_page->{path}; | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | 63 | ▶ | if ( $action) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 6 | $url .= ".$action" ; | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | 6 | return qq{<a class="existingWikiWord" href="$url">$formatted</a>}; | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 57 | return qq{<span class="newWikiWord"><a title="} | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | . $c->loc('Not found. Click to create this page.') | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | . qq{" href="$url.edit">$formatted?</a></span>}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 108 | my $page = pop @$path_pages; | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | 108 | $url .= $page->path; | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | 108 | ▶ | $url .= ".$action" if $action; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 108 | ▶ | $url .= "#$fragment" if $fragment ne ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 108 | return qq{<a class="existingWikiWord" href="$url">$formatted</a>}; | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | =head2 expand_wikilink <wikilink> | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | Replace C<_> with spaces and unescape URL-encoded characters | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 217 | ▶ | sub expand_wikilink { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_wikilink: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 217 | my ( $class, $wikilink ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | 217 | for ($wikilink) { | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 217 | s/\_/ /g; | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | 217 | s/%([0-9A-F]{2})/chr(hex($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 217 | return $wikilink; | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | =head2 find_links <content> <page> | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | Find wiki links in content. | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | Return a listref of linked (existing) and wanted pages. | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 10 | ▶ | sub find_links { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_links: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 10 | my ( $class, $content, $page ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | 10 | my @linked_pages; | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | my @wanted_pages; | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 10 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | 10 | ( $$content, @parts ) = strip_pre($content); | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 10 | my $explicit_regex = | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | qr/$non_wikiword_check$explicit_start \s* ($explicit_path) \s* (?: $explicit_separator \s* $explicit_text \s* )? $explicit_end/x; | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 10 | ▶ | while ( $$content =~ /$explicit_regex/g ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 13 | my $link = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 376 | 13 | $link =~ s/\s/_/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # convert relative paths to absolute paths | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 13 | ▶ | if ( $link !~ m|^/| ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 8 | ▶ | $link = URI->new_abs( $link, ( $page->path || '' ) . "/" ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$page->path || ''
MC/DC0%0/1
$page->path || ''
$page->path
Truth table50%1/2
A
A= $page->path
| |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # use the normalized path string returned by path_pages: | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 13 | my ( $path_pages, $proto_pages ) = | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | $page->result_source->resultset->path_pages($link); | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 13 | ▶ | if ( defined $proto_pages && @$proto_pages ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $proto_pages and @$proto_pages
MC/DC100%2/2
defined $proto_pages and @$proto_pages
defined $proto_pages
@$proto_pages
Truth table100%3/3
A and B
A= defined $proto_pagesB= @$proto_pages
| |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 5 | push @wanted_pages, pop @$proto_pages; | |||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 8 | push @linked_pages, pop @$path_pages; | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 10 | $$content = reinsert_pre( $content, @parts ); | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | 10 | return ( \@linked_pages, \@wanted_pages ); | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | L<MojoMojo>, L<Module::Pluggable::Ordered> | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | Marcus Ramberg <mramberg@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | This library is free software. You can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 37 | 1; | |||||||||||||||||||||||||||||||||||||||||||||