| 1 | # $Id: URL.pm 284 2006-12-01 07:51:49Z chronos $ | ||||||||||
| 2 | package BBCode::Tag::URL; | ||||||||||
| 3 | 4 | ▶ | use base qw(BBCode::Tag); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use BBCode::Util qw(:parse encodeHTML multilineText); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | our $VERSION = '0.34'; | |||||||||
| 8 | |||||||||||
| 9 | 25 | ▶ | sub Class($):method { | ||||||||
|
Subroutine
Class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 10 | 25 | return qw(LINK INLINE); | |||||||||
| 11 | } | ||||||||||
| 12 | |||||||||||
| 13 | 45 | ▶ | sub BodyPermitted($):method { | ||||||||
|
Subroutine
BodyPermitted: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 14 | 45 | return 1; | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 26 | ▶ | sub BodyTags($):method { | ||||||||
|
Subroutine
BodyTags: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 18 | 26 | return qw(:INLINE !:LINK); | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 21 | ▶ | sub NamedParams($):method { | ||||||||
|
Subroutine
NamedParams: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 22 | 21 | return qw(HREF FOLLOW NEWWINDOW TITLE); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub RequiredParams($):method { | ||||||||
|
Subroutine
RequiredParams: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 26 | 0 | return qw(HREF); | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 20 | ▶ | sub DefaultParam($):method { | ||||||||
|
Subroutine
DefaultParam: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 30 | 20 | return 'HREF'; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 15 | ▶ | sub validateParam($$$):method { | ||||||||
|
Subroutine
validateParam: called CC=5 SCAR=17.6
Pod
documented
| |||||||||||
| 34 | 15 | my($this,$param,$val) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 15 | ▶ | if($param eq 'HREF') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 11 | my $url = parseURL($val); | |||||||||
| 38 | 11 | ▶ | if(defined $url) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 10 | return $url->as_string; | |||||||||
| 40 | } else { | ||||||||||
| 41 | 1 | die qq(Invalid value "$val" for [URL]); | |||||||||
| 42 | } | ||||||||||
| 43 | } | ||||||||||
| 44 | 4 | ▶ | if($param eq 'FOLLOW') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 4 | return parseBool $val; | |||||||||
| 46 | } | ||||||||||
| 47 | 0 | ▶ | if($param eq 'NEWWINDOW') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | return parseBool $val; | |||||||||
| 49 | } | ||||||||||
| 50 | 0 | return $this->SUPER::validateParam($param,$val); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 20 | ▶ | sub replace($):method { | ||||||||
|
Subroutine
replace: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||
| 54 | 20 | my $this = shift; | |||||||||
| 55 | 20 | my $href = $this->param('HREF'); | |||||||||
| 56 | 20 | ▶ | if(not defined $href) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 1 | my $text = $this->bodyText; | |||||||||
| 58 | 1 | my $url = parseURL $text; | |||||||||
| 59 | 1 | ▶ | if(not defined $url) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | return BBCode::Tag->new($this->parser, 'TEXT', [ undef, $text ]); | |||||||||
| 61 | } | ||||||||||
| 62 | 1 | $this->param(HREF => $url); | |||||||||
| 63 | } | ||||||||||
| 64 | 20 | return $this; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 8 | ▶ | sub toHTML($):method { | ||||||||
|
Subroutine
toHTML: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||
| 68 | 8 | my $this = shift; | |||||||||
| 69 | |||||||||||
| 70 | 8 | my $ret = ''; | |||||||||
| 71 | 8 | my $href = $this->param('HREF'); | |||||||||
| 72 | 8 | ▶ | if(defined $href) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 8 | my $title = $this->param('TITLE'); | |||||||||
| 74 | 8 | $ret .= '<a href="'.encodeHTML($href).'"'; | |||||||||
| 75 | 8 | ▶ | $ret .= ' rel="nofollow"' if not $this->isFollowed; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 8 | ▶ | $ret .= ' target="_blank"' if $this->openInNewWindow; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 8 | ▶ | $ret .= ' title="'.encodeHTML($title).'"' if defined $title; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 8 | $ret .= '>'; | |||||||||
| 79 | } | ||||||||||
| 80 | 8 | $ret .= $this->bodyHTML; | |||||||||
| 81 | 8 | ▶ | if(defined $href) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 8 | $ret .= '</a>'; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 8 | return multilineText $ret; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 0 | ▶ | sub toText($):method { | ||||||||
|
Subroutine
toText: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 89 | 0 | my $this = shift; | |||||||||
| 90 | |||||||||||
| 91 | 0 | my $href = $this->param('HREF'); | |||||||||
| 92 | 0 | my $text = $this->bodyText; | |||||||||
| 93 | 0 | my $ret; | |||||||||
| 94 | 0 | ▶ | if(defined $href) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 0 | $ret = "_${text}_"; | |||||||||
| 96 | 0 | ▶ | if($href =~ /^mailto:([\w.+-]+\@[\w.-]+)$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | $ret .= " <$1>"; | |||||||||
| 98 | } else { | ||||||||||
| 99 | 0 | $ret .= " <URL:$href>"; | |||||||||
| 100 | } | ||||||||||
| 101 | } else { | ||||||||||
| 102 | 0 | $ret = $text; | |||||||||
| 103 | } | ||||||||||
| 104 | 0 | return multilineText $ret; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 4 | ▶ | sub toLinkList($;$):method { | ||||||||
|
Subroutine
toLinkList: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 108 | 4 | my $this = shift; | |||||||||
| 109 | 4 | my $ret = shift; | |||||||||
| 110 | 4 | ▶ | $ret = [] if not defined $ret; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | |||||||||||
| 112 | 4 | my $href = $this->param('HREF'); | |||||||||
| 113 | 4 | ▶ | if(defined $href) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | 4 | push @$ret, [ $this->isFollowed, $this->Tag, $href, $this->bodyText ]; | |||||||||
| 115 | } | ||||||||||
| 116 | 4 | return $this->SUPER::toLinkList($ret); | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 4 | 1; | |||||||||