| 1 | # Copyright (C) 2003-2007, G. Allen Morris III, all rights reserved | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Data::Tabular::Output::TXT; | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 4 | ▶ | use base qw(Data::Tabular::Output); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 4 | ▶ | use Carp qw (croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 4 | ▶ | use overload '""' => \&_render; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | sub new | ||||||||||||||||||||
| 14 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||
| 15 | 3 | my $class = shift; | |||||||||||||||||||
| 16 | 3 | my $args = { @_ }; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 3 | my $self = bless {}, $class; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 3 | ▶ | die 'No table' unless $args->{table}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | 3 | $self->{table} = $args->{table}; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 3 | ▶ | $self->{output} = $args->{output} || croak "Need output"; | ||||||||||||||||||
|
Condition50%1/2
$args->{'output'} || croak('Need output')
MC/DC0%0/1
$args->{'output'} || croak('Need output')
$args->{'output'}
Truth table50%1/2
A
A= $args->{'output'}
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 3 | $self; | |||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | sub _render | ||||||||||||||||||||
| 29 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
_render: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 3 | my $self = shift; | |||||||||||||||||||
| 31 | 3 | $self->text; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | sub text | ||||||||||||||||||||
| 35 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
text: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||
| 36 | 3 | my $self = shift; | |||||||||||||||||||
| 37 | 3 | my $ret = "\n"; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 3 | my $output = $self->output; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 3 | my @table; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | my @col_length; | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 3 | for my $row ($self->rows(output => $self->output)) { | |||||||||||||||||||
| 46 | 48 | for my $cell ($row->cells($output->headers)) { | |||||||||||||||||||
| 47 | 260 | my $cell_data = $cell->data; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 260 | my $width = 20; # $cell->width; | |||||||||||||||||||
| 50 | 260 | $cell_data =~ s/^\s*(.*)\s*$/$1/; | |||||||||||||||||||
| 51 | 260 | ▶ | if ((my $length = length($cell_data)) >= ($col_length[$cell->col_id] || 0)) { | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$col_length[$cell->col_id] || 0
MC/DC100%1/1
$col_length[$cell->col_id] || 0
$col_length[$cell->col_id]
Truth table100%2/2
A
A= $col_length[$cell->col_id]
| |||||||||||||||||||||
| 52 | 124 | $col_length[$cell->col_id] = $length; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 3 | my $right = 0; | |||||||||||||||||||
| 58 | 3 | for my $row ($self->rows(output => $self->output)) { | |||||||||||||||||||
| 59 | 48 | for my $cell ($row->cells()) { | |||||||||||||||||||
| 60 | 260 | ▶ | push(@table, " ") if $cell->col_id; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 260 | my $cell_data = $cell->html_string; | |||||||||||||||||||
| 62 | 260 | my $width = $col_length[$cell->col_id]; | |||||||||||||||||||
| 63 | 260 | $cell_data =~ s/^\s*(.*)\s*$/$1/; | |||||||||||||||||||
| 64 | 260 | my $length = $width - length($cell_data); | |||||||||||||||||||
| 65 | 260 | ▶ | if ($right) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | 0 | push(@table, " " x $length); | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | 260 | push(@table, $cell_data); | |||||||||||||||||||
| 69 | 260 | ▶ | if (!$right) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 260 | push(@table, " " x $length); | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | 48 | push(@table, "\n"); | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | 3 | $ret .= join('', @table); | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 3 | $ret; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 4 | 1; | |||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||