BBCode/Tag.pm

filter: Statementstmt 86.8% 66 / 76 Branchbran 68.1% 15 / 22 Conditioncond 64.2% 9 / 14 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 90.9% 10 / 11 Podpod 100% 4 / 4 totaltotal 80.7% 109 / 135 CC 22 SCAR 27.1
CC
22
Cov
80%
walk
56.0
_init_info
5.0
_reduce
5.0
CRAP 15.0
« BBCode.pm ↑ Summary BBCode/XHTML.pm »
1 package Parse::BBCode::Tag;
2 15 $Parse::BBCode::Tag::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 Carp qw(croak carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
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/ name attr attr_raw content
10 finished start end close class single type in_url num level auto_closed /);
11  
12 463 ▶sub add_content {
Subroutine add_content: called CC=4 SCAR=13.9
Pod documented
13 463 my ($self, $new) = @_;
14 463 my $content = $self->get_content;
15 463 ▶ if (ref $new) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new) 131 332 463
16 131 push @$content, $new;
17 131 return;
18 }
19 332 ▶ if (@$content and not ref $content->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$content and not ref $content->[-1]) { } 18 314 332
Condition100%3/3
@$content and not ref $content->[-1]
!ll&&!rl&&r
2407418
MC/DC100%2/2
@$content and not ref $content->[-1]
@$content not ref $content->[-1]
Truth table100%3/3
A and not(B)
A= @$contentB= not ref $content->[-1]
ABresult
0X0
100
111
20 18 $content->[-1] .= $new;
21 }
22 else {
23 314 push @$content, $new;
24 }
25 }
26  
27 38 ▶sub raw_text {
Subroutine raw_text: called CC=3 SCAR=11.0
Pod documented
28 38 my ($self, %args) = @_;
29 38 %args = (
30 auto_close => 1,
31 %args,
32 );
33 38 my $auto_close = $args{auto_close};
34 38 my ($start, $end) = ($self->get_start, $self->get_end);
35 38 ▶ if (not $auto_close and $self->get_auto_closed) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $auto_close and $self->get_auto_closed) 2 36 38
Condition100%3/3
not $auto_close and $self->get_auto_closed
!ll&&!rl&&r
3422
MC/DC100%2/2
not $auto_close and $self->get_auto_closed
not $auto_close $self->get_auto_closed
Truth table100%3/3
not(A) and B
A= not $auto_closeB= $self->get_auto_closed
ABresult
0X0
100
111
36 2 $end = '';
37 }
38 38 my $text = $start;
39 38 $text .= $self->raw_content(%args);
40 15 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 38 $text .= $end;
42 38 return $text;
43 }
44  
45 507 ▶sub _init_info {
Subroutine _init_info: called CC=5 SCAR=16.1
46 507 my ($self, $num, $level) = @_;
47 507 ▶ $level ||= 0;
Condition100%2/2
$level ||= 0
l!l
315192
MC/DC100%1/1
$level ||= 0
$level
Truth table100%2/2
A
A= $level
Aresult
11
00
48 507 my $name = $self->get_name;
49 507 $num->{$name}++;
50 507 $self->set_num($num->{$name});
51 507 $self->set_level($level);
52 507 ▶ my $content = $self->get_content || [];
Condition50%1/2
$self->get_content || []
l!l
5070
MC/DC0%0/1
$self->get_content || []
$self->get_content
Truth table50%1/2
A
A= $self->get_content
Aresult
11
00
53 507 for my $c (@$content) {
54 880 ▶ next unless ref $c;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c 565 315 880
55 315 $c->_init_info($num, $level + 1);
56 }
57 }
58  
59 0 ▶sub walk {
Subroutine walk: not called CC=7 SCAR=40.3
Pod documented
60 0 my ($self, $type, $sub) = @_;
61 0 ▶ $type ||= 'bfs';
Condition0%0/2
$type ||= "bfs"
l!l
00
MC/DC0%0/1
$type ||= "bfs"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
62 0 ▶ unless ($type eq 'bfs') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type eq "bfs") 0 0 0
63 0 croak "walk(): $type '$type' not implemented";
64 }
65 0 my $result = $sub->($self);
66 0 ▶ return if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 0 0 0
67 0 ▶ my $content = $self->get_content || [];
Condition0%0/2
$self->get_content || []
l!l
00
MC/DC0%0/1
$self->get_content || []
$self->get_content
Truth table0%0/2
A
A= $self->get_content
Aresult
11
00
68 0 for my $c (@$content) {
69 0 ▶ next unless ref $c;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c 0 0 0
70 0 $c->walk($type, $sub);
71 }
72 }
73  
74 39 ▶sub raw_content {
Subroutine raw_content: called CC=3 SCAR=11.0
Pod documented
75 39 my ($self, %args) = @_;
76 39 my $content = $self->get_content;
77 39 my $text = '';
78 #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$self], ['self']);
79 39 for my $c (@$content) {
80 60 ▶ if (ref $c eq ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c eq ref $self) { } 20 40 60
81 20 $text .= $c->raw_text(%args);
82 }
83 else {
84 40 $text .= $c;
85 }
86 }
87 39 return $text;
88 }
89  
90 28 ▶sub _reduce {
Subroutine _reduce: called CC=5 SCAR=16.1
91 28 my ($self) = @_;
92 28 ▶ if ($self->get_finished) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_finished) 6 22 28
93 6 return $self;
94 }
95 22 my @text = $self->get_start;
96 22 my $content = $self->get_content;
97 22 for my $c (@$content) {
98 24 ▶ if (ref $c eq ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c eq ref $self) { } 6 18 24
99 6 push @text, $c->_reduce;
100 }
101 else {
102 18 push @text, $c;
103 }
104 }
105 22 ▶ push @text, $self->get_end if defined $self->get_end;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->get_end 0 22 22
106 22 return @text;
107 }
108  
109  
110 15 1;
111  
112 __END__
« BBCode.pm ↑ Summary BBCode/XHTML.pm »