| 1 | # Copyright (C) 2003-2007, G. Allen Morris III, all rights reserved | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | package | ||||||||||||||||||||||
| 5 | Data::Tabular::Table::Data; | ||||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | 8 | ▶ | use base 'Data::Tabular::Table'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | 8 | ▶ | use Data::Tabular::Type; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | 8 | ▶ | use Carp qw (croak); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | |||||||||||||||||||||||
| 13 | sub new | ||||||||||||||||||||||
| 14 | 27 | ▶ | { | ||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 15 | 27 | my $caller = shift; | |||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | 27 | my $self = $caller->SUPER::new(@_); | |||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | 27 | $self; | |||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | sub row_count | ||||||||||||||||||||||
| 23 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
row_count: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 24 | 0 | shift->_row_count; | |||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||
| 26 | |||||||||||||||||||||||
| 27 | sub _row_count | ||||||||||||||||||||||
| 28 | 109 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_row_count: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 29 | 109 | my $self = shift; | |||||||||||||||||||||
| 30 | |||||||||||||||||||||||
| 31 | 109 | scalar(@{$self->{data}->{rows}}); | |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||
| 33 | |||||||||||||||||||||||
| 34 | sub headers | ||||||||||||||||||||||
| 35 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
headers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 36 | 0 | my $self = shift; | |||||||||||||||||||||
| 37 | |||||||||||||||||||||||
| 38 | 0 | @{$self->{data}->{headers}}; | |||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||
| 40 | |||||||||||||||||||||||
| 41 | sub all_headers | ||||||||||||||||||||||
| 42 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
all_headers: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||
| 43 | 0 | my $self = shift; | |||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | 0 | ▶ | $self->{_all_headers} ||= [ @{$self->{data}->{headers} || []} ]; | ||||||||||||||||||||
|
Condition0%0/4
$self->{"_all_headers"} ||= [@{$self->{"data"}{"headers"} or [];}]
$self->{'data'}{'headers'} || []
MC/DC0%0/1
$self->{"_all_headers"} ||= [@{$self->{"data"}{"headers"} or [];}]
$self->{"_all_headers"}
MC/DC0%0/1
$self->{'data'}{'headers'} || []
$self->{'data'}{'headers'}
Truth table0%0/2
A
A= $self->{"_all_headers"}
Truth table0%0/2
A
A= $self->{'data'}{'headers'}
| |||||||||||||||||||||||
| 46 | 0 | my @headers = @{$self->{_all_headers}}; | |||||||||||||||||||||
| 47 | |||||||||||||||||||||||
| 48 | 0 | @headers; | |||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||
| 50 | |||||||||||||||||||||||
| 51 | sub get_row_column | ||||||||||||||||||||||
| 52 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
get_row_column: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||
| 53 | 0 | my $self = shift; | |||||||||||||||||||||
| 54 | 0 | my $row = shift; | |||||||||||||||||||||
| 55 | 0 | my $column = shift; | |||||||||||||||||||||
| 56 | 0 | my $count = scalar(@{$self->{data}->{headers}}); | |||||||||||||||||||||
| 57 | 0 | my $ret; | |||||||||||||||||||||
| 58 | 0 | ▶ | if ($column >= $count) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 59 | 0 | warn caller; | |||||||||||||||||||||
| 60 | 0 | $ret = 'Column too great'; | |||||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||||
| 62 | 0 | $ret = $self->{data}->{rows}->[$row][$column]; | |||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||
| 64 | |||||||||||||||||||||||
| 65 | 0 | ▶ | if (my $type = $self->{data}->{types}[$column]) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 66 | 0 | ▶ | unless (ref $ret) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 67 | 0 | $type = "Data::Tabular::Type::$type"; | |||||||||||||||||||||
| 68 | 0 | $ret = bless({ data => $ret }, $type); | |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | 0 | return $ret; | |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | sub get_row_column_name | ||||||||||||||||||||||
| 76 | 1395 | ▶ | { | ||||||||||||||||||||
|
Subroutine
get_row_column_name: called CC=6 SCAR=20.1
Pod
documented
| |||||||||||||||||||||||
| 77 | 1395 | my $self = shift; | |||||||||||||||||||||
| 78 | 1395 | my $row = shift; | |||||||||||||||||||||
| 79 | 1395 | my $column_name = shift; | |||||||||||||||||||||
| 80 | 1395 | my $count = scalar(@{$self->{data}->{headers}}); | |||||||||||||||||||||
| 81 | 1395 | my $column; | |||||||||||||||||||||
| 82 | my $ret; | ||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | 1395 | ▶ | for ($column = 0; $column < $count; $column++) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 85 | 5220 | ▶ | last if $self->{data}->{headers}->[$column] eq $column_name; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | 1395 | ▶ | if ($column >= $count) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 89 | 0 | $ret = 'Unknown Column '. $column_name; | |||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||
| 91 | 1395 | $ret = $self->{data}->{rows}->[$row][$column]; | |||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | 1395 | ▶ | if (my $type = $self->{data}->{types}[$column]) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 95 | 0 | ▶ | unless (ref $ret) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 96 | 0 | $type = "Data::Tabular::Type::$type"; | |||||||||||||||||||||
| 97 | 0 | $ret = bless({ data => $ret }, $type); | |||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | 1395 | return $ret; | |||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | sub row_package | ||||||||||||||||||||||
| 105 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
row_package: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 106 | 0 | require Data::Tabular::Row::Data; | |||||||||||||||||||||
| 107 | |||||||||||||||||||||||
| 108 | 0 | 'Data::Tabular::Row::Data'; | |||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | sub rows | ||||||||||||||||||||||
| 112 | 12 | ▶ | { | ||||||||||||||||||||
|
Subroutine
rows: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||
| 113 | 12 | my $self = shift; | |||||||||||||||||||||
| 114 | 12 | my $args = { @_ }; | |||||||||||||||||||||
| 115 | 12 | my @ret; | |||||||||||||||||||||
| 116 | |||||||||||||||||||||||
| 117 | 12 | ▶ | die 'Need output' unless $args->{output}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | 12 | ▶ | for (my $row = 0; $row < $self->_row_count; $row++) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 120 | push(@ret, $self->row_package->new( | ||||||||||||||||||||||
| 121 | table => $self, # FIXME: This is very bad! | ||||||||||||||||||||||
| 122 | input_row => $row, | ||||||||||||||||||||||
| 123 | extra => $self->{extra}, | ||||||||||||||||||||||
| 124 | output => $args->{output}, | ||||||||||||||||||||||
| 125 | 97 | row_id => $row + 1, | |||||||||||||||||||||
| 126 | )); | ||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | 12 | $self->{rows} = \@ret; | |||||||||||||||||||||
| 130 | 12 | ▶ | wantarray ? @{$self->{rows}} : $self->{rows}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||
| 132 | |||||||||||||||||||||||
| 133 | 8 | 1; | |||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||||