BEGIN {
$Org::Element::Table::VERSION
=
'0.10'
;
}
use
5.010;
has
_dummy
=> (
is
=>
'rw'
);
sub
BUILD {
my
(
$self
,
$args
) =
@_
;
my
$pass
=
$args
->{pass} // 1;
my
$_str
=
$args
->{_str};
if
(
defined
$_str
&& !
defined
(
$self
->children)) {
if
(!
defined
(
$self
->_str_include_children)) {
$self
->_str_include_children(1);
}
my
$doc
=
$self
->document;
my
@rows0
=
split
/\R/,
$_str
;
$self
->children([]);
for
my
$row0
(
@rows0
) {
$log
->tracef(
"table line: %s"
,
$row0
);
next
unless
$row0
=~ /\S/;
my
$row
;
if
(
$row0
=~ /^\s*\|--+(?:\+--+)*\|?\s*$/) {
$row
= Org::Element::TableVLine->new(
parent
=>
$self
);
}
elsif
(
$row0
=~ /^\s*\|\s*(.+?)\s*\|?\s*$/) {
my
$s
= $1;
$row
= Org::Element::TableRow->new(
parent
=>
$self
,
children
=>[]);
for
my
$cell0
(
split
/\s*\|\s*/,
$s
) {
my
$cell
= Org::Element::TableCell->new(
parent
=>
$row
,
children
=>[]);
$doc
->_add_text(
$cell0
,
$cell
,
$pass
);
push
@{
$row
->children },
$cell
;
}
}
else
{
die
"Invalid line in table: $row0"
;
}
push
@{
$self
->children},
$row
;
}
}
}
1;