| 1 | package Script::Toolbox::Util::Formatter; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 21 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 21 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | #use Script::Toolbox::Util qw(Log); | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 21 | require Exporter; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 21 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 10 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||||
| 11 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||||
| 12 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||||
| 13 | 21 | @EXPORT = qw( | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Preloaded methods go here. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 21 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 22 | sub new | ||||||||||||||||||||||||||||
| 23 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 10 | my $classname = shift; | |||||||||||||||||||||||||||
| 25 | 10 | my $self = {}; | |||||||||||||||||||||||||||
| 26 | 10 | bless( $self, $classname ); | |||||||||||||||||||||||||||
| 27 | 10 | $self->_init( @_ ); | |||||||||||||||||||||||||||
| 28 | 10 | return $self; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 32 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 33 | sub _init | ||||||||||||||||||||||||||||
| 34 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 35 | 10 | my ($self, $container) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | $self->{'title'}= defined $container->{'title'} ? | ||||||||||||||||||||||||||||
| 38 | 10 | ▶ | $container->{'title'} : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 'Title'; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 10 | ▶ | if( ref $container->{'data'} eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 9 | ▶ | $self->_initHashArray ( $container ) if( ref $container->{'data'}[0] eq 'HASH' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 9 | ▶ | $self->_initArray ( $container ) if( ref $container->{'data'}[0] eq 'ARRAY'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 10 | ▶ | if( ref $container->{'data'} eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | $self->_initHashHash ( $container ) if( ref $container->{'data'} eq 'HASH' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | $self->{'head'} = defined $container->{'head'} ? | ||||||||||||||||||||||||||||
| 51 | 10 | ▶ | $container->{'head'} : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | _getDefaultHeader($container); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 58 | # Extract column keys from first data row. | ||||||||||||||||||||||||||||
| 59 | # 'data' => { | ||||||||||||||||||||||||||||
| 60 | # key1 => {F1=>'aaa', F2=>'bb ', F3=>3} | ||||||||||||||||||||||||||||
| 61 | # key2 => {F1=>11111, F2=>2222222, F3=>3} | ||||||||||||||||||||||||||||
| 62 | # } | ||||||||||||||||||||||||||||
| 63 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 64 | sub _getHeadsFromFirstRow($) | ||||||||||||||||||||||||||||
| 65 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getHeadsFromFirstRow: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 66 | 1 | my ($data) = @_; | |||||||||||||||||||||||||||
| 67 | 1 | my @H; | |||||||||||||||||||||||||||
| 68 | 1 | push( @H, "KEY" ); | |||||||||||||||||||||||||||
| 69 | 1 | foreach my $d ( values %{$data} ) | |||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 1 | map{ push( @H, $_ ) } sort keys %{$d}; | |||||||||||||||||||||||||||
| 72 | 1 | last; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | #return \@H; | ||||||||||||||||||||||||||||
| 75 | 1 | return @H; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 79 | # 'title' => 'Test1', | ||||||||||||||||||||||||||||
| 80 | # 'head' => ['RowKey', Field1', 'Field2', 'Field3'], | ||||||||||||||||||||||||||||
| 81 | # 'data' => { | ||||||||||||||||||||||||||||
| 82 | # key1 => {F1=>'aaa', F2=>'bb ', F3=>3} | ||||||||||||||||||||||||||||
| 83 | # key2 => {F1=>11111, F2=>2222222, F3=>3} | ||||||||||||||||||||||||||||
| 84 | # } | ||||||||||||||||||||||||||||
| 85 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 86 | sub _initHashHash($$) | ||||||||||||||||||||||||||||
| 87 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_initHashHash: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 88 | 1 | my ($self,$container) = @_; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1 | ▶ | if( ref $container->{'data'} eq 'HASH' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||
| 92 | 1 | @{$self->{'head'}} = _getHeadsFromFirstRow( $container->{'data'} ); | |||||||||||||||||||||||||||
| 93 | 1 | my @D; | |||||||||||||||||||||||||||
| 94 | 1 | foreach my $lk ( sort keys %{$container->{'data'}} ) | |||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||
| 96 | 2 | my $l = $container->{'data'}{$lk}; | |||||||||||||||||||||||||||
| 97 | 2 | my @L; | |||||||||||||||||||||||||||
| 98 | 2 | foreach my $k ( @{$self->{'head'}} ) | |||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||
| 100 | # auto generated meta column | ||||||||||||||||||||||||||||
| 101 | 8 | ▶ | if( $k eq 'KEY' ) { push @L,$lk; next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 6 | ▶ | $self->_logit( $k, $l ) if( !defined $l->{$k} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 6 | push @L, $l->{$k}; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 2 | push @D, \@L; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 1 | $self->{data} = \@D; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 113 | # 'title' => 'Test1', | ||||||||||||||||||||||||||||
| 114 | # 'head' => ['Feld1', 'Feld2', 'Feld3'], | ||||||||||||||||||||||||||||
| 115 | # 'data' => [ | ||||||||||||||||||||||||||||
| 116 | # [ 'aaa', 'bb ', 'cc ' ], | ||||||||||||||||||||||||||||
| 117 | # [ 11111, 2222222, 3 ] | ||||||||||||||||||||||||||||
| 118 | # ] | ||||||||||||||||||||||||||||
| 119 | # OR data part | ||||||||||||||||||||||||||||
| 120 | # 'data' => [ | ||||||||||||||||||||||||||||
| 121 | # {F1=>'aaa', F2=>'bb ', F3=>3} | ||||||||||||||||||||||||||||
| 122 | # {F1=>11111, F2=>2222222, F3=>3} | ||||||||||||||||||||||||||||
| 123 | # ] | ||||||||||||||||||||||||||||
| 124 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 125 | sub _initHashArray($$) | ||||||||||||||||||||||||||||
| 126 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_initHashArray: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 127 | 1 | my ($self,$container) = @_; | |||||||||||||||||||||||||||
| 128 | 1 | $self->{'data'} = $self->_getData($container); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 132 | # [ | ||||||||||||||||||||||||||||
| 133 | # 'title', | ||||||||||||||||||||||||||||
| 134 | # ['COL-HEAD','COL-HEAD2','COL-HEAD3'], | ||||||||||||||||||||||||||||
| 135 | # [1, 2, 3], | ||||||||||||||||||||||||||||
| 136 | # [4, 5, 6], | ||||||||||||||||||||||||||||
| 137 | # ] | ||||||||||||||||||||||||||||
| 138 | # OR: | ||||||||||||||||||||||||||||
| 139 | # [ | ||||||||||||||||||||||||||||
| 140 | # [1, 2, 3], | ||||||||||||||||||||||||||||
| 141 | # [4, 5, 6], | ||||||||||||||||||||||||||||
| 142 | # ] | ||||||||||||||||||||||||||||
| 143 | # OR: | ||||||||||||||||||||||||||||
| 144 | # 'data' => [ | ||||||||||||||||||||||||||||
| 145 | # {F1=>'aaa', F2=>'bb ', F3=>3} | ||||||||||||||||||||||||||||
| 146 | # {F1=>11111, F2=>2222222, F3=>3} | ||||||||||||||||||||||||||||
| 147 | # ] | ||||||||||||||||||||||||||||
| 148 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 149 | sub _initArray($$) | ||||||||||||||||||||||||||||
| 150 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_initArray: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 151 | 7 | my ($self,$container) = @_; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 7 | $self->{'data'} = $container->{'data'}; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 157 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 158 | sub _getData($$) | ||||||||||||||||||||||||||||
| 159 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getData: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||
| 160 | 1 | my ($self, $container) = @_; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 1 | ▶ | return [] if( !defined $container->{'data'}[0] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 1 | ▶ | return $container if( ref($container->{'data'}[0]) eq 'ARRAY' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 1 | ▶ | if( ref($container->{'data'}[0]) eq 'HASH' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||
| 166 | 1 | @{$self->{'head'}} = sort keys %{$container->{'data'}[0]}; | |||||||||||||||||||||||||||
| 167 | 1 | my @D; | |||||||||||||||||||||||||||
| 168 | 1 | foreach my $l ( @{$container->{'data'}} ) | |||||||||||||||||||||||||||
| 169 | { | ||||||||||||||||||||||||||||
| 170 | 2 | my @L; | |||||||||||||||||||||||||||
| 171 | 2 | foreach my $k ( @{$self->{'head'}} ) | |||||||||||||||||||||||||||
| 172 | { | ||||||||||||||||||||||||||||
| 173 | 6 | ▶ | $self->_logit( $k, $l ) if( !defined $l->{$k} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 6 | push @L, $l->{$k}; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | 2 | push @D, \@L; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | 1 | return \@D; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 183 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 184 | sub _logit($$) | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_logit: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 186 | 0 | my ($self,$k,$line) = @_; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | print STDERR | ||||||||||||||||||||||||||||
| 189 | "Warning: inconsistent data hash, missing key $k in line: " . | ||||||||||||||||||||||||||||
| 190 | 0 | join ";", each %{$line}; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 193 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 194 | sub _getDefaultHeader($) | ||||||||||||||||||||||||||||
| 195 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getDefaultHeader: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 196 | 6 | my ($cont) = @_; | |||||||||||||||||||||||||||
| 197 | 6 | my @hd; | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 6 | ▶ | if( ref $cont->{'data'} eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 5 | ▶ | if( ref $cont->{'data'}[0] eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 1 | foreach my $h ( sort keys %{$cont->{'data'}[0]} ) { push @hd, $h; } | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | 5 | ▶ | if( ref $cont->{'data'}[0] eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 4 | ▶ | for( my $i=0; $i <= $#{$cont->{'data'}[0]}; $i++ ) { push @hd, "Col-$i"; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # 'data' => { | ||||||||||||||||||||||||||||
| 209 | # 'line1' => { 'F1' => 'aaaa', 'F2' => 'bbb ', 'F3' => 'c' }, | ||||||||||||||||||||||||||||
| 210 | # 'line2' => { 'F1' => 'dddd', 'F2' => 'eee ', 'F3' => 'f' } | ||||||||||||||||||||||||||||
| 211 | # } | ||||||||||||||||||||||||||||
| 212 | 6 | ▶ | if( ref $cont->{'data'} eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 1 | foreach my $line ( values %{$cont->{'data'}} ) | |||||||||||||||||||||||||||
| 214 | { | ||||||||||||||||||||||||||||
| 215 | 1 | push @hd, "KEY"; | |||||||||||||||||||||||||||
| 216 | 1 | foreach my $fldName ( sort keys %{$line} ) | |||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||
| 218 | 3 | push @hd, $fldName; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | 1 | last; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 6 | return \@hd; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 228 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 229 | sub matrix | ||||||||||||||||||||||||||||
| 230 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
matrix: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 231 | 10 | my ($self) = @_; | |||||||||||||||||||||||||||
| 232 | 10 | ▶ | return [] if( !defined $self->{'data'} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 9 | ▶ | return [] if( scalar @{$self->{'data'}} == 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 9 | my @result; | |||||||||||||||||||||||||||
| 236 | 9 | $self->_matrix( \@result ); | |||||||||||||||||||||||||||
| 237 | 9 | return \@result ; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 241 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 242 | sub _matrix | ||||||||||||||||||||||||||||
| 243 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_matrix: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 244 | 9 | my ($self, $result) = @_; | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 9 | my @maxColW = $self->_maxColWidth(); | |||||||||||||||||||||||||||
| 247 | 9 | my $format = $self->_getFormat( \@maxColW ); | |||||||||||||||||||||||||||
| 248 | 9 | my $formatHd= $format; | |||||||||||||||||||||||||||
| 249 | 9 | $formatHd=~ s/([.]\d*)?[df]/s/g; | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 9 | push @{$result}, sprintf "== %s ==", $self->{'title'}; | |||||||||||||||||||||||||||
| 252 | 9 | push @{$result}, sprintf $formatHd, @{$self->{'head'}}; | |||||||||||||||||||||||||||
| 253 | 9 | push @{$result}, _underline( @maxColW ); | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 24 | map { push @{$result}, | |||||||||||||||||||||||||||
| 256 | 9 | sprintf $format, _getLineArray($_); } @{$self->{'data'}}; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 260 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 261 | sub _underline | ||||||||||||||||||||||||||||
| 262 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_underline: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 263 | 9 | my (@maxColWidth) = @_; | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 9 | my $x; | |||||||||||||||||||||||||||
| 266 | 9 | map { $_ =~s/([.]\d+)?[fds]$//; | |||||||||||||||||||||||||||
| 267 | 28 | $_ =~s/-//; | |||||||||||||||||||||||||||
| 268 | 28 | $x .= sprintf "%s ", '-' x $_ } @maxColWidth; | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 9 | $x =~ s/\s$//; | |||||||||||||||||||||||||||
| 271 | 9 | return $x; | |||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 274 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 275 | sub _getLineArray | ||||||||||||||||||||||||||||
| 276 | 24 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getLineArray: called CC=4 SCAR=22.9
| |||||||||||||||||||||||||||||
| 277 | 24 | my ($line) = @_; | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 24 | ▶ | return @{$line} if( ref $line eq 'ARRAY' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if( ref $line eq 'HASH' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||
| 283 | 0 | my @R; | |||||||||||||||||||||||||||
| 284 | 0 | foreach my $key ( sort keys %{$line} ) { | |||||||||||||||||||||||||||
| 285 | 0 | push @R, ${$line}{$key}; | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | 0 | return @R; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 292 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 293 | sub _getFormat | ||||||||||||||||||||||||||||
| 294 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getFormat: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 295 | 9 | my ($self, $maxColWidth ) = @_; | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 9 | my $form=''; | |||||||||||||||||||||||||||
| 298 | 9 | _mkFloatLen( $maxColWidth ); | |||||||||||||||||||||||||||
| 299 | 9 | foreach my $f ( @{$maxColWidth} ) | |||||||||||||||||||||||||||
| 300 | { | ||||||||||||||||||||||||||||
| 301 | 28 | ▶ | $f = '-' . $f if( $f =~ /s$/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 302 | 28 | $form .= sprintf "%%%s ", $f; | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | 9 | $form =~ s/\s$//; | |||||||||||||||||||||||||||
| 305 | 9 | return $form; | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 309 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 310 | sub _mkFloatLen($) | ||||||||||||||||||||||||||||
| 311 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_mkFloatLen: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 312 | 9 | my ($maxColRef) = @_; | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 9 | ▶ | for( my $i=@{$maxColRef}-1; $i >= 0; $i-- ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | { | ||||||||||||||||||||||||||||
| 316 | 28 | ▶ | if( ${$maxColRef}[$i] =~ /(\d+)[.](\d+)f$/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | { | ||||||||||||||||||||||||||||
| 318 | 6 | my $len = $1; | |||||||||||||||||||||||||||
| 319 | 6 | my $dig = $2; | |||||||||||||||||||||||||||
| 320 | 6 | ${$maxColRef}[$i] = $len+$dig+1 .'.'. $dig .'f'; | |||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 326 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 327 | sub _maxColWidth | ||||||||||||||||||||||||||||
| 328 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_maxColWidth: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||
| 329 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||
| 330 | 9 | my @maxColWidth; | |||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | my @X; | ||||||||||||||||||||||||||||
| 333 | 9 | push @X, $self->{'head'}; | |||||||||||||||||||||||||||
| 334 | 9 | map { push @X, $_ } @{$self->{'data'}}; | |||||||||||||||||||||||||||
| 335 | 9 | my $i=0; | |||||||||||||||||||||||||||
| 336 | 9 | foreach my $line ( @X ) | |||||||||||||||||||||||||||
| 337 | { | ||||||||||||||||||||||||||||
| 338 | 33 | ▶ | next if( $i++ == 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 24 | ▶ | _maxColHashLine( $line, \@maxColWidth ) if( ref $line eq 'HASH' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 24 | ▶ | _maxColArrayLine($line, \@maxColWidth ) if( ref $line eq 'ARRAY'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | 9 | _checkMaxHeader( $X[0], \@maxColWidth ); | |||||||||||||||||||||||||||
| 343 | 9 | return @maxColWidth; | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 347 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 348 | sub _checkMaxHeader($$) | ||||||||||||||||||||||||||||
| 349 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_checkMaxHeader: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 350 | 9 | my ($line, $maxColWidth) = @_; | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 9 | ▶ | for( my $i=0; $i<= $#{$line}; $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||
| 354 | 28 | _trimBlanks( \${$line}[$i] ); | |||||||||||||||||||||||||||
| 355 | 28 | ${$maxColWidth}[$i] = _getMaxColWidthHead(${$maxColWidth}[$i], | |||||||||||||||||||||||||||
| 356 | 28 | ${$line}[$i] ); | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 361 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 362 | sub _getMaxColWidthHead($$) | ||||||||||||||||||||||||||||
| 363 | 28 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getMaxColWidthHead: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||
| 364 | 28 | my ($old,$new) = @_; | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 28 | my $nl= length( $new ); | |||||||||||||||||||||||||||
| 367 | 28 | $old =~ /(\d+)[.]?(\d*)([fds])/; my ($ol,$od, $ot) = ($1,$2,$3); | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 28 | ▶ | return stringType($nl,$ol) if($ot eq 's' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 12 | ▶ | return floatType($nl,0,$ol,$od) if($ot eq 'f'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | 6 | ▶ | return intType($nl,$ol) if($ot eq 'd' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 0 | printf STDERR "ERROR format\n"; | |||||||||||||||||||||||||||
| 374 | 0 | return 0; | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 379 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 380 | sub _maxColArrayLine | ||||||||||||||||||||||||||||
| 381 | 24 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_maxColArrayLine: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 382 | 24 | my ($line, $maxColWidth) = @_; | |||||||||||||||||||||||||||
| 383 | 24 | ▶ | for( my $i=0; $i<= $#{$line}; $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 384 | { | ||||||||||||||||||||||||||||
| 385 | 74 | _trimBlanks( \${$line}[$i] ); | |||||||||||||||||||||||||||
| 386 | 74 | my $type= _getTypeLen( ${$line}[$i] ); | |||||||||||||||||||||||||||
| 387 | 74 | ${$maxColWidth}[$i] = _getMaxColWidth(${$maxColWidth}[$i], $type); | |||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 392 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 393 | sub _getMaxColWidth($$) | ||||||||||||||||||||||||||||
| 394 | 74 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getMaxColWidth: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||
| 395 | 74 | my ($old,$new) = @_; | |||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 74 | $new =~ /(\d+)[.]?(\d*)([fds])/; my ($nl,$nd, $nt) = ($1,$2,$3); | |||||||||||||||||||||||||||
| 398 | 74 | ▶ | $old = $new if( !defined $old ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 74 | $old =~ /(\d+)[.]?(\d*)([fds])/; my ($ol,$od, $ot) = ($1,$2,$3); | |||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 74 | ▶ | return stringType($nl,$ol) if($nt eq 's' || $ot eq 's' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$nt eq "s" or $ot eq "s"
MC/DC100%2/2
$nt eq "s" or $ot eq "s"
$nt eq "s"
$ot eq "s"
Truth table100%3/3
A or B
A= $nt eq "s"B= $ot eq "s"
| |||||||||||||||||||||||||||||
| 402 | 36 | ▶ | return floatType($nl,$nd,$ol,$od) if($nt eq 'f' || $ot eq 'f'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$nt eq "f" or $ot eq "f"
MC/DC100%2/2
$nt eq "f" or $ot eq "f"
$nt eq "f"
$ot eq "f"
Truth table100%3/3
A or B
A= $nt eq "f"B= $ot eq "f"
| |||||||||||||||||||||||||||||
| 403 | 24 | ▶ | return intType($nl,$ol) if($nt eq 'd' && $ot eq 'd' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$nt eq "d" and $ot eq "d"
MC/DC0%0/2
$nt eq "d" and $ot eq "d"
$nt eq "d"
$ot eq "d"
Truth table33%1/3
A and B
A= $nt eq "d"B= $ot eq "d"
| |||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 0 | printf STDERR "ERROR format\n"; | |||||||||||||||||||||||||||
| 406 | 0 | return 0; | |||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 410 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 411 | sub intType($$) | ||||||||||||||||||||||||||||
| 412 | 30 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
intType: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 413 | 30 | my ($nl,$ol) = @_; | |||||||||||||||||||||||||||
| 414 | 30 | ▶ | my $len = $nl > $ol ? $nl : $ol; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | 30 | return $len . 'd'; | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 418 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 419 | sub floatType($$$$$$) | ||||||||||||||||||||||||||||
| 420 | 18 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
floatType: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 421 | 18 | my ($nl,$nd,$ol,$od) = @_; | |||||||||||||||||||||||||||
| 422 | 18 | ▶ | $nl = $nl eq '' ? 0 : $nl; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 423 | 18 | ▶ | $nd = $nd eq '' ? 0 : $nd; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 424 | 18 | ▶ | $od = $od eq '' ? 0 : $od; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | 18 | ▶ | $ol = $ol eq '' ? 0 : $ol; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 426 | 18 | ▶ | my $len = $nl > $ol ? $nl : $ol; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | 18 | ▶ | my $dig = $nd > $od ? $nd : $od; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 18 | return $len .'.'. $dig .'f'; | |||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 433 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 434 | sub stringType($$) | ||||||||||||||||||||||||||||
| 435 | 54 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
stringType: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 436 | 54 | my ($nl,$ol) = @_; | |||||||||||||||||||||||||||
| 437 | 54 | ▶ | my $len = $nl > $ol ? $nl : $ol; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 54 | return $len .'s'; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 443 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 444 | sub _getTypeLen($) | ||||||||||||||||||||||||||||
| 445 | 74 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getTypeLen: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 446 | 74 | my ($field) = @_; | |||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | 74 | my $type; | |||||||||||||||||||||||||||
| 449 | 74 | ▶ | $type = _isFloat($field); return $type if( defined $type ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 450 | 68 | ▶ | $type = _isInt($field); return $type if( defined $type ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | 29 | return length($field) .'s'; | |||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 456 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 457 | sub _isInt($) | ||||||||||||||||||||||||||||
| 458 | 68 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_isInt: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 459 | 68 | my ($field) = @_; | |||||||||||||||||||||||||||
| 460 | 68 | ▶ | return undef if( $field !~ /^[-]?\d+$/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 461 | 39 | return length($field) .'d'; | |||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 465 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 466 | sub _isFloat($) | ||||||||||||||||||||||||||||
| 467 | 74 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_isFloat: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 468 | 74 | my ($field) = @_; | |||||||||||||||||||||||||||
| 469 | 74 | ▶ | return undef if( $field !~ /^[-]?(\d+)[.](\d*)$/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 6 | my $int = $1; my $li = length($int); | |||||||||||||||||||||||||||
| 472 | 6 | my $frac= $2; my $lf = length($frac); | |||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | 6 | my $form= $li+$lf+1 .'.'. $lf .'f'; | |||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | 6 | return $form; | |||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||
| 478 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 479 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 480 | sub _maxColHashLine | ||||||||||||||||||||||||||||
| 481 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_maxColHashLine: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 482 | 0 | my ($line, $maxColWidth) = @_; | |||||||||||||||||||||||||||
| 483 | 0 | my $i=0; | |||||||||||||||||||||||||||
| 484 | 0 | foreach my $key ( sort keys %{$line} ) | |||||||||||||||||||||||||||
| 485 | { | ||||||||||||||||||||||||||||
| 486 | 0 | _trimBlanks( \${$line}{$key} ); | |||||||||||||||||||||||||||
| 487 | 0 | my $type= _getTypeLen( ${$line}{$key} ); | |||||||||||||||||||||||||||
| 488 | 0 | ${$maxColWidth}[$i] = _getMaxColWidth(${$maxColWidth}[$i], $type); | |||||||||||||||||||||||||||
| 489 | 0 | $i++; | |||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 493 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 494 | sub _trimBlanks | ||||||||||||||||||||||||||||
| 495 | 102 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_trimBlanks: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 496 | 102 | my ($field) = @_; | |||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 102 | $$field =~ s/^\s+//; | |||||||||||||||||||||||||||
| 499 | 102 | $$field =~ s/\s+$//; | |||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 102 | return length( $$field ); | |||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 505 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 506 | sub sumBy() | ||||||||||||||||||||||||||||
| 507 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
sumBy: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 508 | 0 | my ($self, $raw, $colIdxRef, $notGroupBy) = @_; | |||||||||||||||||||||||||||
| 509 | 0 | my $colIdx = $colIdxRef->[0]; #FIXME may be more than one colum in future | |||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 0 | my @LEN = _getColLen( $raw->[2] ); | |||||||||||||||||||||||||||
| 512 | 0 | my $fmt = _getSumFormat( $raw->[3],$colIdx,@LEN ); | |||||||||||||||||||||||||||
| 513 | 0 | my $pattern = _getSplitPattern(@LEN); | |||||||||||||||||||||||||||
| 514 | 0 | my $sum = 0; | |||||||||||||||||||||||||||
| 515 | 0 | my $gSum= _getSumField( $raw->[3],$pattern, $colIdx ); | |||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | 0 | my $old = $raw->[3]; | |||||||||||||||||||||||||||
| 518 | 0 | my @NEW = @{$raw}[0..3]; | |||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | 0 | ▶ | for( my $i=4; $i <= $#{$raw}; $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 521 | { | ||||||||||||||||||||||||||||
| 522 | 0 | ▶ | push @NEW, _endGroup(\$gSum,$fmt,\$sum) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 523 | if( _isGroupEnd($raw,$i,$colIdx,$pattern,$notGroupBy)); | ||||||||||||||||||||||||||||
| 524 | 0 | $gSum += _getSumField( $raw->[$i],$pattern, $colIdx ); | |||||||||||||||||||||||||||
| 525 | 0 | push @NEW, $raw->[$i]; | |||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||
| 527 | 0 | push @NEW, sprintf $fmt, $gSum; | |||||||||||||||||||||||||||
| 528 | 0 | push @NEW, sprintf $fmt, $sum; | |||||||||||||||||||||||||||
| 529 | 0 | return \@NEW; | |||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 533 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 534 | sub _endGroup($$) | ||||||||||||||||||||||||||||
| 535 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_endGroup: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 536 | 0 | my ($sumRef, $fmt, $totSumRef) = @_; | |||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | 0 | my $line = sprintf $fmt, $$sumRef; | |||||||||||||||||||||||||||
| 539 | 0 | $$totSumRef += $$sumRef; | |||||||||||||||||||||||||||
| 540 | 0 | $$sumRef = 0; | |||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | 0 | return $line; | |||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 546 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 547 | sub _isGroupEnd($$$$) | ||||||||||||||||||||||||||||
| 548 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_isGroupEnd: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 549 | 0 | my ($raw,$currIdx,$colIdx,$pattern,$notGroupBy) = @_; | |||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | 0 | my @PREV = _getSplitedLine($raw->[$currIdx-1],$pattern); | |||||||||||||||||||||||||||
| 552 | 0 | my @CURR = _getSplitedLine($raw->[$currIdx], $pattern); | |||||||||||||||||||||||||||
| 553 | 0 | ▶ | for( my $i=0; $i <= $#CURR; $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 554 | { | ||||||||||||||||||||||||||||
| 555 | 0 | ▶ | next if( _noGroupCol($i,$colIdx,$notGroupBy) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 556 | 0 | ▶ | return 1 if( $PREV[$i] ne $CURR[$i] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||
| 558 | 0 | return 0; | |||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 562 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 563 | sub _noGroupCol($$$) | ||||||||||||||||||||||||||||
| 564 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_noGroupCol: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 565 | 0 | my ($idx,$sumIdx,$notGroupBy) = @_; | |||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | 0 | ▶ | return 1 if( $idx == $sumIdx ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 568 | 0 | ▶ | return 0 if( !defined $notGroupBy ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | 0 | ▶ | foreach my $col ( @{$notGroupBy} ) { return 1 if( $col == $idx ); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 571 | 0 | return 0; | |||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||
| 573 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 574 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 575 | sub _getSumField($$$) | ||||||||||||||||||||||||||||
| 576 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getSumField: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 577 | 0 | my ($line,$pattern,$idx) = @_; | |||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | 0 | my @L = _getSplitedLine($line,$pattern); | |||||||||||||||||||||||||||
| 580 | 0 | return $L[$idx]; | |||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 584 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 585 | sub _getSumFormat($$@) | ||||||||||||||||||||||||||||
| 586 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getSumFormat: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 587 | 0 | my ($line, $colIdx, @LEN) = @_; | |||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | 0 | my $form=''; | |||||||||||||||||||||||||||
| 590 | 0 | ▶ | for( my $i=0; $i <= $#LEN; $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 591 | { | ||||||||||||||||||||||||||||
| 592 | 0 | ▶ | if( $i == $colIdx ) { $form .= _getSumColForm($line, $colIdx, @LEN); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 593 | 0 | else { $form .= sprintf "%s ", ' ' x $LEN[$i]; } | |||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||
| 595 | 0 | return $form; | |||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 599 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 600 | sub _getSumColForm($$@) | ||||||||||||||||||||||||||||
| 601 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getSumColForm: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 602 | 0 | my ($line, $colIdx, @LEN) = @_; | |||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | 0 | my $pattern = _getSplitPattern(@LEN); | |||||||||||||||||||||||||||
| 605 | 0 | my @splited = _getSplitedLine($line,$pattern); | |||||||||||||||||||||||||||
| 606 | 0 | my $sumField= $splited[$colIdx]; | |||||||||||||||||||||||||||
| 607 | 0 | my @I = $sumField =~ /(\d+)([.]?)(\d*)/; | |||||||||||||||||||||||||||
| 608 | 0 | my $decimal = $I[2]; | |||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||
| 610 | 0 | ▶ | return '%'. $LEN[$colIdx] . | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 611 | '.'. length($decimal) .'f' if( $I[1] eq '.' ); | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | 0 | return '%'. $LEN[$colIdx] .'d'; | |||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 617 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 618 | sub _getSplitedLine($$) | ||||||||||||||||||||||||||||
| 619 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getSplitedLine: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 620 | 0 | my ($line,$pattern) = @_; | |||||||||||||||||||||||||||
| 621 | 0 | return $line =~ m/$pattern/; | |||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 625 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 626 | sub _getSplitPattern(@) | ||||||||||||||||||||||||||||
| 627 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getSplitPattern: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 628 | 0 | my (@LEN) = @_; | |||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | 0 | return join ' ', map { '(.{'. $_ .'})' } @LEN; | |||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||
| 633 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 634 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 635 | sub _getColLen | ||||||||||||||||||||||||||||
| 636 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_getColLen: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 637 | 0 | my ($cols) = @_; | |||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||
| 639 | 0 | my @len; | |||||||||||||||||||||||||||
| 640 | 0 | foreach my $col ( split /\s+/, $cols ) | |||||||||||||||||||||||||||
| 641 | { | ||||||||||||||||||||||||||||
| 642 | 0 | push @len, length $col; | |||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||
| 644 | 0 | return @len; | |||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||
| 647 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 648 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 649 | sub newGroup($$$) | ||||||||||||||||||||||||||||
| 650 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
newGroup: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 651 | 0 | my ($O, $L, $idx) = @_; | |||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | 0 | foreach my $i ( @{$idx} ) | |||||||||||||||||||||||||||
| 654 | { | ||||||||||||||||||||||||||||
| 655 | 0 | ▶ | return 1 if( $O->[$i] ne $L->[$i] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||
| 657 | 0 | return 0; | |||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | 21 | 1; | |||||||||||||||||||||||||||
| 661 | __END__ | ||||||||||||||||||||||||||||