| 1 | package Template::Plugin::LinkTo; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use base 'Template::Plugin'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | our $VERSION = '0.093'; | |||||||||
| 7 | 2 | my @HTML_OPTIONS = qw/href target confirm title img class rel/; | |||||||||
| 8 | |||||||||||
| 9 | 2 | my %escaped = ( '&' => 'amp', '<' => 'lt', '>' => 'gt', '"' => 'quot' ); | |||||||||
| 10 | 165 | ▶ | sub escape { | ||||||||
|
Subroutine
escape: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 11 | 165 | ▶ | my $str = shift or return ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 12 | 74 | $str =~ s{([&<>"])(?!amp;)}{'&' . $escaped{$1} . ';'}msxgeo; | |||||||||
| 13 | 74 | $str; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 25 | ▶ | sub link_to { | ||||||||
|
Subroutine
link_to: called CC=12 SCAR=24.8
Pod
undocumented
| |||||||||||
| 17 | 25 | my ($self, $text, $opt) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 25 | ▶ | $text = $opt->{img} ? qq{<img src="$opt->{img}" />} : escape $text; #" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 25 | my $result = $text; | |||||||||
| 21 | |||||||||||
| 22 | 25 | ▶ | if (my $href = escape $opt->{href}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | my $target = ($opt->{target} = escape $opt->{target}) | ||||||||||
| 24 | 21 | ▶ | ? qq/target="$opt->{target}"/ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | : ''; | ||||||||||
| 26 | my $confirm = ($opt->{confirm} = escape $opt->{confirm}) | ||||||||||
| 27 | 21 | ▶ | ? qq/onclick="return confirm('$opt->{confirm}');"/ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | : ''; | ||||||||||
| 29 | my $title = ($opt->{title} = escape $opt->{title}) | ||||||||||
| 30 | 21 | ▶ | ? qq/title="$opt->{title}"/ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | : ''; | ||||||||||
| 32 | my $class = ($opt->{class} = escape $opt->{class}) | ||||||||||
| 33 | 21 | ▶ | ? qq/class="$opt->{class}"/ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | : ''; | ||||||||||
| 35 | my $rel = ($opt->{rel} = escape $opt->{rel}) | ||||||||||
| 36 | 21 | ▶ | ? qq/rel="$opt->{rel}"/ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | : ''; | ||||||||||
| 38 | |||||||||||
| 39 | 21 | for my $key (@HTML_OPTIONS) { | |||||||||
| 40 | 147 | delete $opt->{$key}; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 21 | my $params; | |||||||||
| 44 | 21 | for my $key (sort keys %$opt) { | |||||||||
| 45 | 16 | $params .= qq/&$key=$opt->{$key}/; | |||||||||
| 46 | } | ||||||||||
| 47 | 21 | ▶ | if ($params) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 11 | $params = escape $params; | |||||||||
| 49 | 11 | $href .= $params; | |||||||||
| 50 | 11 | ▶ | $href =~ s/&/?/ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | if $href !~ m/\?/; | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 21 | $result = qq{<a href="$href" $target $confirm $title $class $rel>$text</a>}; | |||||||||
| 55 | 21 | $result =~ s/\s{2,}/ /g; | |||||||||
| 56 | 21 | $result =~ s/\s>/>/; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 25 | return $result; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 2 | 1; | |||||||||
| 63 | |||||||||||
| 64 | __END__ | ||||||||||