line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::LinkTo; |
2
|
2
|
|
|
2
|
|
216918
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
90
|
|
3
|
2
|
|
|
2
|
|
72
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
83
|
|
4
|
2
|
|
|
2
|
|
12
|
use base 'Template::Plugin'; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
2601
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.093'; |
7
|
|
|
|
|
|
|
my @HTML_OPTIONS = qw/href target confirm title img class rel/; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my %escaped = ( '&' => 'amp', '<' => 'lt', '>' => 'gt', '"' => 'quot' ); |
10
|
|
|
|
|
|
|
sub escape { |
11
|
165
|
100
|
|
165
|
0
|
916
|
my $str = shift or return ''; |
12
|
74
|
|
|
|
|
219
|
$str =~ s{([&<>"])(?!amp;)}{'&' . $escaped{$1} . ';'}msxgeo; |
|
27
|
|
|
|
|
133
|
|
13
|
74
|
|
|
|
|
269
|
$str; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub link_to { |
17
|
25
|
|
|
25
|
0
|
377807
|
my ($self, $text, $opt) = @_; |
18
|
|
|
|
|
|
|
|
19
|
25
|
100
|
|
|
|
147
|
$text = $opt->{img} ? qq{} : escape $text; #" |
20
|
25
|
|
|
|
|
54
|
my $result = $text; |
21
|
|
|
|
|
|
|
|
22
|
25
|
100
|
|
|
|
95
|
if (my $href = escape $opt->{href}) { |
23
|
21
|
100
|
|
|
|
81
|
my $target = ($opt->{target} = escape $opt->{target}) |
24
|
|
|
|
|
|
|
? qq/target="$opt->{target}"/ |
25
|
|
|
|
|
|
|
: ''; |
26
|
21
|
100
|
|
|
|
242
|
my $confirm = ($opt->{confirm} = escape $opt->{confirm}) |
27
|
|
|
|
|
|
|
? qq/onclick="return confirm('$opt->{confirm}');"/ |
28
|
|
|
|
|
|
|
: ''; |
29
|
21
|
100
|
|
|
|
90
|
my $title = ($opt->{title} = escape $opt->{title}) |
30
|
|
|
|
|
|
|
? qq/title="$opt->{title}"/ |
31
|
|
|
|
|
|
|
: ''; |
32
|
21
|
100
|
|
|
|
90
|
my $class = ($opt->{class} = escape $opt->{class}) |
33
|
|
|
|
|
|
|
? qq/class="$opt->{class}"/ |
34
|
|
|
|
|
|
|
: ''; |
35
|
21
|
100
|
|
|
|
82
|
my $rel = ($opt->{rel} = escape $opt->{rel}) |
36
|
|
|
|
|
|
|
? qq/rel="$opt->{rel}"/ |
37
|
|
|
|
|
|
|
: ''; |
38
|
|
|
|
|
|
|
|
39
|
21
|
|
|
|
|
64
|
for my $key (@HTML_OPTIONS) { |
40
|
147
|
|
|
|
|
261
|
delete $opt->{$key}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
21
|
|
|
|
|
33
|
my $params; |
44
|
21
|
|
|
|
|
122
|
for my $key (sort keys %$opt) { |
45
|
16
|
|
|
|
|
55
|
$params .= qq/&$key=$opt->{$key}/; |
46
|
|
|
|
|
|
|
} |
47
|
21
|
100
|
|
|
|
78
|
if ($params) { |
48
|
11
|
|
|
|
|
22
|
$params = escape $params; |
49
|
11
|
|
|
|
|
27
|
$href .= $params; |
50
|
11
|
100
|
|
|
|
69
|
$href =~ s/&/?/ |
51
|
|
|
|
|
|
|
if $href !~ m/\?/; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
21
|
|
|
|
|
2139
|
$result = qq{$text}; |
55
|
21
|
|
|
|
|
154
|
$result =~ s/\s{2,}/ /g; |
56
|
21
|
|
|
|
|
120
|
$result =~ s/\s>/>/; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
25
|
|
|
|
|
129
|
return $result; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |