BBCode.pm

filter: Statementstmt 99.4% 513 / 516 Branchbran 93.7% 210 / 224 Conditioncond 81.2% 104 / 128 MC/DCmcdc 66.2% 49 / 74 Subroutinesub 100% 32 / 32 Podpod 100% 10 / 10 totaltotal 93.2% 918 / 984 CC 172 SCAR 30.8
CC
172
Cov
95%
parse
47.4
_render_tree
26.1
parse_attributes
21.1
CRAP 21.8
↑ Summary BBCode/Tag.pm »
1 package Parse::BBCode;
2 15 $Parse::BBCode::VERSION = '0.15';
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use Parse::BBCode::Tag;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use Parse::BBCode::HTML qw/ &defaults &default_escapes &optional /;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 __PACKAGE__->follow_best_practice;
9 15 __PACKAGE__->mk_accessors(qw/
10 tags allowed compiled plain strict_attributes close_open_tags error
11 tree escapes direct_attribute params url_finder text_processor linebreaks
12 smileys attribute_parser strip_linebreaks attribute_quote /);
13 #use Data::Dumper;
14 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 my $scalar_util = eval "require Scalar::Util; 1";
16  
17 15 my %defaults = (
18 strict_attributes => 1,
19 direct_attribute => 1,
20 linebreaks => 1,
21 smileys => 0,
22 url_finder => 0,
23 strip_linebreaks => 1,
24 attribute_quote => '"',
25 );
26 37 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
27 37 my ($class, $args) = @_;
28 37 ▶ $args ||= {};
Condition100%2/2
$args ||= {}
l!l
343
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
29 37 my %args = %$args;
30 37 ▶ unless ($args{tags}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'tags'}) { } 31 6 37
31 6 $args{tags} = { $class->defaults };
32 }
33 else {
34 31 $args{tags} = { %{ $args{tags} } };
35 }
36 37 ▶ unless ($args{escapes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'escapes'}) { } 3 34 37
37 34 $args{escapes} = {$class->default_escapes };
38 }
39 else {
40 3 $args{escapes} = { %{ $args{escapes} } }
41 }
42 37 my $self = $class->SUPER::new({
43 %defaults,
44 %args
45 });
46 37 $self->set_allowed([ grep { length } keys %{ $self->get_tags } ]);
47 37 $self->_compile_tags;
48 37 return $self;
49 }
50  
51 15 my $re_split = qr{ % (?:\{ (?:[a-zA-Z\|]+) \})? (?:attr|[Aas]) }x;
52 15 my $re_cmp = qr{ % (?:\{ ([a-zA-Z\|]+) \})? (attr|[Aas]) }x;
53  
54 2 ▶sub forbid {
Subroutine forbid: called CC=1 SCAR=0.0
Pod documented
55 2 my ($self, @tags) = @_;
56 2 my $allowed = $self->get_allowed;
57 2 my $re = join '|', map { quotemeta } @tags;
58 2 @$allowed = grep { ! m/^(?:$re)\z/ } @$allowed;
59 }
60  
61 3 ▶sub permit {
Subroutine permit: called CC=2 SCAR=7.0
Pod documented
62 3 my ($self, @tags) = @_;
63 3 my $allowed = $self->get_allowed;
64 3 my %seen;
65 @$allowed = grep {
66 3 ▶ !$seen{$_}++ && $self->get_tags->{$_};
Condition66%2/3
!$seen{$_}++ && $self->get_tags->{$_}
!ll&&!rl&&r
0141
MC/DC50%1/2
!$seen{$_}++ && $self->get_tags->{$_}
!$seen{$_}++ $self->get_tags->{$_}
Truth table66%2/3
not(A) && B
A= !$seen{$_}++B= $self->get_tags->{$_}
ABresult
0X0
100
111
67 } (@$allowed, @tags);
68 }
69  
70 37 ▶sub _compile_tags {
Subroutine _compile_tags: called CC=21 SCAR=30.5
71 37 my ($self) = @_;
72 # unless ($self->get_compiled) {
73 {
74 37 my $defs = $self->get_tags;
75  
76 # get definition for how text should be rendered which is not in tags
77 37 my $plain;
78 37 ▶ if (exists $defs->{""}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $defs->{''}) { } 9 28 37
79 9 $plain = delete $defs->{""};
80 9 ▶ if (ref $plain eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plain eq "CODE") 8 1 9
81 8 $self->set_plain($plain);
82 }
83 }
84 else {
85 28 my $url_finder = $self->get_url_finder;
86 28 my $linebreaks = $self->get_linebreaks;
87 28 my $smileys = $self->get_smileys;
88 28 ▶ if ($url_finder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url_finder) 6 22 28
89 6 my $result = eval { require URI::Find; 1 };
90 6 ▶ unless ($result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 0 6 6
91 0 undef $url_finder;
92 }
93 }
94 28 my $escape = \&Parse::BBCode::escape_html;
95 28 my $post_processor_1 = $escape;
96 28 my $post_processor;
97 28 my $text_processor = $self->get_text_processor;
98 28 ▶ if ($text_processor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text_processor) 5 23 28
99 5 $post_processor_1 = $text_processor;
100 }
101 28 ▶ if ($smileys and ref($smileys->{icons}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($smileys and ref $smileys->{'icons'} eq 'HASH') { } 1 27 28
Condition66%2/3
$smileys and ref $smileys->{"icons"} eq "HASH"
!ll&&!rl&&r
2701
MC/DC50%1/2
$smileys and ref $smileys->{"icons"} eq "HASH"
$smileys ref $smileys->{"icons"} eq "HASH"
Truth table66%2/3
A and B
A= $smileysB= ref $smileys->{"icons"} eq "HASH"
ABresult
0X0
100
111
102 $smileys = {
103 icons => $smileys->{icons},
104 base_url => $smileys->{base_url} || '/smileys/',
105 1 ▶ format => $smileys->{format} || '<img src="%s" alt="%s">',
Condition50%2/4
$smileys->{'base_url'} || '/smileys/'
l!l
10
$smileys->{'format'} || '<img src="%s" alt="%s">'
l!l
10
MC/DC0%0/1
$smileys->{'base_url'} || '/smileys/'
$smileys->{'base_url'}
MC/DC0%0/1
$smileys->{'format'} || '<img src="%s" alt="%s">'
$smileys->{'format'}
Truth table50%1/2
A
A= $smileys->{'base_url'}
Aresult
11
00
Truth table50%1/2
A
A= $smileys->{'format'}
Aresult
11
00
106 };
107 4 my $re = join '|', map { quotemeta $_ } sort { length $b <=> length $a }
108 1 keys %{ $smileys->{icons} };
109 4 ▶ my $code = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
110 4 my ($text, $post_processor) = @_;
111 4 my $out = '';
112 4 ▶ while ($text =~ s/\A (^|.*?[\s]) ($re) (?=[\s]|$)//xsm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/\A (^|.*?[\s]) ($re) (?=[\s]|$)//msx) 7 4 11
113 7 my ($pre, $emo) = ($1, $2);
114 7 my $url = "$smileys->{base_url}$smileys->{icons}->{$emo}";
115 7 my $emo_escaped = Parse::BBCode::escape_html($emo);
116 7 my $image_tag = sprintf $smileys->{format}, $url, $emo_escaped;
117 7 $out .= $post_processor_1->($pre) . $image_tag;
118 }
119 4 $out .= $post_processor_1->($text);
120 4 return $out;
121 1 };
122 1 $post_processor = $code;
123 }
124 else {
125 27 $post_processor = $post_processor_1;
126 }
127  
128 28 ▶ if ($url_finder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url_finder) { } 6 22 28
129 6 my $url_find_sub;
130 6 ▶ if (ref($url_finder) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $url_finder eq 'CODE') { } 1 5 6
131 1 $url_find_sub = $url_finder;
132 }
133 else {
134 5 ▶ unless (ref($url_finder) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $url_finder eq "HASH") 1 4 5
135 1 $url_finder = {
136 max_length => 50,
137 format => '<a href="%s" rel="nofollow">%s</a>',
138 };
139 }
140 5 ▶ my $max_url = $url_finder->{max_length} || 0;
Condition50%1/2
$url_finder->{'max_length'} || 0
l!l
50
MC/DC0%0/1
$url_finder->{'max_length'} || 0
$url_finder->{'max_length'}
Truth table50%1/2
A
A= $url_finder->{'max_length'}
Aresult
11
00
141 5 my $format = $url_finder->{format};
142 2 ▶ my $finder = URI::Find->new(sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
143 2 my ($url) = @_;
144 2 my $title = $url;
145 2 ▶ if ($max_url and length($title) > $max_url) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_url and length $title > $max_url) 1 1 2
Condition66%2/3
$max_url and length $title > $max_url
!ll&&!rl&&r
011
MC/DC50%1/2
$max_url and length $title > $max_url
$max_url length $title > $max_url
Truth table66%2/3
A and B
A= $max_urlB= length $title > $max_url
ABresult
0X0
100
111
146 1 $title = substr($title, 0, $max_url) . "...";
147 }
148 2 my $escaped = Parse::BBCode::escape_html($url);
149 2 my $escaped_title = Parse::BBCode::escape_html($title);
150 2 my $href = sprintf $format, $escaped, $title;
151 2 return $href;
152 5 });
153 5 ▶ $url_find_sub = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
154 5 my ($ref_content, $post, $info) = @_;
155 5 ▶ $finder->find($ref_content, sub { $post->($_[0], $info) });
Subroutine __ANON__: called CC=1 SCAR=0.0
156 5 };
157 }
158 9 ▶ $plain = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
159 9 my ($parser, $attr, $content, $info) = @_;
160 9 ▶ unless ($info->{classes}->{url}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{'classes'}{'url'}) { } 3 6 9
161 6 $url_find_sub->(\$content, $post_processor, $info);
162 }
163 else {
164 3 $content = $post_processor->($content);
165 }
166 9 ▶ $content =~ s/\r?\n|\r/<br>\n/g if $linebreaks;
Branch: 1 branch
BranchTrueFalseTotal
if $linebreaks 8 1 9
167 9 $content;
168 6 };
169 }
170 else {
171 234 ▶ $plain = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
172 234 my ($parser, $attr, $content, $info) = @_;
173 234 my $text = $post_processor->($content, $info);
174 234 ▶ $text =~ s/\r?\n|\r/<br>\n/g if $linebreaks;
Branch: 1 branch
BranchTrueFalseTotal
if $linebreaks 232 2 234
175 234 $text;
176 22 };
177 }
178 28 $self->set_plain($plain);
179 }
180  
181 # now compile the rest of definitions
182 37 for my $key (keys %$defs) {
183 274 my $def = $defs->{$key};
184 #warn __PACKAGE__.':'.__LINE__.": $key: $def\n";
185 274 ▶ if (not ref $def) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $def) { } 186 88 274
elsif (not exists $def->{'code'} and exists $def->{'output'}) { } 8 160 168
186 186 my $new_def = $self->_compile_def($def);
187 186 $defs->{$key} = $new_def;
188 }
189 ▶ elsif (not exists $def->{code} and exists $def->{output}) {
Condition66%2/3
not exists $def->{"code"} and exists $def->{"output"}
!ll&&!rl&&r
8008
MC/DC50%1/2
not exists $def->{"code"} and exists $def->{"output"}
not exists $def->{"code"} exists $def->{"output"}
Truth table66%2/3
not(A) and B
A= not exists $def->{"code"}B= exists $def->{"output"}
ABresult
0X0
100
111
190 8 my $new_def = $self->_compile_def($def);
191 8 $defs->{$key} = $new_def;
192 }
193 274 ▶ $defs->{$key}->{class} ||= 'inline';
Condition100%2/2
$defs->{$key}{"class"} ||= "inline"
l!l
26014
MC/DC100%1/1
$defs->{$key}{"class"} ||= "inline"
$defs->{$key}{"class"}
Truth table100%2/2
A
A= $defs->{$key}{"class"}
Aresult
11
00
194 274 ▶ $defs->{$key}->{classic} = 1 unless defined $defs->{$key}->{classic};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $defs->{$key}{"classic"} 234 40 274
195 274 ▶ $defs->{$key}->{close} = 1 unless defined $defs->{$key}->{close};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $defs->{$key}{"close"} 35 239 274
196 }
197 37 $self->set_compiled(1);
198 }
199 }
200  
201 194 ▶sub _compile_def {
Subroutine _compile_def: called CC=9 SCAR=22.0
202 194 my ($self, $def) = @_;
203 194 my $esc = $self->get_escapes;
204 194 my $parse = 0;
205 194 my $new_def = {};
206 194 my $output = $def;
207 194 my $close = 1;
208 194 my $class = 'inline';
209 194 ▶ if (ref $def eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $def eq 'HASH') { } 8 186 194
210 8 $new_def = { %$def };
211 8 $output = delete $new_def->{output};
212 8 $parse = $new_def->{parse};
213 8 ▶ $close = $new_def->{close} if exists $new_def->{close};
Branch: 1 branch
BranchTrueFalseTotal
if exists $new_def->{"close"} 1 7 8
214 8 ▶ $class = $new_def->{class} if exists $new_def->{class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $new_def->{"class"} 6 2 8
215 }
216 else {
217 }
218 # we have a string, compile
219 #warn __PACKAGE__.':'.__LINE__.": $key => $output\n";
220 194 ▶ if ($output =~ s/^(inline|block|url)://) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output =~ s/^(inline|block|url)://) 43 151 194
221 43 $class = $1;
222 }
223 194 my @parts = split m!($re_split)!, $output;
224 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\@parts], ['parts']);
225 194 my @compiled;
226 194 for my $p (@parts) {
227 774 ▶ if ($p =~ m/$re_cmp/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ /$re_cmp/) { } 305 469 774
228 305 my ($escape, $type) = ($1, $2);
229 305 ▶ $escape ||= 'parse';
Condition100%2/2
$escape ||= "parse"
l!l
172133
MC/DC100%1/1
$escape ||= "parse"
$escape
Truth table100%2/2
A
A= $escape
Aresult
11
00
230 305 my @escapes = split /\|/, $escape;
231 305 ▶ if (grep { $_ eq 'parse' } @escapes) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "parse";} @escapes) 161 144 305
232 161 $parse = 1;
233 }
234 305 push @compiled, [\@escapes, $type];
235 }
236 else {
237 469 push @compiled, $p;
238 }
239 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\@compiled], ['compiled']);
240 }
241 216 ▶ my $code = sub {
Subroutine __ANON__: called CC=14 SCAR=26.4
242 216 my ($self, $attr, $string, $fallback, $tag) = @_;
243 216 my $out = '';
244 216 for my $c (@compiled) {
245  
246 # just text
247 760 ▶ unless (ref $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c) { } 292 468 760
248 468 $out .= $c;
249 }
250 # tag attribute or content
251 else {
252 292 my ($escapes, $type) = @$c;
253 292 my @escapes = @$escapes;
254 292 my $var = '';
255 292 my $attributes = $tag->get_attr;
256 292 ▶ if ($type eq 'attr' and @$attributes > 1) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'attr' and @$attributes > 1) { } 4 288 292
elsif ($type eq 'a') { } 13 275 288
elsif ($type eq 'A') { } 57 218 275
elsif ($type eq 's') { } 217 1 218
Condition100%3/3
$type eq "attr" and @$attributes > 1
!ll&&!rl&&r
28714
MC/DC100%2/2
$type eq "attr" and @$attributes > 1
$type eq "attr" @$attributes > 1
Truth table100%3/3
A and B
A= $type eq "attr"B= @$attributes > 1
ABresult
0X0
100
111
257 4 my $name = shift @escapes;
258 4 for my $item (@$attributes[1 .. $#$attributes]) {
259 4 ▶ if ($item->[0] eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->[0] eq $name) 4 0 4
260 4 $var = $item->[1];
261 4 last;
262 }
263 }
264 }
265 elsif ($type eq 'a') {
266 13 $var = $attr;
267 }
268 elsif ($type eq 'A') {
269 57 $var = $fallback;
270 }
271 elsif ($type eq 's') {
272 217 ▶ if (ref $string eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $string eq "SCALAR") 208 9 217
273 # this text is already finished and escaped
274 208 $string = $$string;
275 }
276 217 $var = $string;
277 }
278 292 for my $e (@escapes) {
279 289 my $sub = $esc->{$e};
280 289 ▶ if ($sub) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub) 91 198 289
281 91 $var = $sub->($self, $c, $var);
282 91 ▶ unless (defined $var) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $var) 5 86 91
283 # if escape returns undef, we return it unparsed
284 return $tag->get_start
285 . (join '', map {
286 9 $self->_render_tree($_);
287 5 } @{ $tag->get_content })
288 . $tag->get_end;
289 }
290 }
291 }
292 287 $out .= $var;
293 }
294 }
295 211 return $out;
296 194 };
297 194 $new_def->{parse} = $parse;
298 194 $new_def->{code} = $code;
299 194 $new_def->{close} = $close;
300 194 $new_def->{class} = $class;
301 194 return $new_def;
302 }
303  
304 521 ▶sub _render_text {
Subroutine _render_text: called CC=2 SCAR=6.9
305 521 my ($self, $tag, $text, $info) = @_;
306 #warn __PACKAGE__.':'.__LINE__.": text '$text'\n";
307 521 ▶ defined (my $code = $self->get_plain) or return $text;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $code = $self->get_plain) or return $text 518 3 521
308 518 return $code->($self, $tag, $text, $info);
309 }
310  
311 192 ▶sub parse {
Subroutine parse: called CC=47 SCAR=38.6
Pod documented
312 192 my ($self, $text, $params) = @_;
313 192 ▶ my $parse_attributes = $self->get_attribute_parser ? $self->get_attribute_parser : $self->can('parse_attributes');
Branch: 1 branch
BranchTrueFalseTotal
$self->get_attribute_parser ? : 3 189 192
314 192 $self->set_error(undef);
315 192 my $defs = $self->get_tags;
316 192 ▶ my $tags = $self->get_allowed || [keys %$defs];
Condition50%1/2
$self->get_allowed || [keys %$defs]
l!l
1920
MC/DC0%0/1
$self->get_allowed || [keys %$defs]
$self->get_allowed
Truth table50%1/2
A
A= $self->get_allowed
Aresult
11
00
317 192 my @classic_tags = grep { $defs->{$_}->{classic} } @$tags;
318 192 my @short_tags = grep { $defs->{$_}->{short} } @$tags;
319 192 my $re_classic = join '|', map { quotemeta } sort {length $b <=> length $a } @classic_tags;
320 #$re_classic = qr/$re_classic/i;
321 192 my $re_short = join '|', map { quotemeta } sort {length $b <=> length $a } @short_tags;
322 #$re_short = qr/$re_short/i;
323 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$re], ['re']);
324 192 my @tags;
325 192 my $out = '';
326 192 my @opened;
327 192 my $current_open_re = '';
328 324 ▶ my $callback_found_text = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
329 324 my ($text) = @_;
330 324 ▶ if (@opened) {
Branch: 1 branch
BranchTrueFalseTotal
if (@opened) { } 109 215 324
331 109 my $o = $opened[-1];
332 109 $o->add_content($text);
333 }
334 else {
335 215 ▶ if (@tags and !ref $tags[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tags and not ref $tags[-1]) { } 14 201 215
Condition100%3/3
@tags and not ref $tags[-1]
!ll&&!rl&&r
4915214
MC/DC100%2/2
@tags and not ref $tags[-1]
@tags not ref $tags[-1]
Truth table100%3/3
A and not(B)
A= @tagsB= not ref $tags[-1]
ABresult
0X0
100
111
336 # text tag, concatenate
337 14 $tags[-1] .= $text;
338 }
339 else {
340 201 push @tags, $text;
341 }
342 }
343 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\@opened], ['opened']);
344 192 };
345 192 my $callback_found_tag;
346 192 my $in_url = 0;
347 324 ▶ $callback_found_tag = sub {
Subroutine __ANON__: called CC=15 SCAR=27.1
348 324 my ($tag) = @_;
349 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$tag], ['tag']);
350 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\@opened], ['opened']);
351 324 ▶ if (@opened) {
Branch: 2 branches
BranchTrueFalseTotal
if (@opened) { } 126 198 324
elsif (ref $tag) { } 191 7 198
352 126 my $o = $opened[-1];
353 126 my $class = $o->get_class;
354 #warn __PACKAGE__.':'.__LINE__.": tag $tag\n";
355 126 ▶ if (ref $tag and $class =~ m/inline|url/ and $tag->get_class eq 'block') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $tag and $class =~ /inline|url/ and $tag->get_class eq 'block') { } 6 120 126
elsif (ref $tag) { } 105 15 120
Condition100%6/6
ref $tag and $class =~ /inline|url/ and $tag->get_class eq "block"
!ll&&!rl&&r
55656
ref $tag and $class =~ /inline|url/
!ll&&!rl&&r
154071
MC/DC100%3/3
ref $tag and $class =~ /inline|url/ and $tag->get_class eq "block"
ref $tag $class =~ /inline|url/ $tag->get_class eq "block"
Truth table100%4/4
A and B and C
A= ref $tagB= $class =~ /inline|url/C= $tag->get_class eq "block"
ABCresult
0XX0
10X0
1100
1111
356 6 $self->_add_error('block_inline', $tag);
357 6 pop @opened;
358 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$o], ['o']);
359 6 ▶ if ($self->get_close_open_tags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_close_open_tags) { } 2 4 6
360 # we close the tag for you
361 2 $self->_finish_tag($o, '[/' . $o->get_name . ']', 1);
362 2 $callback_found_tag->($o);
363 2 $callback_found_tag->($tag);
364 }
365 else {
366 # nope, no automatic closing, invalidate all
367 # open inline tags before
368 4 my @red = $o->_reduce;
369 4 $callback_found_tag->($_) for @red;
370 4 $callback_found_tag->($tag);
371 }
372 }
373 elsif (ref $tag) {
374 105 my $def = $defs->{lc $tag->get_name};
375 105 my $parse = $def->{parse};
376 105 ▶ if ($parse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parse) { } 96 9 105
377 96 $o->add_content($tag);
378 }
379 else {
380 9 my $content = $tag->get_content;
381 9 my $string = '';
382 9 for my $c (@$content) {
383 8 ▶ if (ref $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c) { } 1 7 8
384 1 $string .= $c->raw_text( auto_close => 0 );
385 }
386 else {
387 7 $string .= $c;
388 }
389 }
390 9 $tag->set_content([$string]);
391 9 $o->add_content($tag);
392 }
393 }
394 else {
395 15 $o->add_content($tag);
396 }
397 }
398 elsif (ref $tag) {
399 191 my $def = $defs->{lc $tag->get_name};
400 191 my $parse = $def->{parse};
401 191 ▶ if ($parse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parse) { } 155 36 191
402 155 push @tags, $tag;
403 }
404 else {
405 36 my $content = $tag->get_content;
406 36 my $string = '';
407 36 for my $c (@$content) {
408 35 ▶ if (ref $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c) { } 2 33 35
409 2 $string .= $c->raw_text( auto_close => 0 );
410 }
411 else {
412 33 $string .= $c;
413 }
414 }
415 36 $tag->set_content([$string]);
416 36 push @tags, $tag;
417 }
418 }
419 else {
420 7 push @tags, $tag;
421 }
422 $current_open_re = join '|', map {
423 324 quotemeta $_->get_name
424 } @opened;
425  
426 192 };
427 192 my @class = 'block';
428 192 ▶ while (defined $text and length $text) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text and length $text) 511 192 703
Condition100%3/3
defined $text and length $text
!ll&&!rl&&r
15933511
MC/DC100%2/2
defined $text and length $text
defined $text length $text
Truth table100%3/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
429 511 $in_url = grep { $_->get_class eq 'url' } @opened;
430 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$in_url], ['in_url']);
431 #warn __PACKAGE__.':'.__LINE__.": ============= match $text\n";
432 511 my $tag;
433 511 my ($before, $tag1, $tag2, $after);
434 511 ▶ if ($re_classic and $re_short) {
Branch: 3 branches
BranchTrueFalseTotal
if ($re_classic and $re_short) { } 29 482 511
elsif (not $re_classic and $re_short) { } 0 482 482
elsif ($re_classic and not $re_short) { } 482 0 482
Condition66%2/3
$re_classic and $re_short
!ll&&!rl&&r
048229
MC/DC50%1/2
$re_classic and $re_short
$re_classic $re_short
Truth table66%2/3
A and B
A= $re_classicB= $re_short
ABresult
0X0
100
111
435 29 ($before, $tag1, $tag2, $after) = split m{
436 (?:
437 \[ ($re_short) (?=://)
438 |
439 \[ ($re_classic) (?=\b|\]|\=)
440 )
441 }ix, $text, 2;
442 }
443 ▶ elsif (! $re_classic and $re_short) {
Condition33%1/3
not $re_classic and $re_short
!ll&&!rl&&r
48200
MC/DC0%0/2
not $re_classic and $re_short
not $re_classic $re_short
Truth table33%1/3
not(A) and B
A= not $re_classicB= $re_short
ABresult
0X0
100
111
444 0 ($before, $tag1, $after) = split m{
445 \[ ($re_short) (?=://)
446 }ix, $text, 2;
447 }
448 ▶ elsif ($re_classic and !$re_short) {
Condition33%1/3
$re_classic and not $re_short
!ll&&!rl&&r
00482
MC/DC0%0/2
$re_classic and not $re_short
$re_classic not $re_short
Truth table33%1/3
A and not(B)
A= $re_classicB= not $re_short
ABresult
0X0
100
111
449 482 ($before, $tag2, $after) = split m{
450 \[ ($re_classic) (?=\b|\]|\=)
451 }ix, $text, 2;
452 }
453 15 ▶ { no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
454 # warn __PACKAGE__.':'.__LINE__.": $before, $tag1, $tag2, $after)\n";
455 #warn __PACKAGE__.':'.__LINE__.": RE: $current_open_re\n";
456 }
457 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\@opened], ['opened']);
458 511 ▶ if (length $before) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $before) 313 198 511
459 # look if it contains a closing tag
460 #warn __PACKAGE__.':'.__LINE__.": BEFORE $before\n";
461 313 ▶ while (length $current_open_re and $before =~ s# (.*?) (\[ / ($current_open_re) \]) ##ixs) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $current_open_re and $before =~ s( (.*?) (\[ / ($current_open_re) \]) )[]six) 207 313 520
Condition100%3/3
length $current_open_re and $before =~ s( (.*?) (\[ / ($current_open_re) \]) )[]six
!ll&&!rl&&r
207106207
MC/DC100%2/2
length $current_open_re and $before =~ s( (.*?) (\[ / ($current_open_re) \]) )[]six
length $current_open_re $before =~ s( (.*?) (\[ / ($current_open_re) \]) )[]six
Truth table100%3/3
A and B
A= length $current_open_reB= $before =~ s( (.*?) (\[ / ($current_open_re) \]) )[]six
ABresult
0X0
100
111
462 # found closing tag
463 207 my ($content, $end, $name) = ($1, $2, $3);
464 #warn __PACKAGE__.':'.__LINE__.": found closing tag $name!\n";
465 207 my $f;
466 # try to find the matching opening tag
467 my @not_close;
468 207 ▶ while (@opened) {
Branch: 1 branch
BranchTrueFalseTotal
if (@opened) 240 0 240
469 240 my $try = pop @opened;
470 $current_open_re = join '|', map {
471 240 quotemeta $_->get_name
472 } @opened;
473 240 ▶ if ($try->get_name eq lc $name) {
Branch: 2 branches
BranchTrueFalseTotal
if ($try->get_name eq lc $name) { } 207 33 240
elsif (not $try->get_close) { } 25 8 33
474 207 $f = $try;
475 207 last;
476 }
477 elsif (!$try->get_close) {
478 25 $self->_finish_tag($try, '');
479 25 unshift @not_close, $try;
480 }
481 else {
482 # unbalanced
483 8 $self->_add_error('unclosed', $try);
484 8 ▶ if ($self->get_close_open_tags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_close_open_tags) { } 1 7 8
485 # close
486 1 $f = $try;
487 1 unshift @not_close, $try;
488 1 ▶ if (@opened) {
Branch: 1 branch
BranchTrueFalseTotal
if (@opened) 1 0 1
489 1 $opened[-1]->add_content('');
490 }
491 1 $self->_finish_tag($try, '[/'. $try->get_name() .']', 1);
492 }
493 else {
494 # just add unparsed text
495 7 $callback_found_tag->($_) for $try->_reduce;
496 }
497 }
498 }
499 207 ▶ if (@not_close) {
Branch: 1 branch
BranchTrueFalseTotal
if (@not_close) 22 185 207
500 22 $not_close[-1]->add_content($content);
501 }
502 207 for my $n (@not_close) {
503 26 $f->add_content($n);
504 #$callback_found_tag->($n);
505 }
506 # add text before closing tag as content to the current open tag
507 207 ▶ if ($f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f) 207 0 207
508 207 ▶ unless (@not_close) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@not_close) 185 22 207
509 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$f], ['f']);
510 185 $f->add_content( $content );
511 }
512 # TODO
513 207 $self->_finish_tag($f, $end);
514 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$f], ['f']);
515 207 $callback_found_tag->($f);
516 }
517 }
518 # warn __PACKAGE__." === before='$before' ($tag)\n";
519 313 $callback_found_text->($before);
520 }
521  
522 511 ▶ if (defined $tag1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag1) 10 501 511
523 10 $in_url = grep { $_->get_class eq 'url' } @opened;
524 # short tag
525 # $callback_found_text->($before) if length $before;
526 10 ▶ if ($after =~ s{ :// ([^\[]+) \] }{}x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($after =~ s( :// ([^\[]+) \] )[]x) { } 8 2 10
527 8 my $content = $1;
528 8 my ($attr, $title) = split /\|/, $content, 2;
529 my $tag = $self->new_tag({
530 name => lc $tag1,
531 attr => [[$attr]],
532 attr_raw => $attr,
533 content => [(defined $title and length $title) ? $title : ()],
534 start => "[$tag1://$content]",
535 close => 0,
536 class => $defs->{lc $tag1}->{class},
537 single => $defs->{lc $tag1}->{single},
538 8 ▶ in_url => $in_url,
Branch: 1 branch
BranchTrueFalseTotal
defined $title && length $title ? : 4 4 8
Condition66%2/3
defined $title and length $title
!ll&&!rl&&r
404
MC/DC50%1/2
defined $title and length $title
defined $title length $title
Truth table66%2/3
A and B
A= defined $titleB= length $title
ABresult
0X0
100
111
539 type => 'short',
540 });
541 8 ▶ if ($in_url and $tag->get_class eq 'url') {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_url and $tag->get_class eq 'url') { } 1 7 8
Condition66%2/3
$in_url and $tag->get_class eq "url"
!ll&&!rl&&r
701
MC/DC50%1/2
$in_url and $tag->get_class eq "url"
$in_url $tag->get_class eq "url"
Truth table66%2/3
A and B
A= $in_urlB= $tag->get_class eq "url"
ABresult
0X0
100
111
542 1 $callback_found_text->($tag->get_start);
543 }
544 else {
545 7 $callback_found_tag->($tag);
546 }
547 }
548 else {
549 2 $callback_found_text->("[$tag1");
550 }
551 10 $text = $after;
552 10 next;
553 }
554 501 $tag = $tag2;
555  
556  
557 501 $in_url = grep { $_->get_class eq 'url' } @opened;
558  
559 501 ▶ if ($after) {
Branch: 2 branches
BranchTrueFalseTotal
if ($after) { } 341 160 501
elsif ($tag) { } 1 159 160
560 # found start of a tag
561 #warn __PACKAGE__.':'.__LINE__.": find attribute for $tag\n";
562 341 my ($ok, $attributes, $attr_string, $end) = $self->$parse_attributes(
563 text => \$after,
564 tag => lc $tag,
565 );
566 341 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 335 6 341
567 335 my $attr = $attr_string;
568 335 ▶ $attr = '' unless defined $attr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attr 0 335 335
569 #warn __PACKAGE__.':'.__LINE__.": found attribute for $tag: $attr\n";
570 335 my $close = $defs->{lc $tag}->{close};
571 335 my $def = $defs->{lc $tag};
572 my $open = $self->new_tag({
573 name => lc $tag,
574 attr => $attributes,
575 attr_raw => $attr_string,
576 content => [],
577 start => "[$tag$attr]",
578 close => $close,
579 class => $defs->{lc $tag}->{class},
580 single => $defs->{lc $tag}->{single},
581 335 in_url => $in_url,
582 type => 'classic',
583 });
584 335 my $success = 1;
585 335 ▶ my $nested_url = $in_url && $open->get_class eq 'url';
Condition100%3/3
$in_url && $open->get_class eq 'url'
!ll&&!rl&&r
323111
MC/DC100%2/2
$in_url && $open->get_class eq 'url'
$in_url $open->get_class eq 'url'
Truth table100%3/3
A && B
A= $in_urlB= $open->get_class eq 'url'
ABresult
0X0
100
111
586 {
587 335 my $last = $opened[-1];
588 335 ▶ if ($last and not $last->get_close and not $close) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last and not $last->get_close and not $close) 24 311 335
Condition100%6/6
$last and not $last->get_close and not $close
!ll&&!rl&&r
3001124
$last and not $last->get_close
!ll&&!rl&&r
19110935
MC/DC100%3/3
$last and not $last->get_close and not $close
$last not $last->get_close not $close
Truth table100%4/4
A and not(B) and not(C)
A= $lastB= not $last->get_closeC= not $close
ABCresult
0XX0
10X0
1100
1111
589 24 $self->_finish_tag($last, '');
590 # tag which should not have closing tag
591 24 pop @opened;
592 24 $callback_found_tag->($last);
593 }
594 }
595 335 ▶ if ($open->get_single && !$nested_url) {
Branch: 2 branches
BranchTrueFalseTotal
if ($open->get_single and not $nested_url) { } 3 332 335
elsif (not $nested_url) { } 331 1 332
Condition66%2/3
$open->get_single and not $nested_url
!ll&&!rl&&r
33203
MC/DC50%1/2
$open->get_single and not $nested_url
$open->get_single not $nested_url
Truth table66%2/3
A and not(B)
A= $open->get_singleB= not $nested_url
ABresult
0X0
100
111
596 3 $self->_finish_tag($open, '');
597 3 $callback_found_tag->($open);
598 }
599 elsif (!$nested_url) {
600 331 push @opened, $open;
601 331 my $def = $defs->{lc $tag};
602 #warn __PACKAGE__.':'.__LINE__.": $tag $def\n";
603 331 my $parse = $def->{parse};
604 331 ▶ if ($parse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parse) { } 287 44 331
605 $current_open_re = join '|', map {
606 287 quotemeta $_->get_name
607 } @opened;
608 }
609 else {
610 #warn __PACKAGE__.':'.__LINE__.": noparse, find content\n";
611 # just search for closing tag
612 44 ▶ if ($after =~ s# (.*?) (\[ / $tag \]) ##ixs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($after =~ s( (.*?) (\[ / $tag \]) )[]six) { } 39 5 44
613 39 my $content = $1;
614 39 my $end = $2;
615 #warn __PACKAGE__.':'.__LINE__.": CONTENT $content\n";
616 39 my $finished = pop @opened;
617 39 $finished->set_content([$content]);
618 39 $self->_finish_tag($finished, $end);
619 39 $callback_found_tag->($finished);
620 }
621 else {
622 #warn __PACKAGE__.':'.__LINE__.": nope '$after'\n";
623 }
624 }
625 }
626 else {
627 1 $callback_found_text->($open->get_start);
628 }
629  
630 }
631 else {
632 # unclosed tag
633 6 $callback_found_text->("[$tag$attr_string$end");
634 }
635 }
636 elsif ($tag) {
637 #warn __PACKAGE__.':'.__LINE__.": end\n";
638 1 $callback_found_text->("[$tag");
639 }
640 501 $text = $after;
641 #sleep 1;
642 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\@tags], ['tags']);
643 }
644 # warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\@opened], ['opened']);
645 192 ▶ if ($self->get_close_open_tags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_close_open_tags) { } 8 184 192
646 8 ▶ while (my $opened = pop @opened) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $opened = pop @opened) 11 8 19
647 11 $self->_add_error('unclosed', $opened);
648 11 $self->_finish_tag($opened, '[/' . $opened->get_name . ']', 1);
649 11 $callback_found_tag->($opened);
650 }
651 }
652 else {
653 184 ▶ while (my $opened = shift @opened) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $opened = shift @opened) 11 184 195
654 11 my @text = $opened->_reduce;
655 11 push @tags, @text;
656 }
657 }
658 192 ▶ if ($scalar_util) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scalar_util) { } 192 0 192
659 192 Scalar::Util::weaken($callback_found_tag);
660 }
661 else {
662 # just to make sure no memleak if there's no Scalar::Util
663 0 undef $callback_found_tag;
664 }
665 #warn __PACKAGE__.':'.__LINE__.": !!!!!!!!!!!! left text: '$text'\n";
666 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\@tags], ['tags']);
667 192 my $tree = $self->new_tag({
668 name => '',
669 content => [@tags],
670 start => '',
671 class => 'block',
672 attr => [[]],
673 });
674 192 $tree->_init_info({});
675 192 return $tree;
676 }
677  
678 535 ▶sub new_tag {
Subroutine new_tag: called CC=1 SCAR=0.0
Pod documented
679 535 my $self = shift;
680 535 Parse::BBCode::Tag->new(@_)
681 }
682  
683 25 ▶sub _add_error {
Subroutine _add_error: called CC=2 SCAR=6.9
684 25 my ($self, $error, $tag) = @_;
685 25 ▶ my $errors = $self->get_error || {};
Condition100%2/2
$self->get_error || {}
l!l
718
MC/DC100%1/1
$self->get_error || {}
$self->get_error
Truth table100%2/2
A
A= $self->get_error
Aresult
11
00
686 25 push @{ $errors->{$error} }, $tag;
687 25 $self->set_error($errors);
688 }
689  
690 11 ▶sub error {
Subroutine error: called CC=5 SCAR=16.1
Pod documented
691 11 my ($self, $type) = @_;
692 11 ▶ my $errors = $self->get_error || {};
Condition100%2/2
$self->get_error || {}
l!l
92
MC/DC100%1/1
$self->get_error || {}
$self->get_error
Truth table100%2/2
A
A= $self->get_error
Aresult
11
00
693 11 ▶ if ($type and $errors->{$type}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type and $errors->{$type}) { } 3 8 11
elsif (keys %$errors) { } 6 2 8
Condition66%2/3
$type and $errors->{$type}
!ll&&!rl&&r
083
MC/DC50%1/2
$type and $errors->{$type}
$type $errors->{$type}
Truth table66%2/3
A and B
A= $typeB= $errors->{$type}
ABresult
0X0
100
111
694 3 return $errors->{$type};
695 }
696 elsif (keys %$errors) {
697 6 return $errors;
698 }
699 2 return 0;
700 }
701  
702 192 ▶sub render {
Subroutine render: called CC=3 SCAR=11.0
Pod documented
703 192 my ($self, $text, $params) = @_;
704 192 ▶ if (@_ < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ < 2) 1 191 192
705 1 croak ("Missing input - Usage: \$parser->render(\$text)");
706 }
707 #warn __PACKAGE__.':'.__LINE__.": @_\n";
708 #sleep 2;
709 191 my $tree = $self->parse($text, $params);
710 191 my $out = $self->render_tree($tree, $params);
711 191 ▶ if ($self->get_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_error) 18 173 191
712 18 $self->set_tree($tree);
713 }
714 191 return $out;
715 }
716  
717 191 ▶sub render_tree {
Subroutine render_tree: called CC=2 SCAR=6.9
Pod documented
718 191 my ($self, $tree, $params) = @_;
719 191 ▶ $params ||= {};
Condition100%2/2
$params ||= {}
l!l
1190
MC/DC100%1/1
$params ||= {}
$params
Truth table100%2/2
A
A= $params
Aresult
11
00
720 191 $self->set_params($params);
721 191 my $rendered = $self->_render_tree($tree);
722 191 $self->set_params(undef);
723 191 return $rendered;
724 }
725  
726 1023 ▶sub _render_tree {
Subroutine _render_tree: called CC=26 SCAR=32.6
727 1023 my ($self, $tree, $outer, $info) = @_;
728 1023 my $out = '';
729 1023 ▶ $info ||= {
Condition100%2/2
$info ||= {"stack", [], "tags", {}, "classes", {}}
l!l
823200
MC/DC100%1/1
$info ||= {"stack", [], "tags", {}, "classes", {}}
$info
Truth table100%2/2
A
A= $info
Aresult
11
00
730 stack => [],
731 tags => {},
732 classes => {},
733 };
734 1023 my $defs = $self->get_tags;
735 1023 ▶ if (ref $tree) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tree) { } 502 521 1023
736 502 my $name = $tree->get_name;
737 502 my %tags = %{ $info->{tags} };
738 502 $tags{$name}++;
739 502 my @stack = @{ $info->{stack} };
740 502 push @stack, $name;
741 502 my %classes = %{ $info->{classes} };
742 502 ▶ $classes{ $tree->get_class || '' }++;
Condition50%1/2
$tree->get_class || ''
l!l
5020
MC/DC0%0/1
$tree->get_class || ''
$tree->get_class
Truth table50%1/2
A
A= $tree->get_class
Aresult
11
00
743 502 my %info = (
744 tags => \%tags,
745 stack => [@stack],
746 classes => \%classes,
747 );
748 502 my $code = $defs->{$name}->{code};
749 502 my $parse = $defs->{$name}->{parse};
750 502 ▶ my $attr = $tree->get_attr || [];
Condition50%1/2
$tree->get_attr || []
l!l
5020
MC/DC0%0/1
$tree->get_attr || []
$tree->get_attr
Truth table50%1/2
A
A= $tree->get_attr
Aresult
11
00
751 502 $attr = $attr->[0]->[0];
752 502 my $content = $tree->get_content;
753 502 my $fallback;
754 502 my $string = '';
755 502 ▶ if (($tree->get_type || 'classic') eq 'classic') {
Branch: 1 branch
BranchTrueFalseTotal
if (($tree->get_type || 'classic') eq 'classic') { } 495 7 502
Condition100%2/2
$tree->get_type || 'classic'
l!l
311191
MC/DC100%1/1
$tree->get_type || 'classic'
$tree->get_type
Truth table100%2/2
A
A= $tree->get_type
Aresult
11
00
756 495 ▶ $fallback = (defined $attr and length $attr) ? $attr : $content;
Branch: 1 branch
BranchTrueFalseTotal
defined $attr && length $attr ? : 94 401 495
Condition100%3/3
defined $attr and length $attr
!ll&&!rl&&r
396594
MC/DC100%2/2
defined $attr and length $attr
defined $attr length $attr
Truth table100%3/3
A and B
A= defined $attrB= length $attr
ABresult
0X0
100
111
757 }
758 else {
759 7 $fallback = $attr;
760 7 ▶ $string = @$content ? '' : $attr;
Branch: 1 branch
BranchTrueFalseTotal
@$content ? : 3 4 7
761 }
762 502 ▶ if (ref $fallback) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fallback) 401 101 502
763 # we have recursive content, we don't want that in
764 # an attribute
765 $fallback = join '', grep {
766 401 not ref $_
767 } @$fallback;
768 }
769 502 ▶ if ($self->get_strip_linebreaks and ($tree->get_class || '') eq 'block') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_strip_linebreaks and ($tree->get_class || "") eq "block") 290 212 502
Condition80%4/5
$self->get_strip_linebreaks and ($tree->get_class || "") eq "block"
!ll&&!rl&&r
2210290
$tree->get_class || ''
l!l
5000
MC/DC50%1/2
$self->get_strip_linebreaks and ($tree->get_class || "") eq "block"
$self->get_strip_linebreaks $tree->get_class
Truth table66%2/3
A and B
A= $self->get_strip_linebreaksB= $tree->get_class
ABresult
0X0
100
111
770 290 ▶ if (@$content == 1 and not ref $content->[0] and defined $content->[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$content == 1 and not ref $content->[0] and defined $content->[0]) { } 75 215 290
elsif (@$content > 1) { } 175 40 215
Condition83%5/6
@$content == 1 and not ref $content->[0] and defined $content->[0]
!ll&&!rl&&r
215075
@$content == 1 and not ref $content->[0]
!ll&&!rl&&r
1754075
MC/DC66%2/3
@$content == 1 and not ref $content->[0] and defined $content->[0]
@$content == 1 not ref $content->[0] defined $content->[0]
Truth table75%3/4
A and not(B) and C
A= @$content == 1B= not ref $content->[0]C= defined $content->[0]
ABCresult
0XX0
10X0
1100
1111
771 75 $content->[0] =~ s/^\r?\n//;
772 75 $content->[0] =~ s/\r?\n\z//;
773 }
774 elsif (@$content > 1) {
775 175 ▶ if (not ref $content->[0] and defined $content->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $content->[0] and defined $content->[0]) 56 119 175
Condition66%2/3
not ref $content->[0] and defined $content->[0]
!ll&&!rl&&r
119056
MC/DC50%1/2
not ref $content->[0] and defined $content->[0]
not ref $content->[0] defined $content->[0]
Truth table66%2/3
not(A) and B
A= not ref $content->[0]B= defined $content->[0]
ABresult
0X0
100
111
776 56 $content->[0] =~ s/^\r?\n//;
777 }
778 175 ▶ if (not ref $content->[-1] and defined $content->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $content->[-1] and defined $content->[-1]) 155 20 175
Condition66%2/3
not ref $content->[-1] and defined $content->[-1]
!ll&&!rl&&r
200155
MC/DC50%1/2
not ref $content->[-1] and defined $content->[-1]
not ref $content->[-1] defined $content->[-1]
Truth table66%2/3
not(A) and B
A= not ref $content->[-1]B= defined $content->[-1]
ABresult
0X0
100
111
779 155 $content->[-1] =~ s/\r?\n\z//;
780 }
781 }
782 }
783 502 ▶ if (not exists $defs->{$name}->{parse} or $parse) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $defs->{$name}{'parse'} or $parse) { } 462 40 502
Condition100%3/3
not exists $defs->{$name}{"parse"} or $parse
l!l&&r!l&&!r
19626640
MC/DC100%2/2
not exists $defs->{$name}{"parse"} or $parse
not exists $defs->{$name}{"parse"} $parse
Truth table100%3/3
not(A) or B
A= not exists $defs->{$name}{"parse"}B= $parse
ABresult
1X1
011
000
784 462 for my $c (@$content) {
785 823 $string .= $self->_render_tree($c, $tree, \%info);
786 }
787 }
788 else {
789 40 $string = join '', @$content;
790 }
791 502 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) { } 311 191 502
792 311 my $o = $code->($self, $attr, \$string, $fallback, $tree, \%info);
793 311 $out .= $o;
794 }
795 else {
796 191 $out .= $string;
797 }
798 }
799 else {
800 #warn __PACKAGE__.':'.__LINE__.": ==== $tree\n";
801 521 $out .= $self->_render_text($outer, $tree, $info);
802 }
803 1023 return $out;
804 }
805  
806  
807 533 ▶sub escape_html {
Subroutine escape_html: called CC=2 SCAR=6.9
Pod documented
808 533 my ($str) = @_;
809 533 ▶ return '' unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 4 529 533
810 529 $str =~ s/&/&amp;/g;
811 529 $str =~ s/"/&quot;/g;
812 529 $str =~ s/'/&#39;/g;
813 529 $str =~ s/>/&gt;/g;
814 529 $str =~ s/</&lt;/g;
815 529 return $str;
816 }
817  
818 337 ▶sub parse_attributes {
Subroutine parse_attributes: called CC=21 SCAR=30.5
Pod documented
819 337 my ($self, %args) = @_;
820 337 my $text = $args{text};
821 337 my $tagname = $args{tag};
822 337 my $attribute_quote = $self->get_attribute_quote;
823 337 my $attr_string = '';
824 337 my $attributes = [];
825 337 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_direct_attribute and $$text =~ s/^(=[^\]]*)?]// or $$text =~ s/^( [^\]]*)?\]//) 333 4 337
Condition100%6/6
$self->get_direct_attribute and $$text =~ s/^(=[^\]]*)?]// or $$text =~ s/^( [^\]]*)?\]//
l!l&&r!l&&!r
33124
$self->get_direct_attribute and $$text =~ s/^(=[^\]]*)?]//
!ll&&!rl&&r
15331
MC/DC66%2/3
$self->get_direct_attribute and $$text =~ s/^(=[^\]]*)?]// or $$text =~ s/^( [^\]]*)?\]//
$self->get_direct_attribute $$text =~ s/^(=[^\]]*)?]// $$text =~ s/^( [^\]]*)?\]//
Truth table80%4/5
A and B or C
A= $self->get_direct_attributeB= $$text =~ s/^(=[^\]]*)?]//C= $$text =~ s/^( [^\]]*)?\]//
ABCresult
11X1
0X11
1011
0X00
1000
826 ($self->get_direct_attribute and $$text =~ s/^(=[^\]]*)?]//)
827 or
828 ($$text =~ s/^( [^\]]*)?\]//)
829 ) {
830 333 my $attr = $1;
831 333 my $end = ']';
832 333 ▶ $attr = '' unless defined $attr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attr 235 98 333
833 333 $attr_string = $attr;
834 333 ▶ unless (length $attr) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $attr) 235 98 333
835 235 return (1, [], $attr_string, $end);
836 }
837 98 ▶ if ($self->get_direct_attribute) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_direct_attribute) 97 1 98
838 97 $attr =~ s/^=//;
839 }
840 98 ▶ if ($self->get_strict_attributes and not length $attr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_strict_attributes and not length $attr) 1 97 98
Condition100%3/3
$self->get_strict_attributes and not length $attr
!ll&&!rl&&r
3941
MC/DC100%2/2
$self->get_strict_attributes and not length $attr
$self->get_strict_attributes not length $attr
Truth table100%3/3
A and not(B)
A= $self->get_strict_attributesB= not length $attr
ABresult
0X0
100
111
841 1 return (0, [], $attr_string, $end);
842 }
843 97 my @array;
844 97 ▶ if (length($attribute_quote) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $attribute_quote == 1) { } 96 1 97
845 96 ▶ if ($attr =~ s/^(?:$attribute_quote(.+?)$attribute_quote(?:\s+|$)|(.*?)(?:\s+|$))//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ s/^(?:$attribute_quote(.+?)$attribute_quote(?:\s+|$)|(.*?)(?:\s+|$))//) 96 0 96
846 96 ▶ my $val = defined $1 ? $1 : $2;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 25 71 96
847 96 push @array, [$val];
848 }
849 96 ▶ while ($attr =~ s/^([a-zA-Z0-9_]+)=(?:$attribute_quote(.+?)$attribute_quote(?:\s+|$)|(.*?)(?:\s+|$))//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ s/^([a-zA-Z0-9_]+)=(?:$attribute_quote(.+?)$attribute_quote(?:\s+|$)|(.*?)(?:\s+|$))//) 9 96 105
850 9 my $name = $1;
851 9 ▶ my $val = defined $2 ? $2 : $3;
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 7 2 9
852 9 push @array, [$name, $val];
853 }
854 }
855 else {
856 1 ▶ if ($attr =~ s/^(?:(["'])(.+?)\1|(.*?)(?:\s+|$))//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ s/^(?:(["'])(.+?)\1|(.*?)(?:\s+|$))//) 1 0 1
857 1 ▶ my $val = defined $2 ? $2 : $3;
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 0 1 1
858 1 push @array, [$val];
859 }
860 1 ▶ while ($attr =~ s/^([a-zA-Z0-9_]+)=(?:(["'])(.+?)\2|(.*?)(?:\s+|$))//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ s/^([a-zA-Z0-9_]+)=(?:(["'])(.+?)\2|(.*?)(?:\s+|$))//) 1 1 2
861 1 my $name = $1;
862 1 ▶ my $val = defined $3 ? $3 : $4;
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 1 0 1
863 1 push @array, [$name, $val];
864 }
865 }
866 97 ▶ if ($self->get_strict_attributes and length $attr and $attr =~ tr/ //c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_strict_attributes and length $attr and $attr =~ tr/ //c) 1 96 97
Condition83%5/6
$self->get_strict_attributes and length $attr and $attr =~ tr/ //c
!ll&&!rl&&r
9601
$self->get_strict_attributes and length $attr
!ll&&!rl&&r
3931
MC/DC66%2/3
$self->get_strict_attributes and length $attr and $attr =~ tr/ //c
$self->get_strict_attributes length $attr $attr =~ tr/ //c
Truth table75%3/4
A and B and C
A= $self->get_strict_attributesB= length $attrC= $attr =~ tr/ //c
ABCresult
0XX0
10X0
1100
1111
867 1 return (0, [], $attr_string, $end);
868 }
869 96 $attributes = [@array];
870 96 return (1, $attributes, $attr_string, $end);
871 }
872 4 return (0, $attributes, $attr_string, '');
873 }
874  
875 # TODO add callbacks
876 312 ▶sub _finish_tag {
Subroutine _finish_tag: called CC=3 SCAR=11.0
877 312 my ($self, $tag, $end, $auto_closed) = @_;
878 #warn __PACKAGE__.':'.__LINE__.": _finish_tag(@_)\n";
879 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$tag], ['tag']);
880 312 ▶ unless ($tag->get_finished) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tag->get_finished) 312 0 312
881 312 $tag->set_end($end);
882 312 $tag->set_finished(1);
883 312 ▶ $tag->set_auto_closed($auto_closed || 0);
Condition100%2/2
$auto_closed || 0
l!l
14298
MC/DC100%1/1
$auto_closed || 0
$auto_closed
Truth table100%2/2
A
A= $auto_closed
Aresult
11
00
884 }
885 312 return 1;
886 }
887  
888 __END__
↑ Summary BBCode/Tag.pm »