| 1 | package HTML::TableExtract; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # This package extracts tables from HTML. Tables of interest may be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # specified using header information, depth, order in a depth, table tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # attributes, or some combination of the four. See the POD for more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # information. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # Author: Matthew P. Sisk. See the POD for copyright information. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use vars qw($VERSION @ISA); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | $VERSION = '2.13'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use HTML::Parser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | @ISA = qw(HTML::Parser); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | ▶ | use HTML::Entities; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # trickery for subclassing from HTML::TreeBuilder rather than the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # default HTML::Parser. (use HTML::TableExtract qw(tree);) Also installs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # a mode constant TREE(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 11 | ▶ | BEGIN { *TREE = sub { 0 } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 10 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=26.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 11 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 10 | ▶ | *TREE = @_ ? sub { 1 } : sub { 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | ▶ | return unless @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $mode = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | croak "Unknown mode '$mode'\n" unless $mode eq 'tree'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | eval "use HTML::TreeBuilder"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | croak "Problem loading HTML::TreeBuilder : $@\n" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | eval "use HTML::ElementTable 1.17"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | croak "problem loading HTML::ElementTable : $@\n" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | @ISA = qw(HTML::TreeBuilder); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Backwards compatibility for deprecated methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 11 | *table_state = *table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 11 | *table_states = *tables; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 11 | *first_table_state_found = *first_table_found; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 11 | my %Defaults = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | headers => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | depth => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | count => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | attribs => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | subtables => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | gridmap => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | decode => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | automap => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | slice_columns => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | keep_headers => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | br_translate => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | error_handle => \*STDOUT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | debug => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | keep_html => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | strip_html_on_match => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 11 | my $Dpat = join('|', sort keys %Defaults); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ### Constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 23 | ▶ | my $that = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 23 | ▶ | my $class = ref($that) || $that; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table33%1/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 23 | my(%pass, %parms, $k, $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 23 | ▶ | while (($k,$v) = splice(@_, 0, 2)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 31 | ▶ | if ($k eq 'headers') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 12 | ▶ | ref $v eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | or croak "Param '$k' must be passed in ref to array\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 12 | $parms{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | elsif ($k =~ /^$Dpat$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 19 | $parms{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $pass{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 23 | my $self = $class->SUPER::new(%pass); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 23 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 23 | foreach (keys %parms, keys %Defaults) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | $self->{$_} = exists $parms{$_} && defined $parms{$_} ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 376 | ▶ | $parms{$_} : $Defaults{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $parms{$_} and defined $parms{$_}
MC/DC50%1/2
exists $parms{$_} and defined $parms{$_}
exists $parms{$_}
defined $parms{$_}
Truth table66%2/3
A and B
A= exists $parms{$_}B= defined $parms{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 23 | ▶ | if ($self->{headers}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $self->_emsg("TE here, headers: ", join(',', @{$self->{headers}}), "\n") | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 12 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 12 | $self->{gridmap} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # Initialize counts and containers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 23 | $self->_reset_state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 23 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ### HTML::Parser overrides | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 10650 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=16 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 10650 | my @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 10650 | ▶ | @res = $self->SUPER::start(@_) if TREE(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Create a new table state if entering a table. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 10650 | ▶ | if ($_[0] eq 'table') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 111 | my $ts = $self->_enter_table(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 111 | ▶ | $ts->tree($res[0]) if @res; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | elsif ($self->{_in_a_table}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # Rows and cells are next. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 10389 | my $ts = $self->current_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 10389 | ▶ | if ($_[0] eq 'tr') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 984 | $ts->_enter_row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | ▶ | elsif ($_[0] eq 'td' || $_[0] eq 'th') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_[0] eq "td" or $_[0] eq "th"
MC/DC50%1/2
$_[0] eq "td" or $_[0] eq "th"
$_[0] eq "td"
$_[0] eq "th"
Truth table66%2/3
A or B
A= $_[0] eq "td"B= $_[0] eq "th"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 9312 | $ts->_enter_cell(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 9312 | ▶ | my %attrs = ref $_[1] ? %{$_[1]} : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 9312 | ▶ | my $rspan = $attrs{rowspan} || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$attrs{'rowspan'} || 1
MC/DC100%1/1
$attrs{'rowspan'} || 1
$attrs{'rowspan'}
Truth table100%2/2
A
A= $attrs{'rowspan'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 9312 | ▶ | my $cspan = $attrs{colspan} || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$attrs{'colspan'} || 1
MC/DC100%1/1
$attrs{'colspan'} || 1
$attrs{'colspan'}
Truth table100%2/2
A
A= $attrs{'colspan'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 9312 | $ts->_rasterizer->($ts->row_count, $rspan, $cspan); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 9312 | $ts->_anchor_item(@res); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ▶ | elsif (! TREE() && $ts->{in_cell}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
not TREE() and $ts->{"in_cell"}
MC/DC0%0/2
not TREE() and $ts->{"in_cell"}
not TREE()
$ts->{"in_cell"}
Truth table33%1/3
not(A) and B
A= not TREE()B= $ts->{"in_cell"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 93 | ▶ | if ($self->{keep_html}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # capture full text of tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->text($_[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | ▶ | elsif ($_[0] eq 'br' && $self->{br_translate}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_[0] eq "br" and $self->{"br_translate"}
MC/DC50%1/2
$_[0] eq "br" and $self->{"br_translate"}
$_[0] eq "br"
$self->{"br_translate"}
Truth table66%2/3
A and B
A= $_[0] eq "br"B= $self->{"br_translate"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Replace <br> with newlines if requested | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | $self->text("\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 10650 | @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } # end start | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | sub end { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 10647 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=10 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 10647 | my @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 10647 | ▶ | @res = $self->SUPER::end(@_) if TREE(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 10647 | ▶ | if ($self->{_in_a_table}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 10497 | my $ts = $self->current_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 10497 | ▶ | if ($_[0] eq 'td' || $_[0] eq 'th') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$_[0] eq "td" or $_[0] eq "th"
MC/DC50%1/2
$_[0] eq "td" or $_[0] eq "th"
$_[0] eq "td"
$_[0] eq "th"
Truth table66%2/3
A or B
A= $_[0] eq "td"B= $_[0] eq "th"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 9312 | $ts->_exit_cell; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | elsif ($_[0] eq 'tr') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 984 | $ts->_exit_row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | elsif ($_[0] eq 'table') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 111 | $self->_exit_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | elsif (! TREE()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 90 | ▶ | if ($self->{keep_html} && $ts->{in_cell}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"keep_html"} and $ts->{"in_cell"}
MC/DC0%0/2
$self->{"keep_html"} and $ts->{"in_cell"}
$self->{"keep_html"}
$ts->{"in_cell"}
Truth table33%1/3
A and B
A= $self->{"keep_html"}B= $ts->{"in_cell"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # capture full text of tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $self->text($_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 10647 | @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } # end end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | sub text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 9756 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: called CC=6 SCAR=19.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 9756 | my @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 9756 | ▶ | if (TREE()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | @res = $self->SUPER::text(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | elsif ($self->{_in_a_table}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 9449 | my $ts = $self->current_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 9449 | ▶ | if ($ts->{in_cell}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 9322 | ▶ | if ($self->{decode} && !$self->{keep_html}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"decode"} and not $self->{"keep_html"}
MC/DC0%0/2
$self->{"decode"} and not $self->{"keep_html"}
$self->{"decode"}
not $self->{"keep_html"}
Truth table33%1/3
A and not(B)
A= $self->{"decode"}B= not $self->{"keep_html"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 9322 | $ts->_add_text(decode_entities($_[0])); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $ts->_add_text($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 9756 | @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } # end text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 333 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 333 | ▶ | $self->_reset_state unless $self->{_parsing}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 333 | ▶ | $self->{_parsing} ||= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_parsing"} ||= 1
MC/DC100%1/1
$self->{"_parsing"} ||= 1
$self->{"_parsing"}
Truth table100%2/2
A
A= $self->{"_parsing"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 333 | $self->SUPER::parse(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | sub eof { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 23 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eof: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 23 | $self->{_parsing} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 23 | $self->SUPER::eof(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | ### End HTML::Parser overrides | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | ### Report Methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | sub depths { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # Return all depths where valid tables were located. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
depths: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | return () unless ref $self->{_tables}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | sort { $a <=> $b } keys %{$self->{_tables}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | sub counts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # Given a depth, return the counts of all valid tables found therein. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | my($self, $depth) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
counts: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | defined $depth or croak "Depth required\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return () unless exists $self->{_tables}{$depth}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | sort { $a <=> $b } keys %{$self->{_tables}{$depth}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | sub table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # Return the table state for a particular depth and count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | my($self, $depth, $count) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | defined $depth or croak "Depth required\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | defined $count or croak "Count required\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if (! $self->{_tables}{$depth} || ! $self->{_tables}{$depth}{$count}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_tables"}{$depth} and $self->{"_tables"}{$depth}{$count}
MC/DC0%0/2
$self->{"_tables"}{$depth} and $self->{"_tables"}{$depth}{$count}
$self->{"_tables"}{$depth}
$self->{"_tables"}{$depth}{$count}
Truth table0%0/3
A and B
A= $self->{"_tables"}{$depth}B= $self->{"_tables"}{$depth}{$count}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $self->{_tables}{$depth}{$count}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | sub first_table_found { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first_table_found: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 10 | ▶ | ref $self->{_ts_sequential}[0] ? $self->{_ts_sequential}[0] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | sub rows { shift->first_table_found->rows(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rows: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | sub tables { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # Return all valid table records found, in the order that they | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # were seen. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tables: called CC=3 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 14 | ▶ | while ($self->{_in_a_table}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $ts = $self->current_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | $self->_emsg("Mangled HTML in table ($ts->{depth},$ts->{count}), inferring closing table tag.\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $self->_exit_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 14 | @{$self->{_ts_sequential}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # in tree mode, we already are an HTML::TreeBuilder, which is an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # HTML::Element structure after parsing...but we provide this for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # consistency with the table object method for accessing the tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # structures. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub tree { shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tree: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | sub tables_report { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # Print out a summary of extracted tables, including depth/count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tables_report: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | foreach my $ts ($self->tables) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $str .= $ts->report(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | sub tables_dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tables_dump: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $self->_emsg($self->tables_report(@_)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # for testing/debugging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | sub _attribute_purge { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attribute_purge: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | foreach (keys %Defaults) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | delete $self->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | ### Runtime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | sub _enter_table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 111 | ▶ | my($self, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enter_table: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 111 | ++$self->{_cdepth}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 111 | ++$self->{_in_a_table}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 111 | my $depth = $self->{_cdepth}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # Table tag attributes, if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 111 | ▶ | my $attribs = $args[1] || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args[1] || {}
MC/DC0%0/1
$args[1] || {}
$args[1]
Truth table50%1/2
A
A= $args[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # Table states can come and go on the stack...here we retrieve the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # table state for the table surrounding the current table tag (parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # table state). If the current table tag belongs to a top level table, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # then this will be undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 111 | my $pts = $self->current_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # Counts are tracked for each depth. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 111 | my $counts = $self->{_counts}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 111 | ▶ | $counts->[$depth] = -1 unless defined $counts->[$depth]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 111 | ++$counts->[$depth]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 111 | my $count = $counts->[$depth]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | $self->_emsg("TABLE: cdepth $depth, ccount $count, it: $self->{_in_a_table}\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 111 | ▶ | if $self->{debug} >= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # Umbrella status means that this current table and all of its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # descendant tables will be harvested. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 111 | my $umbrella = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 111 | ▶ | if (! defined $self->{depth} && ! defined $self->{count} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
defined $self->{"depth"} or defined $self->{"count"} or $self->{"attribs"} or $self->{"headers"}
defined $self->{"depth"} or defined $self->{"count"} or $self->{"attribs"}
defined $self->{"depth"} or defined $self->{"count"}
MC/DC100%4/4
defined $self->{"depth"} or defined $self->{"count"} or $self->{"attribs"} or $self->{"headers"}
defined $self->{"depth"}
defined $self->{"count"}
$self->{"attribs"}
$self->{"headers"}
Truth table100%5/5
A or B or C or D
A= defined $self->{"depth"}B= defined $self->{"count"}C= $self->{"attribs"}D= $self->{"headers"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | ! $self->{attribs} && ! $self->{headers}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 30 | ++$umbrella; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # Basic parameters for the soon-to-be-created table state. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | my %tsparms = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | depth => $depth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | count => $count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | attribs => $attribs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | umbrella => $umbrella, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | automap => $self->{automap}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | slice_columns => $self->{slice_columns}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | keep_headers => $self->{keep_headers}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | counts => $counts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | error_handle => $self->{error_handle}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | debug => $self->{debug}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | keep_html => $self->{keep_html}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | strip_html_on_match => $self->{strip_html_on_match}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 111 | parent_table => $pts, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # Target constraints. There is no point in passing any of these along | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # if we are under an umbrella. Notice that with table states, "depth" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # and "count" are absolute coordinates recording where this table was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # created, whereas "tdepth" and "tcount" are the target constraints. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # Headers have "absolute" meaning, therefore are passed by the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # same name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 111 | ▶ | if (!$umbrella) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 81 | $tsparms{tdepth} = $self->{depth}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 81 | $tsparms{tcount} = $self->{count}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 81 | $tsparms{tattribs} = $self->{attribs}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 81 | $tsparms{headers} = $self->{headers}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # Abracadabra | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 111 | my $ts = HTML::TableExtract::Table->new(%tsparms); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # Push the newly created and configured table state onto the stack. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # This will now be the current_table(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 111 | push(@{$self->{_tablestack}}, $ts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 111 | $ts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | sub _exit_table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 111 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exit_table: called CC=8 SCAR=23.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 111 | my $ts = $self->current_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # Last ditch fix for HTML mangle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 111 | ▶ | if ($ts->{in_cell}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | $self->_emsg("Mangled HTML in table ($self->{depth},$self->{count}), forcing exit of cell ($ts->{rc},$ts->{cc}) due to table exit\n") if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $ts->_exit_cell; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 111 | ▶ | if ($ts->{in_row}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | $self->_emsg("Mangled HTML in table ($self->{depth},$self->{count}), forcing exit of row $ts->{rc} due to table exit\n") if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $ts->_exit_row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # transform from tree to grid using our rasterized template | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 111 | $ts->_grid_map(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 111 | ▶ | $self->_capture_table($ts) if $ts->_check_triggers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # Restore last table state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 111 | pop(@{$self->{_tablestack}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 111 | --$self->{_in_a_table}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 111 | my $lts = $self->current_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 111 | ▶ | if (ref $lts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 54 | $self->{_cdepth} = $lts->{depth}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # Back to the top level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 57 | $self->{_cdepth} = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | $self->_emsg("LEAVE: cdepth: $self->{_cdepth}, ccount: $ts->{count}, it: $self->{_in_a_table}\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 111 | ▶ | if $self->{debug} >= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | sub _capture_table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 89 | ▶ | my($self, $ts, $type) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_capture_table: called CC=8 SCAR=22.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 89 | ▶ | croak "Table state ref required\n" unless ref $ts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 89 | ▶ | if ($self->{debug} >= 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my $msg = "Captured table (" . $ts->depth . ',' . $ts->count . ")"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | $msg .= " ($type)" if $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $msg .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $self->_emsg($msg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 89 | ▶ | $ts->tree(HTML::ElementTable->new_from_tree($ts->tree)) if TREE(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 89 | ▶ | if ($self->{subtables}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 11 | foreach my $child (@{$ts->{children}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 8 | ▶ | next if $child->{captured}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 6 | $self->_capture_table($child, 'subtable'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 6 | $child->{slice_columns} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 6 | $child->{keep_headers} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 6 | $child->{headers} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 89 | $ts->{captured} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 89 | $self->{_tables}{$ts->{depth}}{$ts->{count}} = $ts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 89 | push(@{$self->{_ts_sequential}}, $ts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | sub current_table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 30668 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current_table: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 30668 | $self->{_tablestack}[$#{$self->{_tablestack}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | sub _reset_state { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 46 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reset_state: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 46 | $self->{_cdepth} = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 46 | $self->{_tablestack} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 46 | $self->{_tables} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 46 | $self->{_ts_sequential} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 46 | $self->{_counts} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 46 | $self->{_in_a_table} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 46 | $self->{_parsing} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | sub _emsg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emsg: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $fh = $self->{error_handle}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | return unless defined $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | print $fh @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | ########## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | package HTML::TableExtract::Table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 11 | *TREE = *HTML::TableExtract::TREE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 111 | ▶ | my $that = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 111 | ▶ | my $class = ref($that) || $that; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table33%1/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # Note: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # - 'depth' and 'count' are where this table were found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # - 'tdepth' and 'tcount' are target constraints on which to trigger. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # - 'headers' represent a target constraint, location independent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # - 'attribs' represent target table tag constraints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 111 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | umbrella => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | in_row => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | in_cell => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | rc => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | cc => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | grid => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | translation => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | hrow => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | order => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | children => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | captured => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | debug => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 111 | $self->{_rastamon} = HTML::TableExtract::Rasterize->make_rasterizer(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 111 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 111 | my %parms = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # Depth and Count -- this is the absolute address of the table. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 111 | ▶ | croak "Absolute depth required\n" unless defined $parms{depth}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 111 | ▶ | croak "Count required\n" unless defined $parms{count}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 111 | ▶ | croak "Counts required\n" unless defined $parms{counts}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 111 | foreach (keys %parms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 1767 | $self->{$_} = $parms{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | # Register lineage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 111 | my $pts = $self->{parent_table}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 111 | ▶ | $self->lineage($pts || undef); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pts || undef
MC/DC100%1/1
$pts || undef
$pts
Truth table100%2/2
A
A= $pts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 111 | ▶ | push(@{$pts->{children}}, $self) if ($pts); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 111 | delete $self->{parent_table}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 111 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | sub _anchor_item { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # anchor the reference to a cell in our grid -- in TREE mode this is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # a reference to a data element, otherwise it's a reference to an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # empty scalar in which we will collect our text. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 9312 | ▶ | my($self, @res) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_anchor_item: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 9312 | my $row = $self->{grid}[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 9312 | my $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 9312 | ▶ | if (@res && ref $res[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@res and ref $res[0]
MC/DC0%0/2
@res and ref $res[0]
@res
ref $res[0]
Truth table33%1/3
A and B
A= @resB= ref $res[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | $item = $res[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 9312 | my $scalar_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 9312 | $item = \$scalar_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 9312 | push(@$row, $item); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | sub _gridalias { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gridalias: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 3 | ▶ | $self->{gridalias} ||= $self->_make_gridalias; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"gridalias"} ||= $self->_make_gridalias
MC/DC0%0/2
$self->{"gridalias"} ||= $self->_make_gridalias
$self->{"gridalias"}
$self->_make_gridalias
Truth table66%2/3
A ||= B
A= $self->{"gridalias"}B= $self->_make_gridalias
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | sub _grid_map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # using our rasterized template, flesh out our captured items which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | # are still in 'tree' format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 111 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_grid_map: called CC=13 SCAR=30.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 111 | my $template = $self->_rasterizer->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 111 | my $grid = $self->{grid}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | # drop empty rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 111 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | foreach (0 .. $#$grid) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | next if @{$grid->[$_]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | $self->_emsg("Dropping empty row $_\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 111 | @$grid = grep(@$_, @$grid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 111 | foreach my $r (0 .. $#$template) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 984 | my $row = $grid->[$r]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 984 | my $trow = $template->[$r]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 984 | ▶ | $self->_emsg("Flesh row $r ($#$row) to $#$trow\n") if $self->{debug} > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 984 | foreach my $c (0 .. $#$trow) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 9342 | ▶ | print STDERR $trow->[$c] ? '1' : '0' if $self->{debug} > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 9342 | ▶ | if ($trow->[$c]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 9312 | ▶ | if (! defined $row->[$c]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | $row->[$c] = \undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 9312 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 30 | my $scalar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 30 | splice(@$row, $c, 0, \$scalar); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 984 | ▶ | print STDERR "\n" if $self->{debug} > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 984 | ▶ | croak "row $r splice mismatch: $#$row vs $#$trow\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | unless $#$row == $#$trow; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 111 | $grid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | sub _make_gridalias { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # our aliased grid will have references in masked cells to the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # cell that is covering it via spanning. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_gridalias: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 2 | my $grid = $self->{grid}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 2 | my $template = $self->_rasterizer->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 2 | my(@gridalias, @translation); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 2 | $gridalias[$_] = [@{$grid->[$_]}] foreach 0 .. $#$grid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 2 | foreach my $r (0 .. $#gridalias) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 14 | my $row = $gridalias[$r]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 14 | foreach my $c (0 .. $#$row) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 56 | ▶ | my $tcell = $template->[$r][$c] || next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$template->[$r][$c] || (next)
MC/DC100%1/1
$template->[$r][$c] || (next)
$template->[$r][$c]
Truth table100%2/2
A
A= $template->[$r][$c]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 36 | my($rspan, $cspan) = @$tcell; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 36 | foreach my $rs (0 .. $rspan-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 42 | foreach my $cs (0 .. $cspan-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 56 | $gridalias[$r + $rs][$c + $cs] = $grid->[$r][$c]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 56 | $translation[$r + $rs][$c + $cs] = "$r,$c"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 2 | $self->{translation} = \@translation; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 2 | $self->{gridalias} = \@gridalias; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | ### Constraint tests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | sub _check_dtrigger { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | # depth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 81 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_dtrigger: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 81 | ▶ | return 1 unless defined $self->{tdepth}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 15 | ▶ | $self->{tdepth} == $self->{depth} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | sub _check_ctrigger { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | # count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 74 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_ctrigger: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 74 | ▶ | return 1 unless defined $self->{tcount}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | return 1 if (exists $self->{counts}[$self->{depth}] && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 11 | ▶ | $self->{tcount} == $self->{counts}[$self->{depth}]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $self->{"counts"}[$self->{"depth"}] and $self->{"tcount"} == $self->{"counts"}[$self->{"depth"}]
MC/DC50%1/2
exists $self->{"counts"}[$self->{"depth"}] and $self->{"tcount"} == $self->{"counts"}[$self->{"depth"}]
exists $self->{"counts"}[$self->{"depth"}]
$self->{"tcount"} == $self->{"counts"}[$self->{"depth"}]
Truth table66%2/3
A and B
A= exists $self->{"counts"}[$self->{"depth"}]B= $self->{"tcount"} == $self->{"counts"}[$self->{"depth"}]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 7 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | sub _check_atrigger { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | # attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 67 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_atrigger: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 67 | ▶ | return 1 unless scalar keys %{$self->{tattribs}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 15 | ▶ | return 0 unless scalar keys %{$self->{attribs}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 15 | my $a_hit = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 15 | foreach my $attrib (keys %{$self->{tattribs}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 15 | ▶ | if (! defined $self->{attribs}{$attrib}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 8 | $a_hit = 0; last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 7 | ▶ | if (! defined $self->{tattribs}{$attrib}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | # undefined, but existing, target attribs are wildcards | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 6 | ▶ | if ($self->{tattribs}{$attrib} ne $self->{attribs}{$attrib}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 2 | $a_hit = 0; last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 15 | ▶ | $self->_emsg("Matched attributes\n") if $self->{debug} > 3 && $a_hit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"debug"} > 3 and $a_hit
MC/DC0%0/2
$self->{"debug"} > 3 and $a_hit
$self->{"debug"} > 3
$a_hit
Truth table33%1/3
A and B
A= $self->{"debug"} > 3B= $a_hit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 15 | $a_hit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | sub _check_htrigger { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | # headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 57 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_htrigger: called CC=25 SCAR=40.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 57 | ▶ | return 1 if $self->{umbrella}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 57 | ▶ | return 1 unless $self->{headers}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 46 | ROW: foreach my $r (0 .. $#{$self->{grid}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 70 | $self->_reset_hits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 70 | my $hpat = $self->_header_pattern; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 70 | my @hits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 70 | foreach my $c (0 .. $#{$self->{grid}[$r]}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 631 | my $ref = $self->{grid}[$r][$c]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 631 | my $target = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 631 | my $ref_type = ref $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 631 | ▶ | if ($ref_type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 631 | ▶ | if ($ref_type eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 631 | my $item = $$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 631 | ▶ | if ($self->{keep_html} && $self->{strip_html_on_match}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"keep_html"} and $self->{"strip_html_on_match"}
MC/DC0%0/2
$self->{"keep_html"} and $self->{"strip_html_on_match"}
$self->{"keep_html"}
$self->{"strip_html_on_match"}
Truth table33%1/3
A and B
A= $self->{"keep_html"}B= $self->{"strip_html_on_match"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | my $stripper = HTML::TableExtract::StripHTML->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | $target = $stripper->strip($item); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 631 | $target = $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | if (($self->{keep_html} || TREE()) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->{"keep_html"} || TREE() and $self->{"strip_html_on_match"}
$self->{"keep_html"} or TREE()
MC/DC0%0/3
$self->{"keep_html"} || TREE() and $self->{"strip_html_on_match"}
$self->{"keep_html"}
TREE()
$self->{"strip_html_on_match"}
Truth table0%0/5
A or B and C
A= $self->{"keep_html"}B= TREE()C= $self->{"strip_html_on_match"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | $self->{strip_html_on_match}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | $target = $ref->as_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | $target = $ref->as_HTML; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 631 | ▶ | $target = defined $target ? $target : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | $self->_emsg("attempt match on $target ($hpat): ") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 631 | ▶ | if $self->{debug} >= 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 631 | ▶ | if ($target =~ $hpat) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 180 | my $hit = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 180 | ▶ | $self->_emsg("($hit)\n") if $self->{debug} >= 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # Get rid of the header segment that matched so we can tell | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # when we're through with all header patterns. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 180 | my $real_hit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 180 | foreach (sort _header_string_sort keys %{$self->{hits_left}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 228 | ▶ | if ($hit =~ /$_/im) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 180 | delete $self->{hits_left}{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 180 | $real_hit = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 180 | $hpat = $self->_header_pattern; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 180 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 180 | ▶ | if (defined $real_hit) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 180 | ▶ | if ($self->{debug} >= 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | my $str = $ref_type eq 'SCALAR' ? $$ref : $ref->as_HTML; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | $self->_emsg("HIT on '$hit' ($real_hit) in $str ($r,$c)\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 180 | push(@hits, $hit); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 180 | $self->{hits}{$c} = $real_hit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 180 | push(@{$self->{order}}, $c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 180 | ▶ | if (!%{$self->{hits_left}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | # Successful header row match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 42 | ++$self->{head_found}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 42 | $self->{hrow_index} = $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 42 | $self->{hrow} = $self->{grid}[$r]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 42 | last ROW; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | elsif ($self->{debug} >= 5) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | $self->_emsg("0\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 28 | ▶ | if ($self->{debug} && @hits) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"debug"} and @hits
MC/DC0%0/2
$self->{"debug"} and @hits
$self->{"debug"}
@hits
Truth table33%1/3
A and B
A= $self->{"debug"}B= @hits
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | my $str = "Incomplete header match "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | $str .= "(left: " . join(', ', sort keys %{$self->{hits_left}}) . ") "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | $str .= "in row $r, resetting scan"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | $str .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | $self->_emsg($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 46 | $self->{head_found}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | sub _check_triggers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 111 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_triggers: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 111 | ▶ | return 1 if $self->{umbrella}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 81 | ▶ | $self->_check_dtrigger && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->_check_dtrigger and $self->_check_ctrigger and $self->_check_atrigger
$self->_check_dtrigger and $self->_check_ctrigger
MC/DC100%3/3
$self->_check_dtrigger and $self->_check_ctrigger and $self->_check_atrigger
$self->_check_dtrigger
$self->_check_ctrigger
$self->_check_atrigger
Truth table100%4/4
A and B and C
A= $self->_check_dtriggerB= $self->_check_ctriggerC= $self->_check_atrigger
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | $self->_check_ctrigger && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | $self->_check_atrigger && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | $self->_check_htrigger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | ### Maintain table context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | sub _enter_row { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 984 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enter_row: called CC=3 SCAR=13.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 984 | ▶ | if ($self->{in_row}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | ▶ | $self->_emsg("Mangled HTML in table ($self->{depth},$self->{count}), forcing exit of row $self->{rc} due to new row\n") if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | $self->_exit_row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 984 | ++$self->{rc}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 984 | ++$self->{in_row}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 984 | push(@{$self->{grid}}, []) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | sub _exit_row { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 984 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exit_row: called CC=5 SCAR=22.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 984 | ▶ | if ($self->{in_row}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 984 | ▶ | if ($self->{in_cell}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | ▶ | $self->_emsg("Mangled HTML in table ($self->{depth},$self->{count}), forcing exit of cell ($self->{rc}, $self->{cc}) due to new row\n") if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | $self->_exit_cell; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 984 | $self->{in_row} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 984 | $self->{cc} = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | $self->_emsg("Mangled HTML in table ($self->{depth},$self->{count}), extraneous </TR> ignored after row $self->{rc}\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | sub _enter_cell { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 9312 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enter_cell: called CC=8 SCAR=25.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 9312 | ▶ | if ($self->{in_cell}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | ▶ | $self->_emsg("Mangled HTML in table ($self->{depth},$self->{count}), forcing exit of cell ($self->{rc},$self->{cc}) due to new cell\n") if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | $self->_exit_cell; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 9312 | ▶ | if (!$self->{in_row}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | # Go ahead and try to recover from mangled HTML, because we care. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | $self->_emsg("Mangled HTML in table ($self->{depth},$self->{count}), inferring <TR> as row $self->{rc}\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | $self->_enter_row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 9312 | ++$self->{cc}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 9312 | ++$self->{in_cell}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 9312 | ▶ | my %attrs = ref $_[1] ? %{$_[1]} : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 9312 | ▶ | my $rspan = $attrs{rowspan} || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$attrs{'rowspan'} || 1
MC/DC100%1/1
$attrs{'rowspan'} || 1
$attrs{'rowspan'}
Truth table100%2/2
A
A= $attrs{'rowspan'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 9312 | ▶ | my $cspan = $attrs{colspan} || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$attrs{'colspan'} || 1
MC/DC100%1/1
$attrs{'colspan'} || 1
$attrs{'colspan'}
Truth table100%2/2
A
A= $attrs{'colspan'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | sub _exit_cell { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 9312 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exit_cell: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 9312 | ▶ | if ($self->{in_cell}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 9312 | $self->{in_cell} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | $self->_emsg("Mangled HTML in table ($self->{depth},$self->{count}), extraneous </TD> ignored in row $self->{rc}\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | # Header stuff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | sub _header_pattern { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 250 | ▶ | my($self, @headers) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_header_pattern: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | my $str = join('|', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | map("($_)", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 250 | sort _header_string_sort keys %{$self->{hits_left}} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 250 | my $hpat = qr/($str)/im; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 250 | ▶ | $self->_emsg("HPAT: /$hpat/\n") if $self->{debug} >= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 250 | $self->{hpat} = $hpat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | sub _header_string_sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | # this ensures that supersets appear before subsets in our header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | # search pattern, eg, '10' appears before '1' and 'hubbabubba' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | # appears before 'hubba'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 1112 | ▶ | if ($a =~ /^$b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_header_string_sort: called CC=3 SCAR=14.2
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | elsif ($b =~ /^$a/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 1112 | return $b cmp $a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | # Report methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 54 | ▶ | sub depth { shift->{depth} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
depth: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 54 | ▶ | sub count { shift->{count} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
count: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | sub coords { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
coords: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | ($self->depth, $self->count); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 9312 | ▶ | sub row_count { shift->{rc} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
row_count: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | ▶ | sub col_count { shift->{cc} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
col_count: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | sub tree { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tree: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | ▶ | @_ ? $self->{_tree_ref} = shift : $self->{_tree_ref}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | sub lineage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 165 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lineage: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 165 | ▶ | $self->{lineage} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"lineage"} ||= []
MC/DC100%1/1
$self->{"lineage"} ||= []
$self->{"lineage"}
Truth table100%2/2
A
A= $self->{"lineage"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 165 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 111 | my $pts = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 111 | my(@lineage, $pcoords); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 111 | ▶ | if ($pts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 54 | foreach my $pcoord ($pts->lineage) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 20 | push(@lineage, [@$pcoord]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 54 | $pcoords = [$pts->depth, $pts->count, $pts->{rc}, $pts->{cc}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 54 | push(@lineage, $pcoords); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 111 | $self->{lineage} = \@lineage; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 165 | @{$self->{lineage}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 36 | ▶ | sub rows { shift->_rows(0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rows: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | sub space_rows { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
space_rows: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | $self->_rows(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | sub _rows { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 36 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rows: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 36 | my $alias = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 36 | my @ri = $self->row_indices; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 36 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 36 | ▶ | my $grid = $alias ? $self->_gridalias : $self->{grid}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 36 | foreach ($self->row_indices) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 218 | push(@rows, scalar $self->_slice_and_normalize_row($grid->[$_])); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 36 | ▶ | wantarray ? @rows : \@rows; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | sub columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
columns: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | my @cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | my @rows = $self->rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | foreach my $row (@rows) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | foreach my $c (0 .. $#$row) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | ▶ | $cols[$c] ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$cols[$c] ||= []
MC/DC0%0/1
$cols[$c] ||= []
$cols[$c]
Truth table0%0/2
A
A= $cols[$c]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | push(@{$cols[$c]}, $row->[$c]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 0 | @cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | sub row_indices { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 78 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
row_indices: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 78 | my $start_index = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 78 | ▶ | if ($self->{headers}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 38 | $start_index = $self->hrow_index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 38 | ▶ | $start_index += 1 unless $self->{keep_headers}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 78 | $start_index .. $#{$self->{grid}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | sub col_indices { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
col_indices: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | my $row = $self->{grid}[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | 0 .. $#$row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | sub row { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
row: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 6 | my $r = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 6 | ▶ | $r <= $#{$self->{grid}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 0 | or croak "row $r out of range ($#{$self->{grid}})\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | my @row = $self->_slice_and_normalize_row( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 6 | $self->{grid}[($self->row_indices)[$r]] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 6 | ▶ | wantarray ? @row : \@row; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | sub _slice_and_normalize_row { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 224 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_slice_and_normalize_row: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 224 | my $rowref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 224 | my @row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 224 | ▶ | if ($self->{automap} && $self->_map_makes_a_difference) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"automap"} and $self->_map_makes_a_difference
MC/DC50%1/2
$self->{"automap"} and $self->_map_makes_a_difference
$self->{"automap"}
$self->_map_makes_a_difference
Truth table66%2/3
A and B
A= $self->{"automap"}B= $self->_map_makes_a_difference
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 128 | @row = @{$rowref}[$self->column_map]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 96 | @row = @$rowref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 224 | @row = map($self->_cell_to_content($_), @row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 224 | ▶ | wantarray ? @row : \@row; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | sub column { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
column: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 0 | my @column; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 0 | foreach my $row ($self->rows) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | push(@column, $self->cell($row, $c)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | ▶ | wantarray ? @column : \@column; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | sub cell { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cell: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 4 | my($r, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 4 | my $row = $self->row($r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 4 | ▶ | $c <= $#$row or croak "Column $c out of range ($#$row)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 4 | $self->_cell_to_content($row->[$c]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | sub _cell_to_content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 877 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cell_to_content: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 877 | ▶ | @_ or croak "cell item required\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 877 | my $cell = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 877 | ▶ | return $cell unless ref $cell; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 873 | ▶ | return $cell if TREE(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 873 | return $$cell; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | sub space { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
space: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 2 | my($r, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 2 | my $gridalias = $self->_gridalias; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 2 | ▶ | $r <= $#$gridalias | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | or croak "row $r out of range ($#$gridalias)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 2 | my $row = $gridalias->[$r]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 2 | ▶ | $c <= $#$row or croak "Column $c out of range ($#$row)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 2 | $self->_cell_to_content($row->[$c]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | sub source_coords { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 28 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
source_coords: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 28 | my($r, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 28 | ▶ | $r <= $#{$self->{translation}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 0 | or croak "row $r out of range ($#{$self->{translation}})\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 28 | my $row = $self->{translation}[$r]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 28 | ▶ | $c <= $#$row or croak "Column $c out of range ($#$row)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 28 | split(/,/, $self->{translation}[$r][$c]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | sub hrow_index { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 41 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hrow_index: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 41 | $self->{hrow_index}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | sub hrow { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hrow: called CC=5 SCAR=21.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 3 | ▶ | if ($self->{automap} && $self->_map_makes_a_difference) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"automap"} and $self->_map_makes_a_difference
MC/DC0%0/2
$self->{"automap"} and $self->_map_makes_a_difference
$self->{"automap"}
$self->_map_makes_a_difference
Truth table33%1/3
A and B
A= $self->{"automap"}B= $self->_map_makes_a_difference
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 3 | ▶ | return map(ref $_ ? $$_ : $_, @{$self->{hrow}}[$self->column_map]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | ▶ | return map(ref $_ ? $$_ : $_, @{$self->{hrow}}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | sub column_map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | # Return the column numbers of this table in the same order as the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | # provided headers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 419 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
column_map: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 419 | ▶ | if ($self->{headers}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | # First we order the original column counts by taking a hash slice | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | # based on the original header order. The resulting original | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | # column numbers are mapped to the actual content indices since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | # we could have a sparse slice. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 344 | my %order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 344 | foreach (keys %{$self->{hits}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 1026 | $order{$self->{hits}{$_}} = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 344 | return @order{@{$self->{headers}}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 75 | return 0 .. $#{$self->{grid}[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | sub _map_makes_a_difference { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 227 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_map_makes_a_difference: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 227 | ▶ | return 0 unless $self->{slice_columns}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 225 | my $diff = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 225 | my @order = $self->column_map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 225 | my @sorder = sort { $a <=> $b } @order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 225 | ▶ | ++$diff if $#order != $#sorder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 225 | ▶ | ++$diff if $#sorder != $#{$self->{grid}[0]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 225 | foreach (0 .. $#order) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 597 | ▶ | if ($order[$_] != $sorder[$_]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 131 | ++$diff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 131 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 225 | $diff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | sub _add_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 9322 | ▶ | my($self, $txt) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_text: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 9322 | my $r = $self->{rc}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 9322 | my $c = $self->{cc}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 9322 | my $row = $self->{grid}[$r]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 9322 | ${$row->[$c]} .= $txt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 9322 | $txt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | sub _reset_hits { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 70 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reset_hits: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 70 | ▶ | return unless $self->{headers}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 70 | $self->{hits} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 70 | $self->{order} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 70 | foreach (@{$self->{headers}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 254 | ++$self->{hits_left}{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 70 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 9425 | ▶ | sub _rasterizer { shift->{_rastamon} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rasterizer: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | sub report { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | # Print out a summary of this table, including depth/count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | ▶ | my($self, $include_content, $col_sep) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | ▶ | $col_sep ||= ':'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$col_sep ||= ":"
MC/DC0%0/1
$col_sep ||= ":"
$col_sep
Truth table0%0/2
A
A= $col_sep
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | my $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | $str .= "TABLE(" . $self->depth . ", " . $self->count . ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | ▶ | if ($include_content) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 0 | $str .= ":\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 0 | foreach my $row ($self->rows) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | $str .= join($col_sep, @$row) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 0 | $str .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 0 | $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | sub dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 0 | $self->_emsg($self->report(@_)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | sub _emsg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emsg: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 0 | my $fh = $self->{error_handle}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 0 | print $fh @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | ########## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 11 | package HTML::TableExtract::Rasterize; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | # Provide a closure that will rasterize (turn into a grid) a table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | # from a tree structure based on repeated data element calls with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | # rowspan and colspan information. Not as straight forward as it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | # seems...see test cases for an example bugaboo. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 11 | my $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | sub make_rasterizer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 111 | ▶ | my $pkg = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_rasterizer: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 111 | my(@grid, @row_spinner, @col_spinner); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 111 | my $empty_row_offset = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 9425 | ▶ | return \@grid unless @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=33 SCAR=39.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 9312 | my($row_num, $rspan, $cspan) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 9312 | ▶ | $rspan = 1 unless $rspan > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 9312 | ▶ | $cspan = 1 unless $cspan > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 9312 | my($rspin_propogate, $row_added); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 9312 | my $trigger = $#grid + $empty_row_offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 9312 | ▶ | if ($row_num > $trigger) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | # adjust for having been handed a row that skips a prior row, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | # otherwise the next cell will land in a wrong row. Hopefully | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | # this doesn't happen too often but I've seen it in the wild! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 984 | ▶ | if ($row_num - $trigger > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 0 | $empty_row_offset += $row_num - $trigger - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | # add new row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 984 | $row_added = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 984 | my @new_row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | # first add new row spinner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 984 | ▶ | if ($row_spinner[-1] && $col_spinner[-1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$row_spinner[-1] and $col_spinner[-1]
MC/DC0%0/2
$row_spinner[-1] and $col_spinner[-1]
$row_spinner[-1]
$col_spinner[-1]
Truth table33%1/3
A and B
A= $row_spinner[-1]B= $col_spinner[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 0 | push(@row_spinner, $row_spinner[-1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 0 | $rspin_propogate = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 984 | push(@row_spinner, $cspan - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | # spin columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 984 | foreach (@col_spinner) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 8382 | ▶ | if ($_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 15 | push(@new_row, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 15 | --$_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 8367 | push(@new_row, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 984 | ▶ | @new_row = (undef) unless @new_row; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 984 | push(@grid, \@new_row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 9312 | my $current_row = $grid[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | # locate next available cell in row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 9312 | my $col; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 9312 | foreach my $ci (0 .. $#$current_row) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 49821 | ▶ | if (! defined $current_row->[$ci]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 8463 | $col = $ci; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | 8463 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 9312 | ▶ | if (! defined $col) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 849 | ▶ | ADDCOL: while (! defined $col) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | # if no cells were available, add a column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 849 | foreach my $ri (0 .. $#grid) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | 849 | my $row = $grid[$ri]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 849 | my $cspan_count = $row_spinner[$ri]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 849 | ▶ | if (!$cspan_count) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 849 | push(@$row, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 0 | push(@$row, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 0 | --$row_spinner[$ri]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 849 | push(@col_spinner, $col_spinner[-1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | 849 | foreach my $ci (0 .. $#$current_row) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 4989 | ▶ | if (! defined $current_row->[$ci]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 849 | $col = $ci; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 849 | last ADDCOL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 849 | ▶ | $col_spinner[-1] = $rspan - 1 if $col == $#$current_row; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 849 | $row_spinner[$#grid] = $cspan - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | # we now have correct coordinates for this element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | 9312 | $current_row->[$col] = [$rspan, $cspan]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 9312 | $col_spinner[$col] = $rspan - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | # if this is an embedded placement (not a trailing element), use up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | # the cspan | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 9312 | ▶ | if ($col < $#$current_row) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 7482 | my $offset = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 7482 | my $row_span = $col_spinner[$col]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 7482 | ▶ | if ($col + $row_spinner[-1] < $#$current_row && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$col + $row_spinner[-1] < $current_row->$#* and $row_added and not $rspin_propogate
$col + $row_spinner[-1] < $current_row->$#* and $row_added
MC/DC66%2/3
$col + $row_spinner[-1] < $current_row->$#* and $row_added and not $rspin_propogate
$col + $row_spinner[-1] < $current_row->$#*
$row_added
not $rspin_propogate
Truth table75%3/4
A and B and not(C)
A= $col + $row_spinner[-1] < $current_row->$#*B= $row_addedC= not $rspin_propogate
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | $row_added && !$rspin_propogate) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | # cell is spun out -- clear spinner unless it inherited cspan | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | # from a cell above | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 870 | $row_spinner[-1] = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 7482 | ▶ | while ($offset < $cspan) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 15 | my $cursor = $col + $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 15 | $current_row->[$cursor] = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | 15 | $col_spinner[$cursor] = $row_span; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 15 | ++$offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 15 | ▶ | if ($col + $offset > $#$current_row) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 3 | $row_spinner[-1] = $cspan - $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 3 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 9312 | ▶ | if ($DEBUG) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 0 | foreach my $r (0 .. $#grid) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 0 | my $row = $grid[$r]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | foreach my $c (0 .. $#$row) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 0 | ▶ | if (defined $row->[$c]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | 0 | ▶ | print STDERR $row->[$c] ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 0 | print STDERR '?'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 0 | print STDERR " $row_spinner[$r]\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | print STDERR "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 0 | foreach (@col_spinner) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 0 | ▶ | print STDERR defined $_ ? $_ : '?'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 0 | print STDERR "\n\n-----\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 9312 | return \@grid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 111 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | ########## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 11 | package HTML::TableExtract::StripHTML; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 11 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 11 | ▶ | use HTML::Parser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | 11 | @ISA = qw(HTML::Parser); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | sub tag { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 0 | ▶ | my($self, $tag, $num) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | 0 | $self->{_htes_inside}{$tag} += $num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | sub text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | 0 | ▶ | return if $self->{_htes_inside}{script} || $self->{_htes_inside}{style}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_htes_inside"}{"script"} or $self->{"_htes_inside"}{"style"}
MC/DC0%0/2
$self->{"_htes_inside"}{"script"} or $self->{"_htes_inside"}{"style"}
$self->{"_htes_inside"}{"script"}
$self->{"_htes_inside"}{"style"}
Truth table0%0/3
A or B
A= $self->{"_htes_inside"}{"script"}B= $self->{"_htes_inside"}{"style"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | 0 | $self->{_htes_tidbit} .= $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 0 | my $self = HTML::Parser->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | api_version => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | handlers => [start => [\&tag, "self, tagname, '+1'"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | end => [\&tag, "self, tagname, '-1'"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | text => [\&text, "self, dtext"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | marked_sections => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | 0 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | sub strip { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strip: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | 0 | $self->parse(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 0 | $self->eof; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | 0 | $self->{_htes_tidbit}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||