| 1 | ############################################################################# | ||||||||||||||||||
| 2 | ## Name: Encode.pm | ||||||||||||||||||
| 3 | ## Purpose: HDB::Encode - Common things for HDB modules. | ||||||||||||||||||
| 4 | ## Author: Graciliano M. P. | ||||||||||||||||||
| 5 | ## Modified by: | ||||||||||||||||||
| 6 | ## Created: 15/01/2003 | ||||||||||||||||||
| 7 | ## RCS-ID: | ||||||||||||||||||
| 8 | ## Copyright: (c) 2002 Graciliano M. P. | ||||||||||||||||||
| 9 | ## Licence: This program is free software; you can redistribute it and/or | ||||||||||||||||||
| 10 | ## modify it under the same terms as Perl itself | ||||||||||||||||||
| 11 | ############################################################################# | ||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | package HDB::Encode ; | ||||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | 1 | ▶ | use strict qw(vars); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 16 | 1 | ▶ | no warnings ; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | 1 | our $VERSION = '1.0' ; | |||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | ######## | ||||||||||||||||||
| 21 | # VARS # | ||||||||||||||||||
| 22 | ######## | ||||||||||||||||||
| 23 | |||||||||||||||||||
| 24 | 1 | my %VER = ( | |||||||||||||||||
| 25 | PACKED_HASH => '1.0' , | ||||||||||||||||||
| 26 | PACKED_ARRAY => '1.0' , | ||||||||||||||||||
| 27 | ) ; | ||||||||||||||||||
| 28 | |||||||||||||||||||
| 29 | ######## | ||||||||||||||||||
| 30 | # PACK # | ||||||||||||||||||
| 31 | ######## | ||||||||||||||||||
| 32 | |||||||||||||||||||
| 33 | 0 | ▶ | sub Pack { | ||||||||||||||||
|
Subroutine
Pack: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 34 | 0 | ▶ | if ( ref($_[0]) eq 'HASH' ) { return &Pack_HASH($_[0]) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 35 | 0 | ▶ | if ( ref($_[0]) eq 'ARRAY' ) { return &Pack_ARRAY($_[0]) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 36 | } | ||||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | ############# | ||||||||||||||||||
| 39 | # PACK_HASH # | ||||||||||||||||||
| 40 | ############# | ||||||||||||||||||
| 41 | |||||||||||||||||||
| 42 | 0 | ▶ | sub Pack_HASH { | ||||||||||||||||
|
Subroutine
Pack_HASH: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||
| 43 | 0 | my ( $hash ) = @_ ; | |||||||||||||||||
| 44 | |||||||||||||||||||
| 45 | 0 | ▶ | if (ref($hash) ne 'HASH') { return( undef ) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 46 | |||||||||||||||||||
| 47 | 0 | my ($pack_init,$pack) ; | |||||||||||||||||
| 48 | |||||||||||||||||||
| 49 | 0 | ▶ | $pack_init = "%HDB_PACKED_HASH%[$VER{PACKED_HASH}]{0}:" if !$_[1] ; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 50 | |||||||||||||||||||
| 51 | 0 | foreach my $key ( keys %$hash ) { | |||||||||||||||||
| 52 | 0 | my ($blk,$tp,$value) ; | |||||||||||||||||
| 53 | 0 | ▶ | if ( ref( $$hash{$key} ) eq 'HASH' ) { $tp = 1 ; $value = &Pack_HASH( $$hash{$key} , 1 ) } | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 54 | 0 | elsif ( ref( $$hash{$key} ) eq 'ARRAY' ) { $tp = 2 ; $value = &Pack_ARRAY( $$hash{$key} , 1 ) ;} | |||||||||||||||||
| 55 | 0 | elsif ( UNIVERSAL::isa($$hash{$key} ,'UNIVERSAL') ) { next ;} ## ignore objects. | |||||||||||||||||
| 56 | 0 | else { $tp = 0 ; $value = $$hash{$key} ;} | |||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | 0 | $blk .= $tp ; | |||||||||||||||||
| 59 | 0 | $blk .= length($key) . ":" ; | |||||||||||||||||
| 60 | 0 | $blk .= $key ; | |||||||||||||||||
| 61 | 0 | $blk .= length($value) . ":" ; | |||||||||||||||||
| 62 | 0 | $blk .= $value ; | |||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | 0 | $pack .= $blk ; | |||||||||||||||||
| 65 | } | ||||||||||||||||||
| 66 | |||||||||||||||||||
| 67 | 0 | ▶ | if ( !$_[1] ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 68 | 0 | my $sz = length($pack) ; | |||||||||||||||||
| 69 | 0 | $pack_init =~ s/\{0}/\{$sz}/s ; | |||||||||||||||||
| 70 | } | ||||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | 0 | return( $pack_init . $pack ) ; | |||||||||||||||||
| 73 | } | ||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | ############## | ||||||||||||||||||
| 76 | # PACK_ARRAY # | ||||||||||||||||||
| 77 | ############## | ||||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | 0 | ▶ | sub Pack_ARRAY { | ||||||||||||||||
|
Subroutine
Pack_ARRAY: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||
| 80 | 0 | my ( $array ) = @_ ; | |||||||||||||||||
| 81 | |||||||||||||||||||
| 82 | 0 | ▶ | if (ref($array) ne 'ARRAY') { return( undef ) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 83 | |||||||||||||||||||
| 84 | 0 | my ($pack_init,$pack) ; | |||||||||||||||||
| 85 | |||||||||||||||||||
| 86 | 0 | ▶ | $pack_init = "%HDB_PACKED_ARRAY%[$VER{PACKED_ARRAY}]{0}:" if !$_[1] ; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 87 | |||||||||||||||||||
| 88 | 0 | foreach my $array_i ( @$array ) { | |||||||||||||||||
| 89 | 0 | my ($blk,$tp,$value) ; | |||||||||||||||||
| 90 | 0 | ▶ | if ( ref( $array_i ) eq 'HASH' ) { $tp = 1 ; $value = &Pack_HASH( $array_i , 1 ) ;} | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 91 | 0 | elsif ( ref( $array_i ) eq 'ARRAY' ) { $tp = 2 ; $value = &Pack_ARRAY( $array_i , 1 ) ;} | |||||||||||||||||
| 92 | 0 | elsif ( UNIVERSAL::isa($array_i ,'UNIVERSAL') ) { next ;} ## ignore objects. | |||||||||||||||||
| 93 | 0 | else { $tp = 0 ; $value = $array_i ;} | |||||||||||||||||
| 94 | |||||||||||||||||||
| 95 | 0 | $blk .= $tp ; | |||||||||||||||||
| 96 | 0 | $blk .= length($value) . ":" ; | |||||||||||||||||
| 97 | 0 | $blk .= $value ; | |||||||||||||||||
| 98 | |||||||||||||||||||
| 99 | 0 | $pack .= $blk ; | |||||||||||||||||
| 100 | } | ||||||||||||||||||
| 101 | |||||||||||||||||||
| 102 | 0 | ▶ | if ( !$_[1] ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 103 | 0 | my $sz = length($pack) ; | |||||||||||||||||
| 104 | 0 | $pack_init =~ s/\{0}/\{$sz}/s ; | |||||||||||||||||
| 105 | } | ||||||||||||||||||
| 106 | |||||||||||||||||||
| 107 | 0 | return( $pack_init . $pack ) ; | |||||||||||||||||
| 108 | } | ||||||||||||||||||
| 109 | |||||||||||||||||||
| 110 | ########## | ||||||||||||||||||
| 111 | # UNPACK # | ||||||||||||||||||
| 112 | ########## | ||||||||||||||||||
| 113 | |||||||||||||||||||
| 114 | 0 | ▶ | sub UnPack { | ||||||||||||||||
|
Subroutine
UnPack: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 115 | 0 | ▶ | if ( &Is_Packed_HASH($_[0]) ) { return &UnPack_HASH($_[0]) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 116 | 0 | ▶ | if ( &Is_Packed_ARRAY($_[0]) ) { return &UnPack_ARRAY($_[0]) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 117 | 0 | return( $_[0] ) ; | |||||||||||||||||
| 118 | } | ||||||||||||||||||
| 119 | |||||||||||||||||||
| 120 | ############### | ||||||||||||||||||
| 121 | # UNPACK_HASH # | ||||||||||||||||||
| 122 | ############### | ||||||||||||||||||
| 123 | |||||||||||||||||||
| 124 | 0 | ▶ | sub UnPack_HASH { | ||||||||||||||||
|
Subroutine
UnPack_HASH: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||
| 125 | 0 | my %hash ; | |||||||||||||||||
| 126 | |||||||||||||||||||
| 127 | 0 | my $pos = 0 ; | |||||||||||||||||
| 128 | |||||||||||||||||||
| 129 | 0 | ▶ | if ( !$_[1] ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 130 | 0 | ▶ | if ( !&Is_Packed_HASH($_[0]) ) { return() ;} | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 131 | 0 | elsif ( !&Check_Pack_Size($_[0]) ) { return("SIZE_ERROR: $_[0]") ;} | |||||||||||||||||
| 132 | 0 | else { $pos = index($_[0],':') + 1 ;} | |||||||||||||||||
| 133 | } | ||||||||||||||||||
| 134 | |||||||||||||||||||
| 135 | 0 | my $lng = length($_[0]) ; | |||||||||||||||||
| 136 | |||||||||||||||||||
| 137 | 0 | ▶ | while( $pos < $lng ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 138 | 0 | my $tp = substr($_[0],$pos++,1) ; | |||||||||||||||||
| 139 | 0 | my $key = &blk_read($_[0],$pos) ; | |||||||||||||||||
| 140 | 0 | my $val = &blk_read($_[0],$pos) ; | |||||||||||||||||
| 141 | |||||||||||||||||||
| 142 | 0 | ▶ | if ($tp == 1) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 143 | 0 | my %val = &UnPack_HASH($val,1) ; | |||||||||||||||||
| 144 | 0 | $val = \%val ; | |||||||||||||||||
| 145 | } | ||||||||||||||||||
| 146 | elsif ($tp == 2) { | ||||||||||||||||||
| 147 | 0 | my @val = &UnPack_ARRAY($val,1) ; | |||||||||||||||||
| 148 | 0 | $val = \@val ; | |||||||||||||||||
| 149 | } | ||||||||||||||||||
| 150 | |||||||||||||||||||
| 151 | 0 | $hash{$key} = $val ; | |||||||||||||||||
| 152 | } | ||||||||||||||||||
| 153 | |||||||||||||||||||
| 154 | 0 | ▶ | if ( wantarray ) { return( %hash ) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 155 | 0 | else { return( \%hash ) ;} | |||||||||||||||||
| 156 | } | ||||||||||||||||||
| 157 | |||||||||||||||||||
| 158 | ################ | ||||||||||||||||||
| 159 | # UNPACK_ARRAY # | ||||||||||||||||||
| 160 | ################ | ||||||||||||||||||
| 161 | |||||||||||||||||||
| 162 | 0 | ▶ | sub UnPack_ARRAY { | ||||||||||||||||
|
Subroutine
UnPack_ARRAY: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||
| 163 | 0 | my @array ; | |||||||||||||||||
| 164 | |||||||||||||||||||
| 165 | 0 | my $pos = 0 ; | |||||||||||||||||
| 166 | |||||||||||||||||||
| 167 | 0 | ▶ | if ( !$_[1] ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 168 | 0 | ▶ | if ( !&Is_Packed_ARRAY($_[0]) ) { return() ;} | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 169 | 0 | elsif ( !&Check_Pack_Size($_[0]) ) { return("SIZE_ERROR: $_[0]") ;} | |||||||||||||||||
| 170 | 0 | else { $pos = index($_[0],':') + 1 ;} | |||||||||||||||||
| 171 | } | ||||||||||||||||||
| 172 | |||||||||||||||||||
| 173 | 0 | my $lng = length($_[0]) ; | |||||||||||||||||
| 174 | |||||||||||||||||||
| 175 | 0 | ▶ | while( $pos < $lng ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 176 | 0 | my $tp = substr($_[0],$pos++,1) ; | |||||||||||||||||
| 177 | 0 | my $val = &blk_read($_[0],$pos) ; | |||||||||||||||||
| 178 | |||||||||||||||||||
| 179 | 0 | ▶ | if ($tp == 1) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 180 | 0 | my %val = &UnPack_HASH($val,1) ; | |||||||||||||||||
| 181 | 0 | $val = \%val ; | |||||||||||||||||
| 182 | } | ||||||||||||||||||
| 183 | elsif ($tp == 2) { | ||||||||||||||||||
| 184 | 0 | my @val = &UnPack_ARRAY($val,1) ; | |||||||||||||||||
| 185 | 0 | $val = \@val ; | |||||||||||||||||
| 186 | } | ||||||||||||||||||
| 187 | |||||||||||||||||||
| 188 | 0 | push(@array , $val) ; | |||||||||||||||||
| 189 | } | ||||||||||||||||||
| 190 | |||||||||||||||||||
| 191 | 0 | ▶ | if ( wantarray ) { return( @array ) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 192 | 0 | else { return( \@array ) ;} | |||||||||||||||||
| 193 | } | ||||||||||||||||||
| 194 | |||||||||||||||||||
| 195 | ############ | ||||||||||||||||||
| 196 | # BLK_READ # | ||||||||||||||||||
| 197 | ############ | ||||||||||||||||||
| 198 | |||||||||||||||||||
| 199 | 0 | ▶ | sub blk_read { | ||||||||||||||||
|
Subroutine
blk_read: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||
| 200 | 0 | my ( undef , undef , $lng ) = @_ ; | |||||||||||||||||
| 201 | |||||||||||||||||||
| 202 | 0 | ▶ | if (!$lng) { $lng = length( $_[0] ) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 203 | |||||||||||||||||||
| 204 | 0 | my ($s,$sz) ; | |||||||||||||||||
| 205 | |||||||||||||||||||
| 206 | 0 | ▶ | while( $_[1] <= $lng ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 207 | 0 | $s = substr( $_[0] , $_[1] , 1) ; | |||||||||||||||||
| 208 | 0 | $_[1]++ ; | |||||||||||||||||
| 209 | 0 | ▶ | if ($s eq ':') { last ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 210 | 0 | $sz .= $s ; | |||||||||||||||||
| 211 | } | ||||||||||||||||||
| 212 | |||||||||||||||||||
| 213 | 0 | my $blk = substr( $_[0] , $_[1] , $sz) ; | |||||||||||||||||
| 214 | |||||||||||||||||||
| 215 | 0 | $_[1] += $sz ; | |||||||||||||||||
| 216 | |||||||||||||||||||
| 217 | 0 | return( $blk ) ; | |||||||||||||||||
| 218 | } | ||||||||||||||||||
| 219 | |||||||||||||||||||
| 220 | ################## | ||||||||||||||||||
| 221 | # IS_PACKED_HASH # | ||||||||||||||||||
| 222 | ################## | ||||||||||||||||||
| 223 | |||||||||||||||||||
| 224 | 0 | ▶ | sub Is_Packed_HASH { | ||||||||||||||||
|
Subroutine
Is_Packed_HASH: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||
| 225 | 0 | ▶ | if ( $_[0] =~ /^\s*\%HDB_PACKED_HASH%\[[\d\.]+]\{\d+}:/ ) { return( 1 ) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 226 | 0 | return( undef ) ; | |||||||||||||||||
| 227 | } | ||||||||||||||||||
| 228 | |||||||||||||||||||
| 229 | ################### | ||||||||||||||||||
| 230 | # IS_PACKED_ARRAY # | ||||||||||||||||||
| 231 | ################### | ||||||||||||||||||
| 232 | |||||||||||||||||||
| 233 | 0 | ▶ | sub Is_Packed_ARRAY { | ||||||||||||||||
|
Subroutine
Is_Packed_ARRAY: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||
| 234 | 0 | ▶ | if ( $_[0] =~ /^\s*\%HDB_PACKED_ARRAY%\[[\d\.]+]\{\d+}:/ ) { return( 1 ) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 235 | 0 | return( undef ) ; | |||||||||||||||||
| 236 | } | ||||||||||||||||||
| 237 | |||||||||||||||||||
| 238 | ################### | ||||||||||||||||||
| 239 | # CHECK_PACK_SIZE # | ||||||||||||||||||
| 240 | ################### | ||||||||||||||||||
| 241 | |||||||||||||||||||
| 242 | 0 | ▶ | sub Check_Pack_Size { | ||||||||||||||||
|
Subroutine
Check_Pack_Size: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 243 | 0 | ▶ | if ( $_[0] =~ /^(\s*\%HDB_PACKED_(?:HASH|ARRAY)%\[[\d\.]+]\{)(\d+)(}:)/s ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 244 | 0 | my $lng = length($1) + length($3) ; | |||||||||||||||||
| 245 | 0 | my $sz = $2 ; | |||||||||||||||||
| 246 | 0 | $lng += length($sz) + $sz ; | |||||||||||||||||
| 247 | 0 | ▶ | if ( length($_[0]) == $lng ) { return( 1 ) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 248 | } | ||||||||||||||||||
| 249 | 0 | return( undef ) ; | |||||||||||||||||
| 250 | } | ||||||||||||||||||
| 251 | |||||||||||||||||||
| 252 | ############### | ||||||||||||||||||
| 253 | # PACKED_SIZE # | ||||||||||||||||||
| 254 | ############### | ||||||||||||||||||
| 255 | |||||||||||||||||||
| 256 | 0 | ▶ | sub Packed_SIZE { | ||||||||||||||||
|
Subroutine
Packed_SIZE: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 257 | 0 | my ( $ref ) = @_ ; | |||||||||||||||||
| 258 | 0 | ▶ | if ( ref($ref) eq 'HASH' ) { return &Packed_SIZE_HASH($ref) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 259 | 0 | ▶ | if ( ref($ref) eq 'ARRAY' ) { return &Packed_SIZE_ARRAY($ref) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 260 | } | ||||||||||||||||||
| 261 | |||||||||||||||||||
| 262 | #################### | ||||||||||||||||||
| 263 | # PACKED_SIZE_HASH # | ||||||||||||||||||
| 264 | #################### | ||||||||||||||||||
| 265 | |||||||||||||||||||
| 266 | 0 | ▶ | sub Packed_SIZE_HASH { | ||||||||||||||||
|
Subroutine
Packed_SIZE_HASH: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||
| 267 | 0 | my ( $hash ) = @_ ; | |||||||||||||||||
| 268 | |||||||||||||||||||
| 269 | 0 | ▶ | if (ref($hash) ne 'HASH') { return( undef ) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 270 | |||||||||||||||||||
| 271 | 0 | my ($pack_init,$size) ; | |||||||||||||||||
| 272 | |||||||||||||||||||
| 273 | 0 | ▶ | $pack_init = "%HDB_PACKED_HASH%[$VER{PACKED_HASH}]{0}:" if !$_[1] ; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 274 | |||||||||||||||||||
| 275 | 0 | foreach my $key ( keys %$hash ) { | |||||||||||||||||
| 276 | 0 | my ($blk_sz,$value_sz) ; | |||||||||||||||||
| 277 | 0 | ▶ | if ( ref( $$hash{$key} ) eq 'HASH' ) { $value_sz = &Packed_SIZE_HASH( $$hash{$key} , 1 ) } | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 278 | 0 | elsif ( ref( $$hash{$key} ) eq 'ARRAY' ) { $value_sz = &Packed_SIZE_ARRAY( $$hash{$key} , 1 ) ;} | |||||||||||||||||
| 279 | 0 | elsif ( UNIVERSAL::isa($$hash{$key} ,'UNIVERSAL') ) { next ;} ## ignore objects. | |||||||||||||||||
| 280 | 0 | else { $value_sz = length( $$hash{$key} ) ;} | |||||||||||||||||
| 281 | |||||||||||||||||||
| 282 | 0 | $blk_sz += 1 ; | |||||||||||||||||
| 283 | 0 | $blk_sz += length(length($key)) + 1 ; | |||||||||||||||||
| 284 | 0 | $blk_sz += length($key) ; | |||||||||||||||||
| 285 | 0 | $blk_sz += length($value_sz) + 1 ; | |||||||||||||||||
| 286 | 0 | $blk_sz += $value_sz ; | |||||||||||||||||
| 287 | |||||||||||||||||||
| 288 | 0 | $size += $blk_sz ; | |||||||||||||||||
| 289 | } | ||||||||||||||||||
| 290 | |||||||||||||||||||
| 291 | 0 | ▶ | if ( !$_[1] ) { $pack_init =~ s/\{0}/\{$size}/s ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 292 | |||||||||||||||||||
| 293 | 0 | ▶ | $size += length($pack_init) if !$_[1] ; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 294 | |||||||||||||||||||
| 295 | 0 | return( $size ) ; | |||||||||||||||||
| 296 | } | ||||||||||||||||||
| 297 | |||||||||||||||||||
| 298 | ##################### | ||||||||||||||||||
| 299 | # PACKED_SIZE_ARRAY # | ||||||||||||||||||
| 300 | ##################### | ||||||||||||||||||
| 301 | |||||||||||||||||||
| 302 | 0 | ▶ | sub Packed_SIZE_ARRAY { | ||||||||||||||||
|
Subroutine
Packed_SIZE_ARRAY: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||
| 303 | 0 | my ( $array ) = @_ ; | |||||||||||||||||
| 304 | |||||||||||||||||||
| 305 | 0 | ▶ | if (ref($array) ne 'ARRAY') { return( undef ) ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 306 | |||||||||||||||||||
| 307 | 0 | my ($pack_init,$size) ; | |||||||||||||||||
| 308 | |||||||||||||||||||
| 309 | 0 | ▶ | $pack_init = "%HDB_PACKED_ARRAY%[$VER{PACKED_ARRAY}]{0}:" if !$_[1] ; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 310 | |||||||||||||||||||
| 311 | 0 | foreach my $array_i ( @$array ) { | |||||||||||||||||
| 312 | 0 | my ($blk_sz,$value_sz) ; | |||||||||||||||||
| 313 | 0 | ▶ | if ( ref( $array_i ) eq 'HASH' ) { $value_sz = &Packed_SIZE_HASH( $array_i , 1 ) ;} | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 314 | 0 | elsif ( ref( $array_i ) eq 'ARRAY' ) { $value_sz = &Packed_SIZE_ARRAY( $array_i , 1 ) ;} | |||||||||||||||||
| 315 | 0 | elsif ( UNIVERSAL::isa($array_i ,'UNIVERSAL') ) { next ;} ## ignore objects. | |||||||||||||||||
| 316 | 0 | else { $value_sz = length($array_i) ;} | |||||||||||||||||
| 317 | |||||||||||||||||||
| 318 | 0 | $blk_sz += 1 ; | |||||||||||||||||
| 319 | 0 | $blk_sz += length($value_sz) + 1 ; | |||||||||||||||||
| 320 | 0 | $blk_sz += $value_sz ; | |||||||||||||||||
| 321 | |||||||||||||||||||
| 322 | 0 | $size += $blk_sz ; | |||||||||||||||||
| 323 | } | ||||||||||||||||||
| 324 | |||||||||||||||||||
| 325 | 0 | ▶ | if ( !$_[1] ) { $pack_init =~ s/\{0}/\{$size}/s ;} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 326 | |||||||||||||||||||
| 327 | 0 | ▶ | $size += length($pack_init) if !$_[1] ; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 328 | |||||||||||||||||||
| 329 | 0 | return( $size ) ; | |||||||||||||||||
| 330 | } | ||||||||||||||||||
| 331 | |||||||||||||||||||
| 332 | ####### | ||||||||||||||||||
| 333 | # END # | ||||||||||||||||||
| 334 | ####### | ||||||||||||||||||
| 335 | |||||||||||||||||||
| 336 | # 0 => key & val || line | ||||||||||||||||||
| 337 | # 1 => hash ref | ||||||||||||||||||
| 338 | # 2 => array ref | ||||||||||||||||||
| 339 | |||||||||||||||||||
| 340 | 1 | 1; | |||||||||||||||||
| 341 | |||||||||||||||||||
| 342 | __END__ | ||||||||||||||||||