| 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 | 8 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | package Data::Tabular; | ||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 8 | our $VERSION = '0.29'; | |||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 8 | ▶ | use Carp qw (croak); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | 8 | ▶ | use Data::Tabular::Group; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | 8 | ▶ | use Data::Tabular::Table::Extra; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | 8 | ▶ | use Data::Tabular::Table::Data; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | 8 | ▶ | use Data::Tabular::Config::Output; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | 8 | ▶ | use Data::Tabular::Config::Extra; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 17 | 8 | ▶ | use Data::Tabular::Extra; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | sub new | ||||||||||||||||||||||
| 20 | 9 | ▶ | { | ||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||
| 21 | 9 | my $caller = shift; | |||||||||||||||||||||
| 22 | 9 | ▶ | my $class = ref($caller) || $caller; | ||||||||||||||||||||
|
Condition33%1/3
ref $caller || $caller
MC/DC0%0/2
ref $caller || $caller
ref $caller
$caller
Truth table33%1/3
A || B
A= ref $callerB= $caller
| |||||||||||||||||||||||
| 23 | 9 | my $self = bless { @_ }, $class; | |||||||||||||||||||||
| 24 | |||||||||||||||||||||||
| 25 | my $extra = Data::Tabular::Config::Extra->new( | ||||||||||||||||||||||
| 26 | headers => $self->{extra_headers}, | ||||||||||||||||||||||
| 27 | columns => $self->{extra}, | ||||||||||||||||||||||
| 28 | types => $self->{extra_types}, | ||||||||||||||||||||||
| 29 | 9 | ); | |||||||||||||||||||||
| 30 | |||||||||||||||||||||||
| 31 | 9 | ▶ | if (ref($caller)) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 32 | 0 | ▶ | die q|Don't know how to copy object.| | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 33 | unless $caller->isa(__PACKAGE__); | ||||||||||||||||||||||
| 34 | 0 | $self = $caller->clone() | |||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||
| 36 | 9 | my $count = 0; | |||||||||||||||||||||
| 37 | 9 | ▶ | if ($self->{headers}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 38 | 9 | ▶ | $self->{_all_headers} = [ (@{$self->{headers} || []}, @{$self->{extra_headers} || []}) ]; | ||||||||||||||||||||
|
Condition75%3/4
$self->{'headers'} || []
$self->{'extra_headers'} || []
MC/DC0%0/1
$self->{'headers'} || []
$self->{'headers'}
MC/DC100%1/1
$self->{'extra_headers'} || []
$self->{'extra_headers'}
Truth table50%1/2
A
A= $self->{'headers'}
Truth table100%2/2
A
A= $self->{'extra_headers'}
| |||||||||||||||||||||||
| 39 | 9 | for my $elm (@{$self->{_all_headers}}) { | |||||||||||||||||||||
| 40 | 72 | $self->{_header_off}->{$elm} = $count++; | |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||
| 43 | $self->{data_table} = | ||||||||||||||||||||||
| 44 | Data::Tabular::Table::Data->new( | ||||||||||||||||||||||
| 45 | data => bless({ | ||||||||||||||||||||||
| 46 | headers => $self->{headers}, | ||||||||||||||||||||||
| 47 | rows => $self->{data}, | ||||||||||||||||||||||
| 48 | types => $self->{types}, | ||||||||||||||||||||||
| 49 | 9 | }, 'Data::Tabular::Data'), | |||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||
| 51 | $self->{extra_table} = | ||||||||||||||||||||||
| 52 | Data::Tabular::Table::Extra->new( | ||||||||||||||||||||||
| 53 | table => $self->{data_table}, | ||||||||||||||||||||||
| 54 | 9 | extra => $extra, | |||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||
| 56 | 9 | ▶ | $self->{group_by} ||= {}; | ||||||||||||||||||||
|
Condition100%2/2
$self->{"group_by"} ||= {}
MC/DC100%1/1
$self->{"group_by"} ||= {}
$self->{"group_by"}
Truth table100%2/2
A
A= $self->{"group_by"}
| |||||||||||||||||||||||
| 57 | 9 | ▶ | if (my $group_by = $self->{group_by}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 58 | 9 | ▶ | if (ref $group_by eq 'HASH') { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 59 | $self->{grouped_table} = Data::Tabular::Group->new( | ||||||||||||||||||||||
| 60 | table => $self->{extra_table}, | ||||||||||||||||||||||
| 61 | 9 | ▶ | title => $self->{title} || 1, | ||||||||||||||||||||
|
Condition50%1/2
$self->{'title'} || 1
MC/DC0%0/1
$self->{'title'} || 1
$self->{'title'}
Truth table50%1/2
A
A= $self->{'title'}
| |||||||||||||||||||||||
| 62 | %$group_by | ||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||
| 65 | 0 | die "group_by data must be a hash."; | |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||
| 68 | 0 | die "FIXME"; | |||||||||||||||||||||
| 69 | 0 | $self->{grouped_table} = $self->{extra_table}; | |||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||
| 71 | 7 | $self; | |||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | sub headers | ||||||||||||||||||||||
| 75 | 2 | ▶ | { | ||||||||||||||||||||
|
Subroutine
headers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 76 | 2 | my $self = shift; | |||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | 2 | $self->{extra_table}->headers; | |||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | sub output | ||||||||||||||||||||||
| 82 | 10 | ▶ | { | ||||||||||||||||||||
|
Subroutine
output: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||
| 83 | 10 | my $self = shift; | |||||||||||||||||||||
| 84 | 10 | ▶ | my $args = { %{$self->{output} || {}}, @_ }; | ||||||||||||||||||||
|
Condition100%2/2
$self->{'output'} || {}
MC/DC100%1/1
$self->{'output'} || {}
$self->{'output'}
Truth table100%2/2
A
A= $self->{'output'}
| |||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | my $output = Data::Tabular::Config::Output->new( | ||||||||||||||||||||||
| 87 | 10 | ▶ | headers => [ @{$self->{headers}}, | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 88 | 10 | $self->{extra_headers} ? @{$self->{extra_headers}} : keys %{$self->{extra}} ], | |||||||||||||||||||||
| 89 | %$args, | ||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||
| 91 | 10 | $output; | |||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | sub grouped | ||||||||||||||||||||||
| 95 | 9 | ▶ | { | ||||||||||||||||||||
|
Subroutine
grouped: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 96 | 9 | my $self = shift; | |||||||||||||||||||||
| 97 | |||||||||||||||||||||||
| 98 | 9 | $self->{grouped_table}; | |||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | sub extra_table | ||||||||||||||||||||||
| 102 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
extra_table: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 103 | 0 | my $self = shift; | |||||||||||||||||||||
| 104 | |||||||||||||||||||||||
| 105 | 0 | $self->{extra_table}; | |||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||
| 107 | |||||||||||||||||||||||
| 108 | sub data_table | ||||||||||||||||||||||
| 109 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
data_table: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 110 | 0 | my $self = shift; | |||||||||||||||||||||
| 111 | |||||||||||||||||||||||
| 112 | 0 | $self->{data_table}; | |||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | sub html | ||||||||||||||||||||||
| 116 | 2 | ▶ | { | ||||||||||||||||||||
|
Subroutine
html: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 117 | 2 | my $self = shift; | |||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | 2 | require Data::Tabular::Output::HTML; | |||||||||||||||||||||
| 120 | |||||||||||||||||||||||
| 121 | 2 | return Data::Tabular::Output::HTML->new( | |||||||||||||||||||||
| 122 | table => $self->grouped, | ||||||||||||||||||||||
| 123 | output => $self->output, | ||||||||||||||||||||||
| 124 | @_, | ||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||
| 127 | |||||||||||||||||||||||
| 128 | sub xls | ||||||||||||||||||||||
| 129 | 3 | ▶ | { | ||||||||||||||||||||
|
Subroutine
xls: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 130 | 3 | my $self = shift; | |||||||||||||||||||||
| 131 | 3 | require Data::Tabular::Output::XLS; | |||||||||||||||||||||
| 132 | |||||||||||||||||||||||
| 133 | 3 | return Data::Tabular::Output::XLS->new( | |||||||||||||||||||||
| 134 | table => $self->grouped, | ||||||||||||||||||||||
| 135 | output => $self->output, | ||||||||||||||||||||||
| 136 | @_, | ||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||
| 139 | |||||||||||||||||||||||
| 140 | sub txt | ||||||||||||||||||||||
| 141 | 3 | ▶ | { | ||||||||||||||||||||
|
Subroutine
txt: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 142 | 3 | my $self = shift; | |||||||||||||||||||||
| 143 | 3 | require Data::Tabular::Output::TXT; | |||||||||||||||||||||
| 144 | |||||||||||||||||||||||
| 145 | 3 | return Data::Tabular::Output::TXT->new( | |||||||||||||||||||||
| 146 | table => $self->grouped, | ||||||||||||||||||||||
| 147 | output => $self->output, | ||||||||||||||||||||||
| 148 | @_, | ||||||||||||||||||||||
| 149 | ); | ||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||
| 151 | |||||||||||||||||||||||
| 152 | sub csv | ||||||||||||||||||||||
| 153 | 1 | ▶ | { | ||||||||||||||||||||
|
Subroutine
csv: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 154 | 1 | my $self = shift; | |||||||||||||||||||||
| 155 | 1 | require Data::Tabular::Output::CSV; | |||||||||||||||||||||
| 156 | |||||||||||||||||||||||
| 157 | 1 | return Data::Tabular::Output::CSV->new( | |||||||||||||||||||||
| 158 | table => $self->grouped, | ||||||||||||||||||||||
| 159 | output => $self->output, | ||||||||||||||||||||||
| 160 | @_, | ||||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||
| 163 | |||||||||||||||||||||||
| 164 | 8 | 1; | |||||||||||||||||||||
| 165 | __END__ | ||||||||||||||||||||||