blib/lib/Template/Plugin/AutoLink.pm

filter: Statementstmt 44.0% 22 / 50 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 2 totaltotal 33.7% 26 / 77 CC 9 SCAR 40.7
CC
9
Cov
33%
filter
90.0
init
2.0
BEGIN
1.0
CRAP 58.3
↑ Summary
1 package Template::Plugin::AutoLink;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION $TextRe $TagRe $TagRe_ $UrlRe);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 $VERSION = '0.03';
6  
7 1 ▶use Template::Plugin::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use base qw( Template::Plugin::Filter );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 $TextRe = q{[^<]*};
11 1 $TagRe_ = q{[^"'<>]*(?:"[^"]*"[^"'<>]*|'[^']*'[^"'<>]*)*(?:>|(?=<)|$(?!\n))}; #'}}}};
12 1 my $comment_tag_re = '<!(?:--[^-]*-(?:[^-]+-)*?-(?:[^>-]*(?:-[^>-]+)*?)??)*(?:>|$(?!\n)|--.*$)';
13 1 $TagRe = qq{$comment_tag_re|<$TagRe_};
14  
15 1 my $http_url_re =
16 q{\b(?:https?|shttp)://(?:(?:[-_.!~*'()a-zA-Z0-9;:&=+$,]|%[0-9A-Fa-f} .
17 q{][0-9A-Fa-f])*@)?(?:(?:[a-zA-Z0-9](?:[-a-zA-Z0-9]*[a-zA-Z0-9])?\.)} .
18 q{*[a-zA-Z](?:[-a-zA-Z0-9]*[a-zA-Z0-9])?\.?|[0-9]+\.[0-9]+\.[0-9]+\.} .
19 q{[0-9]+)(?::[0-9]*)?(?:/(?:[-_.!~*'()a-zA-Z0-9:@&=+$,]|%[0-9A-Fa-f]} .
20 q{[0-9A-Fa-f])*(?:;(?:[-_.!~*'()a-zA-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40 q{\[\]\000-\037\x80-\xff])|"[^\\\\\x80-\xff\n\015"]*(?:\\\\[^\x80-\xff][} .
41 q{^\\\\\x80-\xff\n\015"]*)*")(?:\.(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x} .
42 q{80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff])|"[^\\\\\x80-} .
43 q{\xff\n\015"]*(?:\\\\[^\x80-\xff][^\\\\\x80-\xff\n\015"]*)*"))*@(?:[^(} .
44 q{\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\0} .
45 q{00-\037\x80-\xff])|\[(?:[^\\\\\x80-\xff\n\015\[\]]|\\\\[^\x80-\xff])*} .
46 q{\])(?:\.(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,} .
47 q{;:".\\\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\\\x80-\xff\n\015\[\]]|\\\\[} .
48 q{^\x80-\xff])*\]))*};
49  
50 1 $UrlRe = "($http_url_re|$ftp_url_re|($mail_re))";
51  
52 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
53 0 my $self = shift;
54 0 $self->{_DYNAMIC} = 1;
55 0 $self->install_filter('auto_link');
56 0 return $self;
57 }
58  
59 0 ▶sub filter {
Subroutine filter: not called CC=9 SCAR=45.0
Pod undocumented
60 0 my ($self, $str, $args, $config) = @_;
61  
62 0 $config = $self->merge_config($config);
63 my $anchor = sprintf '<a %s href="',
64 0 join ' ', map {qq|$_="$config->{$_}"|} keys %{$config};
65  
66 0 my $result = '';
67 0 my $skip = 0;
68 0 ▶ while ($str =~ /($TextRe)($TagRe)?/gso) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /($Template::Plugin::AutoLink::TextRe)($Template::Plugin::AutoLink::TagRe)?/sog) 0 0 0
69 0 ▶ last if $1 eq '' and $2 eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "" and $2 eq "" 0 0 0
Condition0%0/3
$1 eq "" and $2 eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
$1 eq "" and $2 eq ""
$1 eq "" $2 eq ""
Truth table0%0/3
A and B
A= $1 eq ""B= $2 eq ""
ABresult
0X0
100
111
70 0 my $text_tmp = $1;
71 0 my $tag_tmp = $2;
72 0 ▶ if ($skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) { } 0 0 0
73 0 $result .= $text_tmp . $tag_tmp;
74 0 ▶ $skip = 0 if $tag_tmp =~ /^<\/[aA](?![0-9A-Za-z])/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag_tmp =~ m[^</[aA](?![0-9A-Za-z])] 0 0 0
75 } else {
76 0 $text_tmp =~ s{$UrlRe}
77 0 {my($org, $mail) = ($1, $2);
78 0 (my $tmp = $org) =~ s/"/&quot;/g;
79 0 ▶ $anchor . ($mail ne '' ? 'mailto:' : '') . "$tmp\">$org</a>"}ego;
Branch: 1 branch
BranchTrueFalseTotal
$mail ne '' ? : 0 0 0
80 0 $result .= $text_tmp . $tag_tmp;
81 0 ▶ $skip = 1 if $tag_tmp =~ /^<[aA](?![0-9A-Za-z])/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag_tmp =~ /^<[aA](?![0-9A-Za-z])/ 0 0 0
82 0 ▶ if ($tag_tmp =~ /^<(XMP|PLAINTEXT|SCRIPT)(?![0-9A-Za-z])/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag_tmp =~ /^<(XMP|PLAINTEXT|SCRIPT)(?![0-9A-Za-z])/i) 0 0 0
83 0 $str =~ /(.*?(?:<\/$1(?![0-9A-Za-z])$TagRe_|$))/gsi;
84 0 $result .= $1;
85 }
86 }
87 }
88 0 return $result;
89 }
90  
91 1 1;
92 __END__
↑ Summary