Structured/UL.pm

filter: Statementstmt 100% 54 / 54 Branchbran 90.0% 18 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 4 totaltotal 90.1% 82 / 91 CC 12 SCAR 14.5
CC
12
Cov
96%
process_li
6.0
is_ok
6.0
new
2.0
CRAP 4.3
« Structured/OL.pm ↑ Summary Structured/Block.pm »
1 package MKDoc::Text::Structured::UL;
2 20 ▶use base qw /MKDoc::Text::Structured::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 20 ▶use MKDoc::Text::Structured::LI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 sub new
9 274 ▶{
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
10 274 my $class = shift;
11 274 my $line = shift;
12  
13 274 my ($marker) = $line =~ /^((?:\*|\-)\s+)/;
14 274 ▶ return unless ($marker);
Branch: 1 branch
BranchTrueFalseTotal
unless $marker 267 7 274
15  
16 7 my $self = $class->SUPER::new();
17 7 $self->{indent_re} = " " x length ($marker);
18 7 return $self;
19 }
20  
21  
22 sub is_ok
23 52 ▶{
Subroutine is_ok: called CC=6 SCAR=17.9
Pod undocumented
24 52 my $self = shift;
25 52 ▶ $self->{lines} || return 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"lines"} or return 1 45 7 52
26  
27 45 my $line = shift;
28 45 my $re = $self->{indent_re};
29 45 ▶ $line eq '' and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$line eq "" and return 1 11 34 45
30 34 ▶ $line =~ /^\s+$/ and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^\s+$/ and return 1 1 33 34
31 33 ▶ $line =~ /^$re/ and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^$re/ and return 1 17 16 33
32  
33 16 my ($marker) = $line =~ /^((?:\*|\-)\s+)/;
34 16 ▶ $marker and do {
Branch: 1 branch
BranchTrueFalseTotal
$marker and do { $self->{"indent_re"} = " " x length($marker); return 1 } 13 3 16
35 13 $self->{indent_re} = " " x length ($marker);
36 13 return 1;
37 };
38 3 return;
39 }
40  
41  
42 sub process
43 7 ▶{
Subroutine process: called CC=1 SCAR=0.0
Pod undocumented
44 7 my $self = shift;
45 7 my @lines = @{$self->{lines}};
46 7 my $text = join "\n", @lines;
47 7 $text = $self->process_li ($text);
48 7 return "<ul>$text</ul>";
49 }
50  
51  
52 sub process_li
53 7 ▶{
Subroutine process_li: called CC=6 SCAR=18.0
Pod undocumented
54 7 my $self = shift;
55 7 my $text = shift;
56 7 my @lines = split /\n/, $text;
57 7 my @result = ();
58 7 my $current = undef;
59  
60 7 ▶ while (scalar @lines)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @lines) 58 7 65
61 {
62 58 my $line = shift (@lines);
63 58 ▶ $current ||= new MKDoc::Text::Structured::LI ($line);
Condition66%2/3
$current ||= "MKDoc::Text::Structured::LI"->new($line)
l!l&&r!l&&!r
38200
MC/DC0%0/2
$current ||= "MKDoc::Text::Structured::LI"->new($line)
$current "MKDoc::Text::Structured::LI"->new($line)
Truth table66%2/3
A ||= B
A= $currentB= "MKDoc::Text::Structured::LI"->new($line)
ABresult
1X1
011
000
64 58 ▶ $current || next;
Branch: 1 branch
BranchTrueFalseTotal
$current or next 58 0 58
65  
66 58 ▶ if ($current->is_ok ($line))
Branch: 1 branch
BranchTrueFalseTotal
if ($current->is_ok($line)) { } 45 13 58
67 {
68 45 $current->add_line ($line);
69 }
70 else
71 {
72 13 push @result, $current->process();
73 13 unshift (@lines, $line);
74 13 $current = undef;
75 }
76 }
77  
78 7 ▶ push @result, $current->process() if ($current);
Branch: 1 branch
BranchTrueFalseTotal
if $current 7 0 7
79 7 return join "\n", @result;
80 }
81  
82  
83 20 1;
84  
85  
86 __END__
« Structured/OL.pm ↑ Summary Structured/Block.pm »