| 1 | package Text::Xatena::Node::Table; | ||||||||||||||||||||||||||||
| 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 | TABLE => qr/^\|/, | |||||||||||||||||||||||||||
| 8 | 19 | }; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 324 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 324 | my ($class, $s, $parent, $stack) = @_; | |||||||||||||||||||||||||||
| 12 | 324 | ▶ | if ($s->scan(TABLE)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 13 | 4 | my $a = $class->new([ $s->matched->[0] ]); | |||||||||||||||||||||||||||
| 14 | 4 | ▶ | until ($s->eos || !$s->scan(TABLE)) { | ||||||||||||||||||||||||||
|
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/^\|/)
| |||||||||||||||||||||||||||||
| 15 | 7 | push @$a, $s->matched->[0]; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | 4 | push @$parent, $a; | |||||||||||||||||||||||||||
| 18 | 4 | return 1; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 3 | ▶ | sub as_struct { | ||||||||||||||||||||||||||
|
Subroutine
as_struct: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 3 | my ($self, $context) = @_; | |||||||||||||||||||||||||||
| 24 | 3 | my $ret = []; | |||||||||||||||||||||||||||
| 25 | 3 | my $children = $self->children; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 3 | for my $line (@$children) { | |||||||||||||||||||||||||||
| 28 | 8 | my $row = []; | |||||||||||||||||||||||||||
| 29 | 8 | for my $col (split /\|/, $line) { | |||||||||||||||||||||||||||
| 30 | 32 | my ($th, $content) = ($col =~ /^(\*)?(.*)$/); | |||||||||||||||||||||||||||
| 31 | 32 | ▶ | push @$row, +{ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | name => ($th ? 'th' : 'td'), | ||||||||||||||||||||||||||||
| 33 | content => $context->inline->format($content), | ||||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 8 | shift @$row; | |||||||||||||||||||||||||||
| 37 | 8 | push @$ret, $row; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 | $ret; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 3 | ▶ | sub as_html { | ||||||||||||||||||||||||||
|
Subroutine
as_html: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 3 | my ($self, $context, %opts) = @_; | |||||||||||||||||||||||||||
| 45 | 3 | $context->_tmpl(__PACKAGE__, q[ | |||||||||||||||||||||||||||
| 46 | <table> | ||||||||||||||||||||||||||||
| 47 | ? for my $row (@$rows) { | ||||||||||||||||||||||||||||
| 48 | <tr> | ||||||||||||||||||||||||||||
| 49 | ? for my $col (@$row) { | ||||||||||||||||||||||||||||
| 50 | <{{= $col->{name} }}>{{= $col->{content} }}</{{= $col->{name} }}> | ||||||||||||||||||||||||||||
| 51 | ? } | ||||||||||||||||||||||||||||
| 52 | </tr> | ||||||||||||||||||||||||||||
| 53 | ? } | ||||||||||||||||||||||||||||
| 54 | </table> | ||||||||||||||||||||||||||||
| 55 | ], { | ||||||||||||||||||||||||||||
| 56 | rows => $self->as_struct($context) | ||||||||||||||||||||||||||||
| 57 | }); | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 19 | 1; | |||||||||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||||||||||