Qgoda/HTMLFilter/AnchorTarget.pm

filter: Statementstmt 56.7% 21 / 37 Branchbran 25.0% 3 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 51.7% 29 / 56 CC 8 SCAR 28.0
CC
8
Cov
49%
start
30.9
new
3.0
BEGIN
1.0
CRAP 16.5
« Qgoda.pm ↑ Summary Qgoda/Builder.pm »
1 #! /bin/false
2  
3 # Copyright (C) 2016-2018 Guido Flohr <guido.flohr@cantanea.com>,
4 # all rights reserved.
5  
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10  
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15  
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18  
19 package Qgoda::HTMLFilter::AnchorTarget;
20 2 $Qgoda::HTMLFilter::AnchorTarget::VERSION = 'v0.9.2';
21 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use base qw(Qgoda::Processor);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 ▶use Qgoda::Util qw(empty);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 sub new {
28 2 ▶ my ($class, %args) = @_;
Subroutine new: called CC=3 SCAR=11.1
Pod undocumented
29  
30 2 my $match = $args{match};
31 2 ▶ $match = '^(?:https?|ftp)://' if empty $match;
Branch: 1 branch
BranchTrueFalseTotal
if &empty($match) 2 0 2
32  
33 2 my $target = $args{target};
34 2 ▶ $target = '_blank' if empty $target;
Branch: 1 branch
BranchTrueFalseTotal
if &empty($target) 2 0 2
35  
36 2 $match = qr/$match/;
37 2 my $self = {
38 __match => $match,
39 __target => $target,
40 };
41  
42 2 bless $self, $class;
43 }
44  
45 sub start {
46 30 ▶ my ($self, $chunk, %args) = @_;
Subroutine start: called CC=6 SCAR=34.3
Pod undocumented
47  
48 30 ▶ return $chunk if 'a' ne $args{tagname};
Branch: 1 branch
BranchTrueFalseTotal
if "a" ne $args{"tagname"} 30 0 30
49  
50 0 my $attr = $args{attr};
51 0 my $href = $args{attr}->{href};
52  
53 0 ▶ return $chunk if empty $href;
Branch: 1 branch
BranchTrueFalseTotal
if &empty($href) 0 0 0
54 0 ▶ return $chunk if !empty $attr->{target};
Branch: 1 branch
BranchTrueFalseTotal
unless &empty($attr->{"target"}) 0 0 0
55 0 ▶ return $chunk if $href !~ $self->{__match};
Branch: 1 branch
BranchTrueFalseTotal
unless $href =~ /$self->{"__match"}/ 0 0 0
56  
57 0 my $attrseq = $args{attrseq};
58 0 push @$attrseq, 'target';
59 0 $attr->{target} = $self->{__target};
60  
61 0 $chunk = '<' . $args{tagname};
62  
63 0 foreach my $key (@$attrseq) {
64 0 my $value = $attr->{$key};
65  
66 0 my %escapes = (
67 '"' => '&quot;',
68 '&' => '&amp;'
69 );
70 0 $value =~ s/(["&])/$escapes{$1}/g;
71 0 $chunk .= qq{ $key="$value"};
72 }
73
74 0 $chunk .= '>';
75  
76 0 return $chunk;
77 }
78 2 1;
« Qgoda.pm ↑ Summary Qgoda/Builder.pm »