Tag/IMG.pm

filter: Statementstmt 77.9% 60 / 77 Branchbran 50.0% 18 / 36 Conditioncond 53.3% 8 / 15 MC/DCmcdc 30.0% 3 / 10 Subroutinesub 92.3% 12 / 13 Podpod 88.8% 8 / 9 totaltotal 68.1% 109 / 160 CC 24 SCAR 23.2
CC
24
Cov
67%
replace
29.4
toHTML
8.6
validateParam
6.0
CRAP 10.2
« TagSet.pm ↑ Summary Tag/LIST.pm »
1 # $Id: IMG.pm 284 2006-12-01 07:51:49Z chronos $
2 package BBCode::Tag::IMG;
3 3 ▶use base qw(BBCode::Tag::Inline);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use BBCode::Util qw(:parse :text encodeHTML);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 our $VERSION = '0.34';
8  
9 8 ▶sub BodyPermitted($):method {
Subroutine BodyPermitted: called CC=3 SCAR=11.0
Pod documented
10 8 my $this_or_class = shift;
11 8 ▶ if(ref $this_or_class and defined $this_or_class->param('SRC')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this_or_class and defined $this_or_class->param("SRC")) 4 4 8
Condition66%2/3
ref $this_or_class and defined $this_or_class->param("SRC")
!ll&&!rl&&r
044
MC/DC50%1/2
ref $this_or_class and defined $this_or_class->param("SRC")
ref $this_or_class defined $this_or_class->param("SRC")
Truth table66%2/3
A and B
A= ref $this_or_classB= defined $this_or_class->param("SRC")
ABresult
0X0
100
111
12 4 return 0;
13 }
14 4 return 1;
15 }
16  
17 8 ▶sub BodyTags($):method {
Subroutine BodyTags: called CC=1 SCAR=0.0
Pod documented
18 8 return qw(:TEXT);
19 }
20  
21 5 ▶sub NamedParams($):method {
Subroutine NamedParams: called CC=1 SCAR=0.0
Pod documented
22 5 return qw(SRC ALT W H TITLE);
23 }
24  
25 0 ▶sub RequiredParams($):method {
Subroutine RequiredParams: not called CC=1 SCAR=6.9
Pod documented
26 0 return qw(SRC);
27 }
28  
29 5 ▶sub DefaultParam($):method {
Subroutine DefaultParam: called CC=1 SCAR=0.0
Pod documented
30 5 return 'SRC';
31 }
32  
33 10 ▶sub validateParam($$$):method {
Subroutine validateParam: called CC=6 SCAR=18.0
Pod documented
34 10 my($this,$param,$val) = @_;
35 10 ▶ if($param eq 'SRC') {
Branch: 1 branch
BranchTrueFalseTotal
if ($param eq "SRC") 4 6 10
36 4 my $url = parseURL($val);
37 4 ▶ if(defined $url) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url) { } 3 1 4
38 3 ▶ if($url->scheme =~ /^(?:http|https|ftp|data)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url->scheme =~ /^(?:http|https|ftp|data)$/) { } 3 0 3
39 3 return $url->as_string;
40 } else {
41 0 die qq(Scheme "$url->scheme" not permitted for [IMG]);
42 }
43 } else {
44 1 die qq(Invalid value "$val" for [IMG]);
45 }
46 }
47 6 ▶ if($param eq 'W' or $param eq 'H') {
Branch: 1 branch
BranchTrueFalseTotal
if ($param eq "W" or $param eq "H") 2 4 6
Condition100%3/3
$param eq "W" or $param eq "H"
l!l&&r!l&&!r
114
MC/DC100%2/2
$param eq "W" or $param eq "H"
$param eq "W" $param eq "H"
Truth table100%3/3
A or B
A= $param eq "W"B= $param eq "H"
ABresult
1X1
011
000
48 2 return parseNum $val;
49 }
50 4 return $this->SUPER::validateParam($param,$val);
51 }
52  
53 6 ▶sub replace($):method {
Subroutine replace: called CC=8 SCAR=33.8
Pod undocumented
54 6 my $this = shift;
55 6 my($src,$alt) = map { $this->param($_) } qw(SRC ALT);
56 6 ▶ if(defined $src) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $src) 6 0 6
57 # [IMG SRC] has no body...
58 6 delete $this->{body};
59 6 delete $this->{permit};
60 6 delete $this->{forbid};
61 }
62 6 ▶ return $this if defined $src and defined $alt;
Branch: 1 branch
BranchTrueFalseTotal
if defined $src and defined $alt 6 0 6
Condition33%1/3
defined $src and defined $alt
!ll&&!rl&&r
006
MC/DC0%0/2
defined $src and defined $alt
defined $src defined $alt
Truth table33%1/3
A and B
A= defined $srcB= defined $alt
ABresult
0X0
100
111
63  
64 0 my($text,$url);
65 0 ▶ if(defined $src) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $src) { } 0 0 0
66 0 $url = parseURL $src;
67 0 ▶ die "BUG: Cannot re-parse URL <$src>" unless defined $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url 0 0 0
68 0 $text = textALT $url;
69 } else {
70 0 $text = $this->bodyText;
71 0 $url = parseURL $text;
72 0 ▶ goto boom unless defined $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url 0 0 0
73 0 $text = textALT $url;
74 0 $this->param(SRC => $url);
75 }
76 0 ▶ $this->param(ALT => $text) if not defined $alt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $alt 0 0 0
77 0 return $this;
78  
79 0 boom:
80 return BBCode::Tag->new($this->parser, 'TEXT', [ undef, $text ]);
81 }
82  
83 1 ▶sub toHTML($):method {
Subroutine toHTML: called CC=7 SCAR=21.5
Pod documented
84 1 my $this = shift;
85 1 my($src,$alt,$w,$h,$t) = map { $this->param($_) } qw(SRC ALT W H TITLE);
86  
87 1 ▶ if(defined $src and defined $alt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $src and defined $alt) 1 0 1
Condition33%1/3
defined $src and defined $alt
!ll&&!rl&&r
001
MC/DC0%0/2
defined $src and defined $alt
defined $src defined $alt
Truth table33%1/3
A and B
A= defined $srcB= defined $alt
ABresult
0X0
100
111
88 1 ▶ if(not defined $t) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 0 1 1
89 0 $t = $this->bodyText;
90 }
91 1 my $ret = '<img';
92 1 $ret .= ' src="'.encodeHTML($src).'"';
93 1 $ret .= ' alt="'.encodeHTML($alt).'"';
94 1 ▶ $ret .= ' width="'.encodeHTML($w).'"' if defined $w;
Branch: 1 branch
BranchTrueFalseTotal
if defined $w 1 0 1
95 1 ▶ $ret .= ' height="'.encodeHTML($h).'"' if defined $h;
Branch: 1 branch
BranchTrueFalseTotal
if defined $h 1 0 1
96 1 ▶ $ret .= ' title="'.encodeHTML($t).'"' if defined $t;
Branch: 1 branch
BranchTrueFalseTotal
if defined $t 1 0 1
97 1 $ret .= ' />';
98 1 return $ret;
99 }
100 0 return '';
101 }
102  
103 2 ▶sub toLinkList($;$):method {
Subroutine toLinkList: called CC=4 SCAR=14.6
Pod documented
104 2 my $this = shift;
105 2 my $ret = shift;
106 2 ▶ $ret = [] if not defined $ret;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret 0 2 2
107  
108 2 my($src,$alt) = map { $this->param($_) } qw(SRC ALT);
109 2 ▶ if(defined $src and defined $alt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $src and defined $alt) 2 0 2
Condition33%1/3
defined $src and defined $alt
!ll&&!rl&&r
002
MC/DC0%0/2
defined $src and defined $alt
defined $src defined $alt
Truth table33%1/3
A and B
A= defined $srcB= defined $alt
ABresult
0X0
100
111
110 2 push @$ret, [ 1, $this->Tag, $src, $alt ];
111 }
112 2 return $this->SUPER::toLinkList($ret);
113 }
114  
115 3 1;
« TagSet.pm ↑ Summary Tag/LIST.pm »