Element/Table.pm

filter: Statementstmt 98.8% 83 / 84 Branchbran 63.3% 19 / 30 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 9 / 9 Podpod 80.0% 4 / 5 totaltotal 86.0% 117 / 136 CC 25 SCAR 18.5
CC
25
Cov
87%
BUILD
10.6
column_count
7.3
rows
4.0
CRAP 6.4
« Element/List.pm ↑ Summary Element/Footnote.pm »
1 package Org::Element::Table;
2  
3 6 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use locale;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 extends 'Org::Element';
8 6 with 'Org::ElementRole';
9 6 with 'Org::ElementRole::Block';
10  
11 6 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
12 6 our $DATE = '2026-07-21'; # DATE
13 6 our $DIST = 'Org-Parser'; # DIST
14 6 our $VERSION = '0.563'; # VERSION
15  
16 6 has _dummy => (is => 'rw'); # workaround Moo bug
17  
18 6 ▶sub BUILD {
Subroutine BUILD: called CC=10 SCAR=23.6
Pod undocumented
19 6 require Org::Element::TableRow;
20 6 require Org::Element::TableHLine;
21 6 require Org::Element::TableCell;
22 6 my ($self, $args) = @_;
23 6 ▶ my $pass = $args->{pass} // 1;
Condition50%1/2
$args->{"pass"} // 1
l!l
60
MC/DC0%0/1
$args->{"pass"} // 1
$args->{"pass"}
Truth table50%1/2
A
A= $args->{"pass"}
Aresult
11
00
24  
25 # parse _str into rows & cells
26 6 my $_str = $args->{_str};
27 6 ▶ if (defined $_str && !defined($self->children)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_str and not defined $self->children) 6 0 6
Condition33%1/3
defined $_str and not defined $self->children
!ll&&!rl&&r
006
MC/DC0%0/2
defined $_str and not defined $self->children
defined $_str not defined $self->children
Truth table33%1/3
A and not(B)
A= defined $_strB= not defined $self->children
ABresult
0X0
100
111
28  
29 6 ▶ if (!defined($self->_str_include_children)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->_str_include_children) 6 0 6
30 6 $self->_str_include_children(1);
31 }
32  
33 6 my $doc = $self->document;
34 6 my @rows0 = split /\R/, $_str;
35 6 $self->children([]);
36 6 for my $row0 (@rows0) {
37 20 log_trace("table line: %s", $row0);
38 20 ▶ next unless $row0 =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $row0 =~ /\S/l 0 20 20
39 20 my $row;
40 20 ▶ if ($row0 =~ /^\s*\|--+(?:\+--+)*\|?\s*$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($row0 =~ /^\s*\|--+(?:\+--+)*\|?\s*$/l) { } 2 18 20
elsif ($row0 =~ /^\s*\|\s*(.+?)\s*\|?\s*$/l) { } 18 0 18
41 2 $row = Org::Element::TableHLine->new(parent => $self);
42 } elsif ($row0 =~ /^\s*\|\s*(.+?)\s*\|?\s*$/) {
43 18 my $s = $1;
44 18 $row = Org::Element::TableRow->new(
45 parent => $self, children=>[]);
46 18 for my $cell0 (split /\s*\|\s*/, $s) {
47 32 my $cell = Org::Element::TableCell->new(
48 parent => $row, children=>[]);
49 32 $doc->_add_text($cell0, $cell, $pass);
50 32 push @{ $row->children }, $cell;
51 }
52 } else {
53 0 $self->die("Invalid line in table: $row0");
54 }
55 20 push @{$self->children}, $row;
56 }
57 }
58 }
59  
60 2 ▶sub rows {
Subroutine rows: called CC=4 SCAR=13.9
Pod documented
61 2 my ($self) = @_;
62 2 ▶ return [] unless $self->children;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->children 0 2 2
63 2 my $rows = [];
64 2 for my $el (@{$self->children}) {
65 10 ▶ push @$rows, $el if $el->isa('Org::Element::TableRow');
Branch: 1 branch
BranchTrueFalseTotal
if $el->isa("Org::Element::TableRow") 8 2 10
66 }
67 2 $rows;
68 }
69  
70 1 ▶sub row_count {
Subroutine row_count: called CC=4 SCAR=13.9
Pod documented
71 1 my ($self) = @_;
72 1 ▶ return 0 unless $self->children;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->children 0 1 1
73 1 my $n = 0;
74 1 for my $el (@{$self->children}) {
75 5 ▶ $n++ if $el->isa('Org::Element::TableRow');
Branch: 1 branch
BranchTrueFalseTotal
if $el->isa("Org::Element::TableRow") 4 1 5
76 }
77 1 $n;
78 }
79  
80 1 ▶sub column_count {
Subroutine column_count: called CC=7 SCAR=19.9
Pod documented
81 1 my ($self) = @_;
82 1 ▶ return 0 unless $self->children;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->children 0 1 1
83  
84 # get first row
85 1 my $row;
86 1 for my $el (@{$self->children}) {
87 1 ▶ if ($el->isa('Org::Element::TableRow')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($el->isa("Org::Element::TableRow")) 1 0 1
88 1 $row = $el;
89 1 last;
90 }
91 }
92 1 ▶ return 0 unless $row; # table doesn't have any row
Branch: 1 branch
BranchTrueFalseTotal
unless $row 0 1 1
93  
94 1 my $n = 0;
95 1 for my $el (@{$row->children}) {
96 3 ▶ $n++ if $el->isa('Org::Element::TableCell');
Branch: 1 branch
BranchTrueFalseTotal
if $el->isa("Org::Element::TableCell") 3 0 3
97 }
98 1 $n;
99 }
100  
101 1 ▶sub as_aoa {
Subroutine as_aoa: called CC=4 SCAR=13.9
Pod documented
102 1 my ($self) = @_;
103 1 ▶ return [] unless $self->children;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->children 0 1 1
104  
105 1 my @rows;
106 1 for my $row (@{$self->children}) {
107 5 ▶ next unless $row->isa('Org::Element::TableRow');
Branch: 1 branch
BranchTrueFalseTotal
unless $row->isa("Org::Element::TableRow") 1 4 5
108 4 push @rows, $row->as_array;
109 }
110 1 \@rows;
111 }
112  
113 6 1;
114 # ABSTRACT: Represent Org table
115  
116 __END__
« Element/List.pm ↑ Summary Element/Footnote.pm »