lib/Text/Xatena/Node/List.pm

filter: Statementstmt 100% 60 / 60 Branchbran 100% 18 / 18 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 96.9% 96 / 99 CC 14 SCAR 16.5
CC
14
Cov
100%
as_struct
9.0
parse
4.0
as_html
2.0
CRAP 5.2
« lib/Text/Xatena/Node/Section.pm ↑ Summary blib/lib/Text/Xatena/Inline.pm »
1 package Text::Xatena::Node::List;
2  
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 19 ▶use base qw(Text::Xatena::Node);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 19 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 LIST => qr/^([-+]+)\s*(.+)/,
8 19 };
9  
10 353 ▶sub parse {
Subroutine parse: called CC=4 SCAR=13.9
Pod undocumented
11 353 my ($class, $s, $parent, $stack) = @_;
12  
13 353 ▶ if ($s->scan(LIST)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->scan(qr/^([-+]+)\s*(.+)/)) 18 335 353
14 18 my $node = $class->new([ $s->matched ]);
15 18 ▶ until ($s->eos || !$s->scan(LIST)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s->eos or not $s->scan(qr/^([-+]+)\s*(.+)/)) 30 18 48
Condition100%3/3
$s->eos or not $s->scan(qr/^([-+]+)\s*(.+)/)
l!l&&r!l&&!r
12630
MC/DC100%2/2
$s->eos or not $s->scan(qr/^([-+]+)\s*(.+)/)
$s->eos not $s->scan(qr/^([-+]+)\s*(.+)/)
Truth table100%3/3
A or not(B)
A= $s->eosB= not $s->scan(qr/^([-+]+)\s*(.+)/)
ABresult
1X1
011
000
16 30 push @$node, $s->matched;
17 }
18 18 push @$parent, $node;
19 18 return 1;
20 }
21 }
22  
23 15 ▶sub as_struct {
Subroutine as_struct: called CC=9 SCAR=22.0
Pod undocumented
24 15 my ($self) = @_;
25  
26 15 my $ret = [];
27 15 my $stack = []; # ol ul stack (that is, exluding li)
28  
29 15 for my $child (@{ $self->children }) {
30 39 my ($line, $symbol, $text) = @$child;
31 39 my $level = length($symbol);
32 39 ▶ my $type = substr($line, $level - 1, 1) eq '+' ? 'ol' : 'ul';
Branch: 1 branch
BranchTrueFalseTotal
substr($line, $level - 1, 1) eq '+' ? : 6 33 39
33  
34 39 ▶ while ($level < @$stack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level < @$stack) 3 39 42
35 3 pop @$stack;
36 }
37  
38 39 ▶ pop @$stack if @$stack == $level && $stack->[-1]->{name} ne $type;
Branch: 1 branch
BranchTrueFalseTotal
if @$stack == $level and $stack->[-1]{"name"} ne $type 1 38 39
Condition100%3/3
@$stack == $level and $stack->[-1]{"name"} ne $type
!ll&&!rl&&r
18201
MC/DC100%2/2
@$stack == $level and $stack->[-1]{"name"} ne $type
@$stack == $level $stack->[-1]{"name"} ne $type
Truth table100%3/3
A and B
A= @$stack == $levelB= $stack->[-1]{"name"} ne $type
ABresult
0X0
100
111
39  
40 39 ▶ while (@$stack < $level) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack < $level) 23 39 62
41 23 my $container = +{
42 name => $type,
43 items => []
44 };
45  
46 23 ▶ if (@$stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack) { } 7 16 23
47 7 ▶ if ($stack->[-1]->{items}->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stack->[-1]{'items'}[-1]) { } 3 4 7
48 3 push @{ $stack->[-1]->{items}->[-1]->{children} }, $container;
49 } else {
50 4 my $item = {
51 name => 'li',
52 children => [ $container ],
53 };
54 4 push @{ $stack->[-1]->{items} }, $item;
55 }
56 } else {
57 16 push @$ret, $container;
58 }
59 23 push @$stack, $container;
60 }
61  
62 39 my $item = {
63 name => 'li',
64 children => [ $text ],
65 };
66  
67 39 push @{ $stack->[-1]->{items} }, $item;
68 }
69  
70 15 $ret;
71 }
72  
73 15 ▶sub as_html {
Subroutine as_html: called CC=2 SCAR=6.9
Pod undocumented
74 15 my ($self, $context, %opts) = @_;
75 15 my $ret = '';
76 15 for my $list (@{ $self->as_struct }) {
77 16 $ret .= $self->_as_html($context, $list, %opts);
78 }
79 15 $ret;
80 }
81  
82 23 ▶sub _as_html {
Subroutine _as_html: called CC=2 SCAR=6.9
83 23 my ($self, $context, $list, %opts) = @_;
84  
85 $context->_tmpl(__PACKAGE__, q[
86 <{{= $name }}>
87 ? for (@$items) {
88 <li>{{= $_ }}</li>
89 ? }
90 </{{= $name }}>
91 ], {
92 name => $list->{name},
93 items => [
94 map {
95 join('',
96 map {
97 46 ▶ if (ref($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 7 39 46
98 7 $self->_as_html($context, $_, %opts)
99 } else {
100 39 $context->inline->format($_)
101 }
102 }
103 43 @{ $_->{children} }
104 )
105 }
106 23 @{ $list->{items} }
107 ]
108 });
109 }
110  
111  
112 19 1;
113 __END__
« lib/Text/Xatena/Node/Section.pm ↑ Summary blib/lib/Text/Xatena/Inline.pm »