| 1 | package HTML::TableContent::Table::Row; | ||||||||||
| 2 | |||||||||||
| 3 | 20 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 20 | our $VERSION = '0.18'; | |||||||||
| 6 | |||||||||||
| 7 | 20 | ▶ | use HTML::TableContent::Table::Header; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 20 | ▶ | use HTML::TableContent::Table::Row::Cell; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 20 | extends 'HTML::TableContent::Element'; | |||||||||
| 11 | |||||||||||
| 12 | has cells => ( | ||||||||||
| 13 | is => 'rw', | ||||||||||
| 14 | lazy => 1, | ||||||||||
| 15 | 2233 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 20 | ); | |||||||||
| 17 | |||||||||||
| 18 | 20 | has header => ( | |||||||||
| 19 | is => 'rw', | ||||||||||
| 20 | lazy => 1, | ||||||||||
| 21 | ); | ||||||||||
| 22 | |||||||||||
| 23 | 20 | has '+html_tag' => ( | |||||||||
| 24 | default => 'tr', | ||||||||||
| 25 | ); | ||||||||||
| 26 | |||||||||||
| 27 | around raw => sub { | ||||||||||
| 28 | 46 | ▶ | my ( $orig, $self ) = ( shift, shift ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 29 | |||||||||||
| 30 | 46 | my $row = $self->$orig(@_); | |||||||||
| 31 | |||||||||||
| 32 | 46 | my @cells = map { $_->raw } $self->all_cells; | |||||||||
| 33 | 46 | $row->{cells} = \@cells; | |||||||||
| 34 | |||||||||||
| 35 | 46 | return $row; | |||||||||
| 36 | 20 | }; | |||||||||
| 37 | |||||||||||
| 38 | around has_nested => sub { | ||||||||||
| 39 | 65 | ▶ | my ( $orig, $self ) = ( shift, shift ); | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 40 | |||||||||||
| 41 | 65 | my $nested = $self->$orig(@_); | |||||||||
| 42 | |||||||||||
| 43 | 65 | foreach my $cell ( $self->all_cells ) { | |||||||||
| 44 | 105 | ▶ | if ( $cell->has_nested ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 23 | $nested = 1; | |||||||||
| 46 | } | ||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 65 | return $nested; | |||||||||
| 50 | 20 | }; | |||||||||
| 51 | |||||||||||
| 52 | sub hash { | ||||||||||
| 53 | 43 | ▶ | my $hash = { }; | ||||||||
|
Subroutine
hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 54 | 43 | map { $hash->{$_->header->text} = $_->text } $_[0]->all_cells; | |||||||||
| 55 | 43 | return $hash; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | sub array { | ||||||||||
| 59 | 47 | ▶ | my @row = map { $_->text } $_[0]->all_cells; | ||||||||
|
Subroutine
array: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 60 | 47 | return @row; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | sub add_header { | ||||||||||
| 64 | 0 | ▶ | my $header = HTML::TableContent::Table::Header->new($_[1]); | ||||||||
|
Subroutine
add_header: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 65 | 0 | $_[0]->header($header); | |||||||||
| 66 | 0 | return $header; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | sub add_cell { | ||||||||||
| 70 | 5283 | ▶ | my $cell = HTML::TableContent::Table::Row::Cell->new($_[1]); | ||||||||
|
Subroutine
add_cell: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 71 | 5283 | push @{ $_[0]->cells }, $cell; | |||||||||
| 72 | 5283 | return $cell; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 6254 | ▶ | sub cell_count { return scalar @{ $_[0]->cells }; } | ||||||||
|
Subroutine
cell_count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 76 | |||||||||||
| 77 | 725 | ▶ | sub all_cells { return @{ $_[0]->cells }; } | ||||||||
|
Subroutine
all_cells: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 78 | |||||||||||
| 79 | 320 | ▶ | sub get_cell { return $_[0]->cells->[ $_[1] ]; } | ||||||||
|
Subroutine
get_cell: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 80 | |||||||||||
| 81 | 147 | ▶ | sub get_first_cell { return $_[0]->get_cell(0); } | ||||||||
|
Subroutine
get_first_cell: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 82 | |||||||||||
| 83 | 122 | ▶ | sub get_last_cell { return $_[0]->get_cell( $_[0]->cell_count - 1 ); } | ||||||||
|
Subroutine
get_last_cell: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 84 | |||||||||||
| 85 | 64 | ▶ | sub clear_cell { return splice @{ $_[0]->cells }, $_[1], 1; } | ||||||||
|
Subroutine
clear_cell: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 86 | |||||||||||
| 87 | 1 | ▶ | sub clear_first_cell { return shift @{ $_[0]->cells }; } | ||||||||
|
Subroutine
clear_first_cell: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 88 | |||||||||||
| 89 | 1 | ▶ | sub clear_last_cell { return $_[0]->clear_cell( $_[0]->cell_count - 1 ); } | ||||||||
|
Subroutine
clear_last_cell: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 90 | |||||||||||
| 91 | sub _filter_headers { | ||||||||||
| 92 | 130 | ▶ | my ( $self, $headers ) = @_; | ||||||||
|
Subroutine
_filter_headers: called CC=4 SCAR=13.9
| |||||||||||
| 93 | 130 | my $cells = []; | |||||||||
| 94 | 130 | foreach my $cell ( $self->all_cells ) { | |||||||||
| 95 | 356 | for ( @{$headers} ) { | |||||||||
| 96 | 686 | ▶ | if ( $cell->header->text eq $_->text ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 244 | push @{$cells}, $cell; | |||||||||
| 98 | } | ||||||||||
| 99 | } | ||||||||||
| 100 | } | ||||||||||
| 101 | 130 | return $self->cells($cells); | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | sub _render_element { | ||||||||||
| 105 | 147 | ▶ | my @cells = map { $_->render } $_[0]->all_cells; | ||||||||
|
Subroutine
_render_element: called CC=1 SCAR=0.0
| |||||||||||
| 106 | 147 | my $cell = sprintf '%s' x @cells, @cells; | |||||||||
| 107 | 147 | return $cell; | |||||||||
| 108 | }; | ||||||||||
| 109 | |||||||||||
| 110 | 20 | __PACKAGE__->meta->make_immutable; | |||||||||
| 111 | |||||||||||
| 112 | 20 | 1; | |||||||||
| 113 | |||||||||||
| 114 | __END__ | ||||||||||