| 1 | package Text::Xatena::Node::DefinitionList; | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use base qw(Text::Xatena::Node); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 19 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 19 | DL => qr/^:([^:]*):(.*)/, | |||||||||||||||||||||||||||
| 11 | 19 | }; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 332 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 332 | my ($class, $s, $parent, $stack) = @_; | |||||||||||||||||||||||||||
| 15 | 332 | ▶ | if ($s->scan(DL)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 8 | my $node = $class->new([ $s->matched->[0] ]); | |||||||||||||||||||||||||||
| 17 | 8 | ▶ | until ($s->eos || !$s->scan(DL)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$s->eos or not $s->scan(qr/^:([^:]*):(.*)/)
MC/DC100%2/2
$s->eos or not $s->scan(qr/^:([^:]*):(.*)/)
$s->eos
not $s->scan(qr/^:([^:]*):(.*)/)
Truth table100%3/3
A or not(B)
A= $s->eosB= not $s->scan(qr/^:([^:]*):(.*)/)
| |||||||||||||||||||||||||||||
| 18 | 11 | push @$node, $s->matched->[0]; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | 8 | push @$parent, $node; | |||||||||||||||||||||||||||
| 21 | 8 | return 1; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | ## NOT COMPATIBLE WITH Hatena Syntax | ||||||||||||||||||||||||||||
| 26 | 8 | ▶ | sub as_struct { | ||||||||||||||||||||||||||
|
Subroutine
as_struct: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 8 | my ($self, $context) = @_; | |||||||||||||||||||||||||||
| 28 | 8 | my $ret = []; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 8 | my $children = $self->children; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 8 | for my $line (@$children) { | |||||||||||||||||||||||||||
| 33 | 19 | ▶ | if (my ($description) = ($line =~ /^::(.+)/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 3 | push @$ret, +{ | |||||||||||||||||||||||||||
| 35 | name => 'dd', | ||||||||||||||||||||||||||||
| 36 | content => $context->inline->format($description), | ||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||||||||||
| 39 | 16 | my ($title, $description) = ($line =~ /^:([^:]+)(?::(.*))?$/); | |||||||||||||||||||||||||||
| 40 | 16 | push @$ret, +{ | |||||||||||||||||||||||||||
| 41 | name => 'dt', | ||||||||||||||||||||||||||||
| 42 | content => $context->inline->format($title), | ||||||||||||||||||||||||||||
| 43 | }; | ||||||||||||||||||||||||||||
| 44 | 16 | ▶ | push @$ret, +{ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | name => 'dd', | ||||||||||||||||||||||||||||
| 46 | content => $context->inline->format($description), | ||||||||||||||||||||||||||||
| 47 | } if $description; | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 8 | $ret; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 8 | ▶ | sub as_html { | ||||||||||||||||||||||||||
|
Subroutine
as_html: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 8 | my ($self, $context, %opts) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 8 | $context->_tmpl(__PACKAGE__, q[ | |||||||||||||||||||||||||||
| 58 | <dl> | ||||||||||||||||||||||||||||
| 59 | ? for (@$items) { | ||||||||||||||||||||||||||||
| 60 | <{{= $_->{name} }}>{{= $_->{content} }}</{{= $_->{name} }}> | ||||||||||||||||||||||||||||
| 61 | ? } | ||||||||||||||||||||||||||||
| 62 | </dl> | ||||||||||||||||||||||||||||
| 63 | ], { | ||||||||||||||||||||||||||||
| 64 | items => $self->as_struct($context), | ||||||||||||||||||||||||||||
| 65 | }); | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 19 | 1; | |||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||