| 1 | # $Id: LIST.pm 284 2006-12-01 07:51:49Z chronos $ | ||||||||||||||||||||||||||||
| 2 | package BBCode::Tag::LIST; | ||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use base qw(BBCode::Tag::Block); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use BBCode::Util qw(:parse encodeHTML multilineText createListSequence); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use BBCode::Tag::TEXT (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = '0.34'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 19 | ▶ | sub Class($):method { | ||||||||||||||||||||||||||
|
Subroutine
Class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 19 | return qw(LIST BLOCK); | |||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 68 | ▶ | sub BodyPermitted($):method { | ||||||||||||||||||||||||||
|
Subroutine
BodyPermitted: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 68 | return 1; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 20 | ▶ | sub BodyTags($):method { | ||||||||||||||||||||||||||
|
Subroutine
BodyTags: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 20 | return qw(LI TEXT); | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 18 | ▶ | sub NamedParams($):method { | ||||||||||||||||||||||||||
|
Subroutine
NamedParams: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 18 | return qw(TYPE START BULLET OUTSIDE); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub RequiredParams($):method { | ||||||||||||||||||||||||||
|
Subroutine
RequiredParams: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 0 | return (); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | ▶ | sub DefaultParam($):method { | ||||||||||||||||||||||||||
|
Subroutine
DefaultParam: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 1 | return 'TYPE'; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | ▶ | sub validateParam($$$):method { | ||||||||||||||||||||||||||
|
Subroutine
validateParam: called CC=7 SCAR=24.7
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 2 | my($this,$param,$val) = @_; | |||||||||||||||||||||||||||
| 36 | 2 | ▶ | if($param eq 'TYPE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | return $val if parseListType($val) > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | return '*'; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 1 | ▶ | if($param eq 'START') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | return parseInt $val; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 1 | ▶ | if($param eq 'BULLET') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 1 | my $url = parseURL($val); | |||||||||||||||||||||||||||
| 45 | 1 | ▶ | if(defined $url) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | return $url->as_string; | |||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||
| 48 | 1 | die qq(Invalid value "$val" for [LIST BULLET]); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if($param eq 'OUTSIDE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | return parseBool $val; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | return $this->SUPER::validateParam($param,$val); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub _text($$):method { | ||||||||||||||||||||||||||
|
Subroutine
_text: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 58 | 0 | my $this = shift; | |||||||||||||||||||||||||||
| 59 | 0 | my $text = shift; | |||||||||||||||||||||||||||
| 60 | 0 | my $tag = BBCode::Tag->new($this->parser, 'TEXT', [ undef, $text ]); | |||||||||||||||||||||||||||
| 61 | 0 | return $tag; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub _li($$):method { | ||||||||||||||||||||||||||
|
Subroutine
_li: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 65 | 0 | my $this = shift; | |||||||||||||||||||||||||||
| 66 | 0 | my $text = shift; | |||||||||||||||||||||||||||
| 67 | 0 | my $tag = BBCode::Tag->new($this->parser, 'LI'); | |||||||||||||||||||||||||||
| 68 | 0 | $tag->pushBody($this->_text($text)); | |||||||||||||||||||||||||||
| 69 | 0 | return $tag; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 41 | ▶ | sub pushBody($@):method { | ||||||||||||||||||||||||||
|
Subroutine
pushBody: called CC=9 SCAR=29.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 41 | my $this = shift; | |||||||||||||||||||||||||||
| 74 | 41 | my @tags; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 41 | ▶ | while(@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 41 | my $tag = shift; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 41 | ▶ | next if not defined $tag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 41 | ▶ | if(not ref $tag) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | unshift @_, $this->_text($tag); | |||||||||||||||||||||||||||
| 83 | 0 | next; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 41 | ▶ | if(UNIVERSAL::isa($tag,'BBCode::Tag::TEXT')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 22 | my $str = $tag->param(undef); | |||||||||||||||||||||||||||
| 88 | 22 | ▶ | unless($str =~ /^\s*$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | push @tags, $this->_text("$1") if $str =~ s/^(\s+)//; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | unshift @_, $this->_text("$1") if $str =~ s/(\s+)$//; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | while($str =~ s/^(.*\S)(\s*\n\s*)//) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | my($item,$sep) = ($1,$2); | |||||||||||||||||||||||||||
| 93 | 0 | push @tags, $this->_li($item); | |||||||||||||||||||||||||||
| 94 | 0 | push @tags, $this->_text($sep); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 0 | push @tags, $this->_li($str); | |||||||||||||||||||||||||||
| 97 | 0 | next; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 41 | push @tags, $tag; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 41 | return $this->SUPER::pushBody(@tags); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 8 | ▶ | sub bodyHTML($):method { | ||||||||||||||||||||||||||
|
Subroutine
bodyHTML: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 8 | my $this = shift; | |||||||||||||||||||||||||||
| 109 | 8 | my $html = ''; | |||||||||||||||||||||||||||
| 110 | 8 | foreach($this->body) { | |||||||||||||||||||||||||||
| 111 | 34 | ▶ | next unless UNIVERSAL::isa($_,'BBCode::Tag::LI'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 16 | $html .= $_->toHTML; | |||||||||||||||||||||||||||
| 113 | # die qq(\n> $html[$#html]\nOMGWTFBBQ?) if $html[$#html] =~ m#<br\s*/>#i; | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 8 | return multilineText $html; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 7 | ▶ | sub ListDefault($):method { | ||||||||||||||||||||||||||
|
Subroutine
ListDefault: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 7 | return qw(ul); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 8 | ▶ | sub toHTML($):method { | ||||||||||||||||||||||||||
|
Subroutine
toHTML: called CC=11 SCAR=26.8
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 8 | my $this = shift; | |||||||||||||||||||||||||||
| 124 | 8 | my @list = parseListType($this->param('TYPE')); | |||||||||||||||||||||||||||
| 125 | 8 | ▶ | @list = $this->ListDefault unless @list; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 8 | my @css; | |||||||||||||||||||||||||||
| 128 | 8 | ▶ | if(@list > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | push @css, qq(list-style-type: $list[1]); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 8 | my $start = $this->param('START'); | |||||||||||||||||||||||||||
| 133 | 8 | ▶ | if($list[0] eq 'ol' and defined $start) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$list[0] eq "ol" and defined $start
MC/DC0%0/2
$list[0] eq "ol" and defined $start
$list[0] eq "ol"
defined $start
Truth table66%2/3
A and B
A= $list[0] eq "ol"B= defined $start
| |||||||||||||||||||||||||||||
| 134 | 0 | $start = qq( start="$start"); | |||||||||||||||||||||||||||
| 135 | } else { | ||||||||||||||||||||||||||||
| 136 | 8 | $start = ''; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 8 | ▶ | if($list[0] eq 'ul' and $this->parser->allow_image_bullets) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$list[0] eq "ul" and $this->parser->allow_image_bullets
MC/DC50%1/2
$list[0] eq "ul" and $this->parser->allow_image_bullets
$list[0] eq "ul"
$this->parser->allow_image_bullets
Truth table66%2/3
A and B
A= $list[0] eq "ul"B= $this->parser->allow_image_bullets
| |||||||||||||||||||||||||||||
| 140 | 7 | my $url = $this->param('BULLET'); | |||||||||||||||||||||||||||
| 141 | 7 | ▶ | if(defined $url) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | push @css, sprintf "list-style-image: url('%s')", encodeHTML($url->as_string); | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 8 | my $outside = $this->param('OUTSIDE'); | |||||||||||||||||||||||||||
| 147 | 8 | ▶ | if(defined $outside) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | push @css, "list-style-position: ".($outside ? "outside" : "inside"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 8 | ▶ | my $css = @css ? qq( style=").join("; ", @css).qq(") : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 8 | my $body = $this->bodyHTML; | |||||||||||||||||||||||||||
| 153 | 8 | $body =~ s#(<li>)(<[uo]l>)#$1\n$2#g; | |||||||||||||||||||||||||||
| 154 | 8 | $body =~ s/^/\t/mg; | |||||||||||||||||||||||||||
| 155 | 8 | $body =~ s#^\t(?!</?li>)#\t\t#mg; | |||||||||||||||||||||||||||
| 156 | 8 | return multilineText "<$list[0]$start$css>\n$body</$list[0]>\n"; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub toText($):method { | ||||||||||||||||||||||||||
|
Subroutine
toText: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 160 | 0 | my $this = shift; | |||||||||||||||||||||||||||
| 161 | 0 | my @body = grep { $_->isa('BBCode::Tag::LI') } $this->body; | |||||||||||||||||||||||||||
| 162 | 0 | my $seq = createListSequence($this->param('TYPE'), $this->param('START'), scalar(@body)); | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | my $text = ""; | |||||||||||||||||||||||||||
| 165 | 0 | foreach(@body) { | |||||||||||||||||||||||||||
| 166 | 0 | $text .= $seq->()." ".$_->toText."\n"; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 0 | return multilineText $text; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 3 | 1; | |||||||||||||||||||||||||||