lib/Text/Xatena/Node/Section.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 4 / 4 Conditioncond 94.4% 17 / 18 MC/DCmcdc 77.7% 7 / 9 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 91.0% 71 / 78 CC 9 SCAR 16.6
CC
9
Cov
98%
parse
9.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.2
↑ Summary lib/Text/Xatena/Node/List.pm »
1 package Text::Xatena::Node::Section;
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  
7 19 ▶use Text::Xatena::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 19 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 SECTION => qr/^(?:
11 (\*\*\*?)([^\*].*) | # *** or **
12 (\*)((?!\*\*?[^\*]).*) # *
13 )$/x,
14 19 };
15  
16 320 ▶sub parse {
Subroutine parse: called CC=9 SCAR=22.0
Pod undocumented
17 320 my ($class, $s, $parent, $stack) = @_;
18 320 ▶ if ($s->scan(SECTION)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->scan(qr/^(?: (\*\*\*?)([^\*].*) | # *** or ** (\*)((?!\*\*?[^\*]).*) # * )$/x)) 44 276 320
19 44 ▶ my $level = length($s->matched->[1] || $s->matched->[3]);
Condition66%2/3
$s->matched->[1] || $s->matched->[3]
l!l&&r!l&&!r
14300
MC/DC0%0/2
$s->matched->[1] || $s->matched->[3]
$s->matched->[1] $s->matched->[3]
Truth table66%2/3
A || B
A= $s->matched->[1]B= $s->matched->[3]
ABresult
1X1
011
000
20 44 ▶ my $title = $s->matched->[2] || $s->matched->[4];
Condition100%3/3
$s->matched->[2] || $s->matched->[4]
l!l&&r!l&&!r
14291
MC/DC100%2/2
$s->matched->[2] || $s->matched->[4]
$s->matched->[2] $s->matched->[4]
Truth table100%3/3
A || B
A= $s->matched->[2]B= $s->matched->[4]
ABresult
1X1
011
000
21 44 $title =~ s/^\s+|\s+$//g;
22  
23 44 my $node = $class->new;
24 44 $node->{level} = $level;
25 44 $node->{title} = $title;
26  
27 pop @$stack while
28 ((ref($stack->[-1]) eq $class) && ($stack->[-1]->level >= $level)) ||
29 44 ▶ ($level == 1 && ref($stack->[-1]) eq 'Text::Xatena::Node::SeeMore' && !$stack->[-1]->{is_super});
Branch: 1 branch
BranchTrueFalseTotal
ref $stack->[-1] eq $class && $stack->[-1]->level >= $level || $level == 1 && ref $stack->[-1] eq "Text::Xatena::Node::SeeMore" && !$stack->[-1]{"is_super"} and do { pop @$stack } 24 44 68
Condition100%12/12
ref $stack->[-1] eq $class and $stack->[-1]->level >= $level or $level == 1 and ref $stack->[-1] eq "Text::Xatena::Node::SeeMore" and not $stack->[-1]{"is_super"}
l!l&&r!l&&!r
23144
ref $stack->[-1] eq $class and $stack->[-1]->level >= $level
!ll&&!rl&&r
331223
$level == 1 and ref $stack->[-1] eq "Text::Xatena::Node::SeeMore" and not $stack->[-1]{"is_super"}
!ll&&!rl&&r
4221
$level == 1 and ref $stack->[-1] eq "Text::Xatena::Node::SeeMore"
!ll&&!rl&&r
14283
MC/DC100%5/5
ref $stack->[-1] eq $class and $stack->[-1]->level >= $level or $level == 1 and ref $stack->[-1] eq "Text::Xatena::Node::SeeMore" and not $stack->[-1]{"is_super"}
ref $stack->[-1] eq $class $stack->[-1]->level >= $level $level == 1 ref $stack->[-1] eq "Text::Xatena::Node::SeeMore" not $stack->[-1]{"is_super"}
Truth table66%6/9
A and B or C and D and not(E)
A= ref $stack->[-1] eq $classB= $stack->[-1]->level >= $levelC= $level == 1D= ref $stack->[-1] eq "Text::Xatena::Node::SeeMore"E= not $stack->[-1]{"is_super"}
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
30  
31 44 $parent = $stack->[-1];
32  
33 44 push @$parent, $node;
34 44 push @$stack, $node;
35 44 return 1;
36 }
37 }
38  
39 74 ▶sub level { $_[0]->{level} }
Subroutine level: called CC=1 SCAR=0.0
Pod undocumented
40 39 ▶sub title { $_[0]->{title} }
Subroutine title: called CC=1 SCAR=0.0
Pod undocumented
41  
42 ## NOT COMPATIBLE WITH Hatena Syntax
43 39 ▶sub as_html {
Subroutine as_html: called CC=1 SCAR=0.0
Pod undocumented
44 39 my ($self, $context, %opts) = @_;
45 39 my $level = $self->level;
46  
47 39 $context->_tmpl(__PACKAGE__, q[
48 <div class="section">
49 <h{{= $level + 2 }}>{{= $title }}</h{{= $level + 2 }}>
50 {{= $content }}
51 </div>
52 ], {
53 title => $context->inline->format($self->title),
54 level => $level,
55 content => $self->SUPER::as_html($context, %opts),
56 });
57 }
58  
59 19 1;
60 __END__
↑ Summary lib/Text/Xatena/Node/List.pm »