blib/lib/Template/Plugin/LinkTo.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 20 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 96.9% 64 / 66 CC 13 SCAR 21.8
CC
13
Cov
100%
link_to
12.0
escape
2.0
BEGIN
1.0
CRAP 8.9
↑ Summary
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
BranchTrueFalseTotal
my $str = shift() or return "" 74 91 165
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
BranchTrueFalseTotal
$opt->{'img'} ? : 1 24 25
20 25 my $result = $text;
21  
22 25 ▶ if (my $href = escape $opt->{href}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $href = escape($opt->{"href"})) 21 4 25
23 my $target = ($opt->{target} = escape $opt->{target})
24 21 ▶ ? qq/target="$opt->{target}"/
Branch: 1 branch
BranchTrueFalseTotal
($opt->{'target'} = escape($opt->{'target'})) ? : 11 10 21
25 : '';
26 my $confirm = ($opt->{confirm} = escape $opt->{confirm})
27 21 ▶ ? qq/onclick="return confirm('$opt->{confirm}');"/
Branch: 1 branch
BranchTrueFalseTotal
($opt->{'confirm'} = escape($opt->{'confirm'})) ? : 5 16 21
28 : '';
29 my $title = ($opt->{title} = escape $opt->{title})
30 21 ▶ ? qq/title="$opt->{title}"/
Branch: 1 branch
BranchTrueFalseTotal
($opt->{'title'} = escape($opt->{'title'})) ? : 1 20 21
31 : '';
32 my $class = ($opt->{class} = escape $opt->{class})
33 21 ▶ ? qq/class="$opt->{class}"/
Branch: 1 branch
BranchTrueFalseTotal
($opt->{'class'} = escape($opt->{'class'})) ? : 1 20 21
34 : '';
35 my $rel = ($opt->{rel} = escape $opt->{rel})
36 21 ▶ ? qq/rel="$opt->{rel}"/
Branch: 1 branch
BranchTrueFalseTotal
($opt->{'rel'} = escape($opt->{'rel'})) ? : 1 20 21
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
BranchTrueFalseTotal
if ($params) 11 10 21
48 11 $params = escape $params;
49 11 $href .= $params;
50 11 ▶ $href =~ s/&amp;/?/
Branch: 1 branch
BranchTrueFalseTotal
unless $href =~ /\?/ 5 6 11
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__
↑ Summary