| 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 || []
MC/DC100%1/1
$children || []
$children
Truth table100%2/2
A
A= $children
| |||||||||||||
| 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
| |||||||||||||
| 28 | 113 | ▶ | $ret .= $self->as_html_paragraph($context, join("\n", @texts), %opts) if join '', @texts; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 46 | 11 | $text; | |||||||||||
| 47 | } else { | ||||||||||||
| 48 | "<p>" . join("", | ||||||||||||
| 49 | map { | ||||||||||||
| 50 | 103 | ▶ | if (/^(\n+)$/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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__ | ||||||||||||