| 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
Condition66%2/3
ref $this_or_class and defined $this_or_class->param("SRC")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 36 | 4 | my $url = parseURL($val); | |||||||||||||||||||||||||||
| 37 | 4 | ▶ | if(defined $url) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 3 | ▶ | if($url->scheme =~ /^(?:http|https|ftp|data)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$param eq "W" or $param eq "H"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $src and defined $alt
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
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | my($text,$url); | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | if(defined $src) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | $url = parseURL $src; | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | die "BUG: Cannot re-parse URL <$src>" unless defined $url; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $src and defined $alt
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
| |||||||||||||||||||||||||||||
| 88 | 1 | ▶ | if(not defined $t) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 95 | 1 | ▶ | $ret .= ' height="'.encodeHTML($h).'"' if defined $h; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 1 | ▶ | $ret .= ' title="'.encodeHTML($t).'"' if defined $t; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | my($src,$alt) = map { $this->param($_) } qw(SRC ALT); | |||||||||||||||||||||||||||
| 109 | 2 | ▶ | if(defined $src and defined $alt) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $src and defined $alt
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
| |||||||||||||||||||||||||||||
| 110 | 2 | push @$ret, [ 1, $this->Tag, $src, $alt ]; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 2 | return $this->SUPER::toLinkList($ret); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 3 | 1; | |||||||||||||||||||||||||||