Tabular/Group.pm

filter: Statementstmt 72.5% 66 / 91 Branchbran 73.0% 19 / 26 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 66.6% 12 / 18 Podpod 30.0% 3 / 10 totaltotal 65.3% 100 / 153 CC 18 SCAR 16.5
CC
18
Cov
70%
clone
12.0
group_it
12.0
_doit
7.1
CRAP 5.2
« Tabular/Table/Group.pm ↑ Summary Tabular/Row/Extra.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
5 package
6 Data::Tabular::Group;
7  
8 8 ▶use base 'Data::Tabular::Table::Extra';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 ▶use Data::Tabular::Table::Group;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 8 ▶use Carp qw (croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub clone
15 0 ▶{
Subroutine clone: not called CC=3 SCAR=24.8
Pod undocumented
16 0 my $caller = shift;
17 0 ▶ my $self = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
18 0 my $class = ref($caller);
19 0 for my $key (keys %$caller) {
20 0 $self->{$key} = $caller->{$key};
21 }
22 0 bless $self, $class;
23 }
24  
25 sub new
26 9 ▶{
Subroutine new: called CC=6 SCAR=17.9
Pod documented
27 9 my $caller = shift;
28  
29 9 my $self = $caller->SUPER::new(@_);
30  
31 9 ▶ if ($self->{groups}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'groups'}) { } 7 2 9
32 7 my @groups = @{$self->{groups}};
33 7 my $group = shift @groups;
34 7 ▶ die 'No column required for first group.' if $group->{column};
Branch: 1 branch
BranchTrueFalseTotal
if $group->{"column"} 1 6 7
35 6 my $x = 2;
36 6 for my $group (@groups) {
37 6 ▶ die "Need column for group $x" unless $group->{column};
Branch: 1 branch
BranchTrueFalseTotal
unless $group->{"column"} 1 5 6
38 5 $x++;
39 }
40 } else {
41 2 ▶ die q|Columns are gone!| if $self->{columns};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"columns"} 0 2 2
42 $self->{groups} = [
43 {
44 4 ▶ pre => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
45 4 my $self = shift;
46 4 ( $self->titles( class => 'xgam3x' ) );
47 }
48 }
49 2 ];
50 }
51  
52 # die 'Group needs a table' unless $self->table;
53 # die 'table must be a Data::Tabular::Output object.' unless $self->table->isa('Data::Tabular::Output');
54  
55 7 $self;
56 }
57  
58 sub sum_list
59 0 ▶{
Subroutine sum_list: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my $self = shift;
61 0 @{$self->{sum}};
62 }
63  
64 sub compare
65 94 ▶{
Subroutine compare: called CC=1 SCAR=0.0
Pod undocumented
66 94 my $self = shift;
67 94 my $first = shift;
68 94 my $row = shift;
69 94 my $key = shift;
70  
71 94 $first->get_column($key)->string ne $row->get_column($key)->string;
72 }
73  
74 sub _doit
75 91 ▶{
Subroutine _doit: called CC=7 SCAR=19.5
76 91 my $self = shift;
77 91 my $level = shift;
78  
79 91 ▶ if ($level < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level < 0) 0 91 91
80 0 return( @_ );
81 }
82 91 ▶ if ($level > $self->max_level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level > $self->max_level) 35 56 91
83 35 return( @_ );
84 }
85 56 my @sections = @_;
86  
87 56 my $first = shift @sections;
88  
89 56 my @inp = ();
90  
91 56 ▶ while (my $row = shift @sections) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = shift @sections) 155 33 188
92 155 ▶ for (my $x = 1; $x <= $level; $x++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x <= $level) 94 132 226
93 94 ▶ die 'Need column' unless $self->{groups}->[$x]->{column};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"groups"}[$x]{"column"} 0 94 94
94 94 ▶ if ($self->compare($first, $row, $self->{groups}->[$x]->{column})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->compare($first, $row, $self->{"groups"}[$x]{"column"})) 23 71 94
95 23 return ( $self->_do_group($level, $self->_doit($level+1, $first, @inp)),
96 $self->_doit($level, $row, @sections)
97 );
98 }
99 }
100 132 push(@inp, $row);
101 }
102 33 return($self->_do_group($level, $self->_doit($level + 1, $first, @inp)));
103 }
104  
105 sub max_level
106 91 ▶{
Subroutine max_level: called CC=2 SCAR=7.0
Pod undocumented
107 91 my $self = shift;
108 91 ▶ die 'no groups' unless(scalar(@{$self->{groups}}) - 1 >= 0);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar(@{$self->{"groups"};}) - 1 >= 0 0 91 91
109 91 scalar(@{$self->{groups}}) - 1;
110 }
111  
112 sub data
113 0 ▶{
Subroutine data: not called CC=1 SCAR=6.9
Pod undocumented
114 0 my $self = shift;
115 0 $self->{data};
116 }
117  
118 sub _columns
119 0 ▶{
Subroutine _columns: not called CC=1 SCAR=6.9
120 0 my $self = shift;
121 0 $self->table->columns;
122 }
123  
124 sub row_count
125 1 ▶{
Subroutine row_count: called CC=2 SCAR=7.2
Pod documented
126 1 my $self = shift;
127  
128 1 ▶ $self->{row_count} || die "row_count is not available until after rows is called.";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"row_count"} or die "row_count is not available until after rows is called." 1 0 1
129 }
130  
131 sub rows
132 12 ▶{
Subroutine rows: called CC=1 SCAR=0.0
Pod documented
133 12 my $self = shift;
134 12 my $args = { @_ };
135  
136 12 my $ret = $self->_doit(0, $self->SUPER::rows(@_));
137  
138 12 my @rows = $ret->rows(@_);
139 12 $self->{row_count} = scalar(@rows);
140 12 @rows;
141 }
142  
143 sub group_it
144 0 ▶{
Subroutine group_it: not called CC=3 SCAR=24.8
Pod undocumented
145 0 my $self = shift;
146 0 my $data = shift; # Data::Tabular::Output;
147  
148 0 my $ret;
149 0 my $grouped = $self->{grouped};
150 0 ▶ unless ($self->{grouped} && $self->data eq $data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"grouped"} and $self->data eq $data) 0 0 0
Condition0%0/3
$self->{"grouped"} and $self->data eq $data
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"grouped"} and $self->data eq $data
$self->{"grouped"} $self->data eq $data
Truth table0%0/3
A and B
A= $self->{"grouped"}B= $self->data eq $data
ABresult
0X0
100
111
151 0 $grouped = $self->new(data => $data);
152 0 $ret = $grouped->_do_group(0, $self->_doit($self->max_level, $data->rows));
153 0 $grouped->{grouped} = $ret;
154 }
155 0 $grouped;
156 }
157  
158 sub _do_group
159 56 ▶{
Subroutine _do_group: called CC=1 SCAR=0.0
160 56 my $self = shift;
161 56 my $level = shift;
162  
163 56 my $ret = Data::Tabular::Table::Group->new(data => [ @_ ], level => $level, group => $self);
164 56 ($ret);
165 }
166  
167 sub table
168 0 ▶{
Subroutine table: not called CC=1 SCAR=6.9
Pod undocumented
169 0 my $self = shift;
170 0 $self->{table};
171 }
172  
173 8 1;
174 __END__
« Tabular/Table/Group.pm ↑ Summary Tabular/Row/Extra.pm »