blib/lib/Text/Xatena/Node.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 10 / 10 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 4 totaltotal 93.4% 57 / 61 CC 8 SCAR 10.5
CC
8
Cov
100%
as_html
5.0
as_html_paragraph
3.0
new
2.0
CRAP 2.9
« lib/Text/Xatena/Node/Blockquote.pm ↑ Summary lib/Text/Xatena/Node/Table.pm »
1 package Text::Xatena::Node;
2  
3 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 use overload
6 20 ▶ '@{}' => \&children,
Subroutine BEGIN: called CC=1 SCAR=0.0
7 20 fallback => 1;
8  
9 20 ▶use Text::Xatena::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 273 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
12 273 my ($class, $children) = @_;
13 273 ▶ bless {
Condition100%2/2
$children || []
l!l
55218
MC/DC100%1/1
$children || []
$children
Truth table100%2/2
A
A= $children
Aresult
11
00
14 children => $children || [],
15 }, $class;
16 }
17  
18 514 ▶sub children { $_[0]->{children} };
Subroutine children: called CC=1 SCAR=0.0
Pod undocumented
19  
20 190 ▶sub as_html {
Subroutine as_html: called CC=5 SCAR=16.1
Pod undocumented
21 190 my ($self, $context, %opts) = @_;
22 190 my $ret = "";
23  
24 190 my $children = $_[0]->{children};
25 190 my @texts;
26 190 for my $child (@$children) {
27 370 ▶ if (ref($child)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $child) { } 113 257 370
28 113 ▶ $ret .= $self->as_html_paragraph($context, join("\n", @texts), %opts) if join '', @texts;
Branch: 1 branch
BranchTrueFalseTotal
if join "", @texts 22 91 113
29 113 @texts = ();
30 113 $ret .= $child->as_html($context, %opts);
31 } else {
32 257 push @texts, $child;
33 }
34 }
35 190 ▶ $ret .= $self->as_html_paragraph($context, join("\n", @texts), %opts) if join '', @texts;
Branch: 1 branch
BranchTrueFalseTotal
if join "", @texts 106 84 190
36  
37 190 $ret;
38 }
39  
40 ## NOT COMPATIBLE WITH Hatena Syntax: Auto br insertation as \n
41 114 ▶sub as_html_paragraph {
Subroutine as_html_paragraph: called CC=3 SCAR=11.0
Pod undocumented
42 114 my ($self, $context, $text, %opts) = @_;
43 114 $text = $context->inline->format($text, $context);
44  
45 114 ▶ if ($opts{stopp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'stopp'}) { } 11 103 114
46 11 $text;
47 } else {
48 "<p>" . join("",
49 map {
50 103 ▶ if (/^(\n+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\n+)$/) { } 9 112 121
51 9 "</p>" . ("<br />\n" x (length($1) - 2)) . "<p>";
52 } else {
53 112 join("<br />\n", split /\n/);
54 }
55 }
56 split(/(\n\n+)/, $text)
57 ) . "</p>\n";
58 }
59 }
60  
61 20 1;
62 __END__
« lib/Text/Xatena/Node/Blockquote.pm ↑ Summary lib/Text/Xatena/Node/Table.pm »