Tabular/Table/Extra.pm

filter: Statementstmt 37.1% 26 / 70 Branchbran 0.0% 0 / 16 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 8 / 12 Podpod 77.7% 7 / 9 totaltotal 36.1% 43 / 119 CC 14 SCAR 27.6
CC
14
Cov
30%
extra_column
42.0
header_offset
20.0
all_headers
12.0
CRAP 15.8
« Tabular/Output/XLS.pm ↑ Summary Tabular/Row/Function.pm »
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::Extra;
6  
7 8 ▶use base 'Data::Tabular::Table::Data';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 ▶use Carp qw (croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub new
12 18 ▶{
Subroutine new: called CC=3 SCAR=11.2
Pod documented
13 18 my $caller = shift;
14 18 my $self = $caller->SUPER::new(@_);
15  
16 18 ▶ $self->{_all_headers} = [ (@{$self->{data}->{headers} || []}, sort keys(%{$self->extra->{columns} || {}})) ];
Condition50%2/4
$self->{'data'}{'headers'} || []
l!l
180
$self->extra->{'columns'} || {}
l!l
180
MC/DC0%0/1
$self->{'data'}{'headers'} || []
$self->{'data'}{'headers'}
MC/DC0%0/1
$self->extra->{'columns'} || {}
$self->extra->{'columns'}
Truth table50%1/2
A
A= $self->{'data'}{'headers'}
Aresult
11
00
Truth table50%1/2
A
A= $self->extra->{'columns'}
Aresult
11
00
17  
18 18 $self;
19 }
20  
21 sub extra
22 1831 ▶{
Subroutine extra: called CC=1 SCAR=0.0
Pod undocumented
23 1831 my $self = shift;
24  
25 1831 $self->{extra};
26 }
27  
28 sub is_extra
29 1813 ▶{
Subroutine is_extra: called CC=1 SCAR=0.0
Pod documented
30 1813 my $self = shift;
31 1813 my $column_name = shift;
32  
33 1813 exists $self->extra->{columns}->{$column_name};
34 }
35  
36 sub headers
37 554 ▶{
Subroutine headers: called CC=1 SCAR=0.0
Pod documented
38 554 my $self = shift;
39  
40 554 @{$self->{_all_headers}};
41 }
42  
43 sub all_headers
44 0 ▶{
Subroutine all_headers: not called CC=3 SCAR=24.8
Pod documented
45 0 my $self = shift;
46  
47 0 ▶ $self->{_all_headers} = [ (@{$self->{data}->{headers} || []}, sort keys(%{$self->extra->{columns} || {}})) ];
Condition0%0/4
$self->{'data'}{'headers'} || []
l!l
00
$self->extra->{'columns'} || {}
l!l
00
MC/DC0%0/1
$self->{'data'}{'headers'} || []
$self->{'data'}{'headers'}
MC/DC0%0/1
$self->extra->{'columns'} || {}
$self->extra->{'columns'}
Truth table0%0/2
A
A= $self->{'data'}{'headers'}
Aresult
11
00
Truth table0%0/2
A
A= $self->extra->{'columns'}
Aresult
11
00
48  
49 0 @{$self->{_all_headers}};
50 }
51  
52 sub row_package
53 97 ▶{
Subroutine row_package: called CC=1 SCAR=0.0
Pod documented
54 97 require Data::Tabular::Row::Extra;
55 97 'Data::Tabular::Row::Extra';
56 }
57  
58 sub header_offset
59 0 ▶{
Subroutine header_offset: not called CC=4 SCAR=30.0
Pod documented
60 0 die;
61 0 my $self = shift;
62 0 my $column = shift;
63 0 my $count = 0;
64 0 ▶ unless ($self->{_header_off}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_header_off"}) 0 0 0
65 0 for my $header ($self->headers) {
66 0 $self->{_header_off}->{$header} = $count++;
67 }
68 }
69 0 my $ret = $self->{_header_off}->{$column};
70 croak "column '$column' not found in [",
71 join(" ",
72 0 ▶ sort keys(%{$self->{_header_off}})
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret 0 0 0
73 ), ']' unless defined $ret;
74 0 $ret;
75 }
76  
77 sub get_row_column
78 0 ▶{
Subroutine get_row_column: not called CC=2 SCAR=17.9
Pod documented
79 0 my $self = shift;
80 0 my $row = shift;
81 0 my $column = shift;
82 0 my $count = scalar(@{$self->{data}->{headers}});
83  
84 0 ▶ if ($column >= $count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($column >= $count) { } 0 0 0
85 0 die 'column out of range';
86 } else {
87 0 $self->{data}->{rows}->[$row][$column];
88 }
89 }
90  
91 sub extra_column
92 0 ▶{
Subroutine extra_column: not called CC=6 SCAR=37.4
Pod undocumented
93 0 my $self = shift;
94 0 my $row = shift;
95 0 my $key = shift;
96 0 my $ret = 'N/A';
97 0 die;
98 0 my $extra = $self->{extra};
99  
100 0 ▶ return undef unless $row;
Branch: 1 branch
BranchTrueFalseTotal
unless $row 0 0 0
101  
102 0 my $offset = $self->header_offset($key);
103  
104 0 my $x = $self->extra_package->new(row => $row, table => $self);
105  
106 0 ▶ if (ref($extra->{$key}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $extra->{$key} eq 'CODE') { } 0 0 0
107 0 eval {
108 0 $ret = $extra->{$key}->($x);
109 };
110 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
111 0 die $@;
112 }
113 } else {
114 0 die 'only know how to deal with code';
115 }
116 0 die $ret;
117 0 ▶ if (ref($ret)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ret) 0 0 0
118 0 ▶ die if (ref($ret) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $ret eq "HASH" 0 0 0
119 }
120  
121 0 $ret;
122 }
123  
124 8 1;
125 __END__
« Tabular/Output/XLS.pm ↑ Summary Tabular/Row/Function.pm »