BlockPack.pm

filter: Statementstmt 8.8% 17 / 192 Branchbran 0.6% 1 / 152 Conditioncond 3.1% 1 / 32 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 6 totaltotal 5.5% 23 / 412 CC 90 SCAR 69.7
CC
90
Cov
5%
unpack_block
2070.0
init_block_element
380.0
pack_block
272.0
CRAP 1062.1
↑ Summary MaTirelire/AccountsV2.pm »
1 =encoding iso-8859-1
2  
3 =cut
4  
5 #
6 # Copyright (C) 2005, Maxime Soulé
7 # You may distribute this file under the terms of the Artistic
8 # License, as specified in the README file.
9 #
10  
11 package Palm::BlockPack;
12  
13 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use Carp qw(carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Palm::FieldPack;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 our $VERBOSE = 1;
19  
20 2 our $VERSION = '1.0';
21  
22  
23 2 my %SPECIAL_TYPES = (UInt8 => [ \&pack_fields_to_UInt8,
24 \&unpack_UInt8_to_fields ],
25 UInt16 => [ \&pack_fields_to_UInt16,
26 \&unpack_UInt16_to_fields ],
27 UInt32 => [ \&pack_fields_to_UInt32,
28 \&unpack_UInt32_to_fields ],
29 DateType => [ \&pack_DateType, \&unpack_DateType ],
30 TimeType => [ \&pack_TimeType, \&unpack_TimeType ],
31 double => [ \&pack_double, \&unpack_double, 8 ],
32 );
33  
34 sub pretty_str ($)
35 0 ▶{
Subroutine pretty_str: not called CC=5 SCAR=34.0
Pod undocumented
36 0 my $str = shift;
37 0 my $new = '';
38  
39 0 ▶ return $str if ref $str;
Branch: 1 branch
BranchTrueFalseTotal
if ref $str 0 0 0
40  
41 0 ▶ while (length($str) > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (length $str > 0) 0 0 0
42 {
43 0 my $char = substr($str, 0, 1, '');
44  
45 0 ▶ if (ord($char) < 32)
Branch: 1 branch
BranchTrueFalseTotal
if (ord $char < 32) { } 0 0 0
46 {
47 0 ▶ if (ord($char) == 10)
Branch: 1 branch
BranchTrueFalseTotal
if (ord $char == 10) { } 0 0 0
48 {
49 0 $new .= "\n";
50 }
51 else
52 {
53 0 $new .= "^" . chr(ord($char) + 64);
54 }
55 }
56 else
57 {
58 0 $new .= $char;
59 }
60 }
61  
62 0 return $new;
63 }
64  
65  
66 sub __negate ($$)
67 0 ▶{
Subroutine __negate: not called CC=6 SCAR=37.4
68 0 my($ref, $size) = @_;
69  
70 0 ▶ my $array = ref($ref) eq 'ARRAY' ? $ref : [ $$ref ];
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
71  
72 0 foreach my $elt (@$array)
73 {
74 # Already null or negative, nothing to do...
75 0 ▶ next if $elt <= 0; # (1 << ($size - 1));
Branch: 1 branch
BranchTrueFalseTotal
if $elt <= 0 0 0 0
76  
77 0 ▶ if ($size == 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($size == 2) { } 0 0 0
78 {
79 0 $elt = unpack('s', pack('S', $elt));
80 }
81 else # $size == 4
82 {
83 0 $elt = unpack('l', pack('L', $elt));
84 }
85 }
86  
87 0 ▶ if (ref($ref) ne 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref ne "ARRAY") 0 0 0
88 {
89 0 $$ref = $array->[0];
90 }
91 }
92  
93  
94 sub new ($@)
95 28 ▶{
Subroutine new: called CC=3 SCAR=12.0
Pod undocumented
96 28 my $class = shift;
97  
98 28 ▶ die "Odd number of attributes" if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 28 28
99  
100 28 my $self = [ @_ ];
101  
102 28 ▶ return bless($self, ref($class) || $class);
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0280
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
103 }
104  
105  
106 sub init_block_element ($$$;$)
107 0 ▶{
Subroutine init_block_element: not called CC=19 SCAR=59.4
Pod undocumented
108 0 my($self, $ref_hash, $index, $delete_noinit) = @_;
109  
110 0 my $type = $self->[$index];
111 0 my $value = $self->[$index + 1];
112  
113 # Skip bytes
114 0 ▶ if ($type eq 'skip')
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'skip') { } 0 0 0
elsif ($type =~ /^UInt(?:8|16|32)\z/) { } 0 0 0
elsif ($type eq 'DateType') { } 0 0 0
elsif ($type eq 'TimeType') { } 0 0 0
115 {
116 # Nothing to do here
117 }
118 # Bit field
119 elsif ($type =~ /^UInt(?:8|16|32)\z/)
120 {
121 0 foreach my $field (@$value)
122 {
123 # No reference => no init
124 0 ▶ if (ref $field)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $field) { } 0 0 0
elsif ($delete_noinit) { } 0 0 0
125 {
126 # The name without bit_width
127 0 my($name) = split(':', $field->[0]);
128  
129 0 $ref_hash->{$name} = $field->[1];
130 }
131 elsif ($delete_noinit)
132 {
133 # The name without bit_width
134 0 my($name) = split(':', $field);
135  
136 0 delete $ref_hash->{$name};
137 }
138 }
139 }
140 elsif ($type eq 'DateType')
141 {
142 # No reference => no init
143 0 ▶ if (ref $value)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value) { } 0 0 0
elsif ($delete_noinit) { } 0 0 0
144 {
145 # 'date_', 'now'
146 0 ▶ if (@$value == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@$value == 2) { } 0 0 0
147 {
148 0 ▶ if ($value->[1] eq 'now')
Branch: 1 branch
BranchTrueFalseTotal
if ($value->[1] eq 'now') { } 0 0 0
149 {
150 0 my @now = localtime(time);
151 0 $ref_hash->{"$value->[0]day"} = $now[3];
152 0 $ref_hash->{"$value->[0]month"} = $now[4] + 1;
153 0 $ref_hash->{"$value->[0]year"} = $now[5] + 1900;
154 }
155 else
156 {
157 0 $ref_hash->{"$value->[0]day"} = $value->[1];
158 0 $ref_hash->{"$value->[0]month"} = $value->[1];
159 0 $ref_hash->{"$value->[0]year"} = $value->[1];
160 }
161 }
162 # 'date_', day, month, year
163 else
164 {
165 0 $ref_hash->{"$value->[0]day"} = $value->[1];
166 0 $ref_hash->{"$value->[0]month"} = $value->[2];
167 0 $ref_hash->{"$value->[0]year"} = $value->[3];
168 }
169 }
170 elsif ($delete_noinit)
171 {
172 0 delete @$ref_hash{"${value}day",
173 "${value}month",
174 "${value}year"};
175 }
176 }
177 elsif ($type eq 'TimeType')
178 {
179 # No reference => no init
180 0 ▶ if (ref $value)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value) { } 0 0 0
elsif ($delete_noinit) { } 0 0 0
181 {
182 # 'time_', 'now'
183 0 ▶ if (@$value == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@$value == 2) { } 0 0 0
184 {
185 0 ▶ if ($value->[1] eq 'now')
Branch: 1 branch
BranchTrueFalseTotal
if ($value->[1] eq 'now') { } 0 0 0
186 {
187 0 my @now = localtime(time);
188 0 $ref_hash->{"$value->[0]hour"} = $now[2];
189 0 $ref_hash->{"$value->[0]min"} = $now[1];
190 }
191 else
192 {
193 0 $ref_hash->{"$value->[0]hour"} = $value->[1];
194 0 $ref_hash->{"$value->[0]min"} = $value->[1];
195 }
196 }
197 # 'time_', hour, min
198 else
199 {
200 0 $ref_hash->{"$value->[0]hour"} = $value->[1];
201 0 $ref_hash->{"$value->[0]min"} = $value->[2];
202 }
203 }
204 elsif ($delete_noinit)
205 {
206 0 delete @$ref_hash{"${value}hour", "${value}min"};
207 }
208 }
209 # Other types
210 else
211 {
212 # No reference => no init
213 0 ▶ if (ref $value)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value) { } 0 0 0
elsif ($delete_noinit) { } 0 0 0
214 {
215 # Liste de nombres
216 0 ▶ if ($type =~ /^\[(?:-?[Nn]|[Cc])[1-9]\d*\]\z/)
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^\[(?:-?[Nn]|[Cc])[1-9]\d*\]\z/) { } 0 0 0
217 {
218 0 $ref_hash->{$value->[0]} = [ @$value[1 .. $#$value] ];
219 }
220 else
221 {
222 0 $ref_hash->{$value->[0]} = $value->[1];
223 }
224 }
225 elsif ($delete_noinit)
226 {
227 0 delete $ref_hash->{$value};
228 }
229 }
230 }
231  
232  
233 #
234 # Initialise le hash passé avec les valeurs par défaut
235 sub init_block ($$;$)
236 0 ▶{
Subroutine init_block: not called CC=2 SCAR=17.9
Pod undocumented
237 0 my($self, $ref_hash, $delete_noinit) = @_;
238 0 my $index;
239  
240 0 ▶ for (my $index = 0; $index < @$self; $index += 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($index < @$self) 0 0 0
241 {
242 0 $self->init_block_element($ref_hash, $index, $delete_noinit);
243 }
244 }
245  
246  
247 sub pack_block ($$)
248 0 ▶{
Subroutine pack_block: not called CC=16 SCAR=56.1
Pod undocumented
249 0 my($self, $ref_hash) = @_;
250 0 my $index;
251  
252 0 my $pack = '';
253  
254 0 ▶ for (my $index = 0; $index < @$self; $index += 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($index < @$self) 0 0 0
255 {
256 0 my $type = $self->[$index];
257 0 my $value = $self->[$index + 1];
258  
259 # Skip bytes
260 0 ▶ if ($type eq 'skip')
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'skip') { } 0 0 0
elsif ($type =~ /^UInt(?:8|16|32)\z/) { } 0 0 0
261 {
262 0 my($num, $byte);
263  
264 0 ▶ if (ref $value)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 0 0 0
265 {
266 0 ($num, $byte) = @$value;
267 }
268 else
269 {
270 0 $num = $value;
271 0 $byte = "\0";
272 }
273  
274 0 $pack .= $byte x $num;
275 }
276 # Bit field
277 elsif ($type =~ /^UInt(?:8|16|32)\z/)
278 {
279 $pack .=
280 $SPECIAL_TYPES{$type}[0]->($ref_hash,
281 0 ▶ map {ref($_) ? $_->[0] : $_} @$value);
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
282 }
283 else
284 {
285 0 ▶ my $field_name = ref($value) ? $value->[0] : $value;
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 0 0 0
286  
287 # DateType || TimeType
288 0 ▶ if ($type =~ /^(?:Date|Time)Type\z/)
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /^(?:Date|Time)Type\z/) { } 0 0 0
elsif ($type =~ /^\[((?:-?[Nn]|[Cc])([1-9]\d*))\]\z/) { } 0 0 0
289 {
290 0 $pack .= $SPECIAL_TYPES{$type}[0]->($ref_hash, $field_name);
291 }
292 # Liste de nombres
293 elsif ($type =~ /^\[((?:-?[Nn]|[Cc])([1-9]\d*))\]\z/)
294 {
295 0 my($pack_type, $num) = ($1, $2);
296  
297 0 $pack_type =~ s/^-//; # Negative case deleted here...
298  
299 0 ▶ my $ref_list = $ref_hash->{$field_name} || [];
Condition0%0/2
$ref_hash->{$field_name} || []
l!l
00
MC/DC0%0/1
$ref_hash->{$field_name} || []
$ref_hash->{$field_name}
Truth table0%0/2
A
A= $ref_hash->{$field_name}
Aresult
11
00
300  
301 0 ▶ if (@$ref_list < $num)
Branch: 1 branch
BranchTrueFalseTotal
if (@$ref_list < $num) 0 0 0
302 {
303 0 push(@$ref_list, (0) x (@{$ref_list} - $num));
304 }
305  
306 0 $pack .= pack($pack_type, @$ref_list);
307 }
308 else
309 {
310 0 my $field_value = $ref_hash->{$field_name};
311  
312 0 ▶ unless (defined $field_value)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $field_value) 0 0 0
313 {
314 0 ▶ if ($type =~ /^(?:-?[Nn]|[Cc])\z/
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /^(?:-?[Nn]|[Cc])\z/ or exists $SPECIAL_TYPES{$type}) { } 0 0 0
elsif ($type =~ /^Z(\*|\d+)\z/) { } 0 0 0
Condition0%0/3
$type =~ /^(?:-?[Nn]|[Cc])\z/ or exists $SPECIAL_TYPES{$type}
l!l&&r!l&&!r
000
MC/DC0%0/2
$type =~ /^(?:-?[Nn]|[Cc])\z/ or exists $SPECIAL_TYPES{$type}
$type =~ /^(?:-?[Nn]|[Cc])\z/ exists $SPECIAL_TYPES{$type}
Truth table0%0/3
A or B
A= $type =~ /^(?:-?[Nn]|[Cc])\z/B= exists $SPECIAL_TYPES{$type}
ABresult
1X1
011
000
315 or exists $SPECIAL_TYPES{$type})
316 {
317 0 $field_value = 0;
318 }
319 elsif ($type =~ /^Z(\*|\d+)\z/)
320 {
321 0 $field_value = '';
322 }
323 else
324 {
325 0 die "Unknown Perl pack type";
326 }
327 }
328  
329 # Special type
330 0 ▶ if (exists $SPECIAL_TYPES{$type})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $SPECIAL_TYPES{$type}) { } 0 0 0
331 {
332 0 $pack .= $SPECIAL_TYPES{$type}[0]->($field_value);
333 }
334 # Perl pack type
335 else
336 {
337 0 $type =~ s/^-//; # Negative case deleted here...
338  
339 0 $pack .= pack($type, $field_value);
340 }
341 }
342 }
343 }
344  
345 0 return $pack;
346 }
347  
348  
349 sub unpack_block ($$;$$)
350 0 ▶{
Subroutine unpack_block: not called CC=45 SCAR=76.4
Pod undocumented
351 0 my($self, $pack, $ref_hash, $no_nonempty_alert) = @_;
352  
353 0 ▶ $ref_hash = {} unless defined $ref_hash;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref_hash 0 0 0
354  
355 0 ▶ my $ref_pack = ref($pack) ? $pack : \$pack;
Branch: 1 branch
BranchTrueFalseTotal
ref $pack ? : 0 0 0
356  
357 0 ▶ for (my $index = 0; $index < @$self; $index += 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($index < @$self) 0 0 0
358 {
359 0 my $type = $self->[$index];
360 0 my $value = $self->[$index + 1];
361 0 my $out_of_data = 0;
362  
363 0 ▶ if ($type eq 'skip')
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'skip') { } 0 0 0
elsif ($type =~ /^UInt(8|16|32)\z/) { } 0 0 0
364 {
365 0 ▶ my $size = ref($value) ? $value->[0] : $value;
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 0 0 0
366  
367 0 ▶ if (length($$ref_pack) < $size)
Branch: 1 branch
BranchTrueFalseTotal
if (length $$ref_pack < $size) { } 0 0 0
368 {
369 0 ▶ if ($VERBOSE and not $no_nonempty_alert)
Branch: 1 branch
BranchTrueFalseTotal
if ($Palm::BlockPack::VERBOSE and not $no_nonempty_alert) 0 0 0
Condition0%0/3
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
!ll&&!rl&&r
000
MC/DC0%0/2
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
$Palm::BlockPack::VERBOSE not $no_nonempty_alert
Truth table0%0/3
A and not(B)
A= $Palm::BlockPack::VERBOSEB= not $no_nonempty_alert
ABresult
0X0
100
111
370 {
371 0 carp("unpack_block: out of data, can't skip"
372 . " (only " . length($$ref_pack)
373 . " byte(s) available: \""
374 . pretty_str($$ref_pack)
375 . "\")");
376 }
377 }
378 else
379 {
380 0 substr($$ref_pack, 0, $size) = '';
381 }
382 }
383 # Bit field
384 elsif ($type =~ /^UInt(8|16|32)\z/)
385 {
386 0 my $size = $1 / 8;
387  
388 0 ▶ if (length($$ref_pack) < $size)
Branch: 1 branch
BranchTrueFalseTotal
if (length $$ref_pack < $size) { } 0 0 0
389 {
390 0 ▶ if ($VERBOSE and not $no_nonempty_alert)
Branch: 1 branch
BranchTrueFalseTotal
if ($Palm::BlockPack::VERBOSE and not $no_nonempty_alert) 0 0 0
Condition0%0/3
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
!ll&&!rl&&r
000
MC/DC0%0/2
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
$Palm::BlockPack::VERBOSE not $no_nonempty_alert
Truth table0%0/3
A and not(B)
A= $Palm::BlockPack::VERBOSEB= not $no_nonempty_alert
ABresult
0X0
100
111
391 {
392 0 carp("unpack_block: ",
393 "out of data, can't unpack field $type"
394 . " (only " . length($$ref_pack)
395 . " byte(s) available: \""
396 . pretty_str($$ref_pack)
397 . "\")");
398 }
399 0 $out_of_data = 1;
400 }
401 else
402 {
403 $SPECIAL_TYPES{$type}[1]->($ref_hash,
404 substr($$ref_pack, 0, $size, ''),
405 0 ▶ map { ref($_) ? $_->[0] : $_ }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
406 @$value);
407 }
408 }
409 else
410 {
411 0 ▶ my $field_name = ref($value) ? $value->[0] : $value;
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 0 0 0
412  
413 # DateType || TimeType
414 0 ▶ if ($type =~ /^(?:Date|Time)Type\z/)
Branch: 3 branches
BranchTrueFalseTotal
if ($type =~ /^(?:Date|Time)Type\z/) { } 0 0 0
elsif (exists $SPECIAL_TYPES{$type}) { } 0 0 0
elsif ($type =~ /^\[((-?[Nn]|[Cc])([1-9]\d*))\]\z/) { } 0 0 0
415 {
416 0 ▶ if (length($$ref_pack) < 2)
Branch: 1 branch
BranchTrueFalseTotal
if (length $$ref_pack < 2) { } 0 0 0
417 {
418 0 ▶ if ($VERBOSE and not $no_nonempty_alert)
Branch: 1 branch
BranchTrueFalseTotal
if ($Palm::BlockPack::VERBOSE and not $no_nonempty_alert) 0 0 0
Condition0%0/3
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
!ll&&!rl&&r
000
MC/DC0%0/2
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
$Palm::BlockPack::VERBOSE not $no_nonempty_alert
Truth table0%0/3
A and not(B)
A= $Palm::BlockPack::VERBOSEB= not $no_nonempty_alert
ABresult
0X0
100
111
419 {
420 0 carp("unpack_block: out of data, can't unpack $type"
421 . " (only " . length($$ref_pack)
422 . " byte(s) available: \""
423 . pretty_str($$ref_pack)
424 . "\")");
425 }
426 0 $out_of_data = 1;
427 }
428 else
429 {
430 0 $SPECIAL_TYPES{$type}[1]->($ref_hash,
431 substr($$ref_pack, 0, 2, ''),
432 $field_name);
433 }
434 }
435 # Special type
436 elsif (exists $SPECIAL_TYPES{$type})
437 {
438 0 ▶ if (length($$ref_pack) < $SPECIAL_TYPES{$type}[2])
Branch: 1 branch
BranchTrueFalseTotal
if (length $$ref_pack < $SPECIAL_TYPES{$type}[2]) { } 0 0 0
439 {
440 0 ▶ if ($VERBOSE and not $no_nonempty_alert)
Branch: 1 branch
BranchTrueFalseTotal
if ($Palm::BlockPack::VERBOSE and not $no_nonempty_alert) 0 0 0
Condition0%0/3
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
!ll&&!rl&&r
000
MC/DC0%0/2
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
$Palm::BlockPack::VERBOSE not $no_nonempty_alert
Truth table0%0/3
A and not(B)
A= $Palm::BlockPack::VERBOSEB= not $no_nonempty_alert
ABresult
0X0
100
111
441 {
442 0 carp("unpack_block: out of data, can't unpack $type"
443 . " (only " . length($$ref_pack)
444 . " byte(s) available: \""
445 . pretty_str($$ref_pack)
446 . "\")");
447 }
448 0 $out_of_data = 1;
449 }
450 else
451 {
452 $ref_hash->{$field_name} = $SPECIAL_TYPES{$type}[1]
453 0 ->(substr($$ref_pack, 0, $SPECIAL_TYPES{$type}[2],''));
454 }
455 }
456 # Liste de nombres
457 elsif ($type =~ /^\[((-?[Nn]|[Cc])([1-9]\d*))\]\z/)
458 {
459 0 my($pack_type, $pack_one, $num) = ($1, $2, $3);
460  
461 0 my $neg = 0;
462 0 ▶ if (substr($pack_type, 0, 1) eq '-')
Branch: 1 branch
BranchTrueFalseTotal
if (substr($pack_type, 0, 1) eq "-") 0 0 0
463 {
464 0 substr($pack_type, 0, 1) = '';
465 0 substr($pack_one, 0, 1) = '';
466 0 $neg = 1;
467 }
468  
469 0 my $size;
470 0 ▶ if ($pack_one eq 'N')
Branch: 2 branches
BranchTrueFalseTotal
if ($pack_one eq 'N') { } 0 0 0
elsif ($pack_one eq 'n') { } 0 0 0
471 {
472 0 $size = 4;
473 }
474 elsif ($pack_one eq 'n')
475 {
476 0 $size = 2;
477 }
478 else # $pack_one eq 'C' or $pack_one eq 'c'
479 {
480 0 $size = 1;
481 }
482  
483 0 ▶ if (length($$ref_pack) < $size * $num)
Branch: 1 branch
BranchTrueFalseTotal
if (length $$ref_pack < $size * $num) { } 0 0 0
484 {
485 0 ▶ if ($VERBOSE and not $no_nonempty_alert)
Branch: 1 branch
BranchTrueFalseTotal
if ($Palm::BlockPack::VERBOSE and not $no_nonempty_alert) 0 0 0
Condition0%0/3
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
!ll&&!rl&&r
000
MC/DC0%0/2
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
$Palm::BlockPack::VERBOSE not $no_nonempty_alert
Truth table0%0/3
A and not(B)
A= $Palm::BlockPack::VERBOSEB= not $no_nonempty_alert
ABresult
0X0
100
111
486 {
487 0 carp("unpack_block: out of data, can't unpack $type"
488 . " (only " . length($$ref_pack)
489 . " byte(s) available: \""
490 . pretty_str($$ref_pack)
491 . "\")");
492 }
493 0 $out_of_data = 1;
494 }
495 else
496 {
497 0 $ref_hash->{$field_name}
498 = [ unpack($pack_type,
499 substr($$ref_pack, 0, $size * $num, '')) ];
500  
501 # 16 bits or 32 bits value is signed...
502 0 ▶ __negate($ref_hash->{$field_name}, $size) if $neg;
Branch: 1 branch
BranchTrueFalseTotal
if $neg 0 0 0
503 }
504 }
505 # Perl pack type
506 else
507 {
508 0 my($size, $min_size);
509  
510 0 my $neg = 0;
511  
512 0 ▶ if ($type =~ s/^(-?)N\z/N/)
Branch: 4 branches
BranchTrueFalseTotal
if ($type =~ s/^(-?)N\z/N/) { } 0 0 0
elsif ($type =~ s/^(-?)n\z/n/) { } 0 0 0
elsif ($type =~ /^[Cc]\z/) { } 0 0 0
elsif ($type =~ /^Z(\*|\d+)\z/) { } 0 0 0
513 {
514 0 $neg = $1;
515 0 $size = $min_size = 4;
516 }
517 elsif ($type =~ s/^(-?)n\z/n/)
518 {
519 0 $neg = $1;
520 0 $size = $min_size = 2;
521 }
522 elsif ($type =~ /^[Cc]\z/)
523 {
524 0 $size = $min_size = 1;
525 }
526 elsif ($type =~ /^Z(\*|\d+)\z/)
527 {
528 0 ▶ if ($1 eq '*')
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq '*') { } 0 0 0
529 {
530 0 $min_size = 1; # juste \0
531 0 $size = undef;
532 }
533 else
534 {
535 0 $size = $min_size = $1;
536 }
537 }
538 else
539 {
540 0 die "Unknown Perl unpack type";
541 }
542  
543 0 ▶ if (length($$ref_pack) < $min_size)
Branch: 1 branch
BranchTrueFalseTotal
if (length $$ref_pack < $min_size) { } 0 0 0
544 {
545 0 ▶ if ($VERBOSE and not $no_nonempty_alert)
Branch: 1 branch
BranchTrueFalseTotal
if ($Palm::BlockPack::VERBOSE and not $no_nonempty_alert) 0 0 0
Condition0%0/3
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
!ll&&!rl&&r
000
MC/DC0%0/2
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
$Palm::BlockPack::VERBOSE not $no_nonempty_alert
Truth table0%0/3
A and not(B)
A= $Palm::BlockPack::VERBOSEB= not $no_nonempty_alert
ABresult
0X0
100
111
546 {
547 0 carp("unpack_block: out of data, can't unpack $type"
548 . " (only " . length($$ref_pack)
549 . " byte(s) available: \""
550 . pretty_str($$ref_pack)
551 . "\")");
552 }
553 0 $out_of_data = 1;
554 }
555 else
556 {
557 0 ▶ if (defined $size)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $size) { } 0 0 0
558 {
559 0 $ref_hash->{$field_name}
560 = unpack($type, substr($$ref_pack, 0, $size, ''));
561  
562 # 16 bits or 32 bits value is signed...
563 0 ▶ __negate(\$ref_hash->{$field_name}, $size) if $neg;
Branch: 1 branch
BranchTrueFalseTotal
if $neg 0 0 0
564 }
565 # On ne pouvait pas connaître la taille avant le unpack
566 else
567 {
568 0 $ref_hash->{$field_name} = unpack($type, $$ref_pack);
569  
570 substr($$ref_pack, 0,
571 0 length($ref_hash->{$field_name}) + 1)
572 = ''; # Longueur avec le \0
573 }
574 }
575 }
576 }
577  
578 # Cas de out of data, il faut initialiser à la valeur par défaut
579 0 ▶ $self->init_block_element($ref_hash, $index) if $out_of_data;
Branch: 1 branch
BranchTrueFalseTotal
if $out_of_data 0 0 0
580 }
581  
582 0 ▶ if ($VERBOSE and not $no_nonempty_alert and length($$ref_pack) > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($Palm::BlockPack::VERBOSE and not $no_nonempty_alert and length $$ref_pack > 0) 0 0 0
Condition0%0/6
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert and length $$ref_pack > 0
!ll&&!rl&&r
000
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert
!ll&&!rl&&r
000
MC/DC0%0/3
$Palm::BlockPack::VERBOSE and not $no_nonempty_alert and length $$ref_pack > 0
$Palm::BlockPack::VERBOSE not $no_nonempty_alert length $$ref_pack > 0
Truth table0%0/4
A and not(B) and C
A= $Palm::BlockPack::VERBOSEB= not $no_nonempty_alertC= length $$ref_pack > 0
ABCresult
0XX0
10X0
1100
1111
583 {
584 0 carp("unpack_block: ", length($$ref_pack), " bytes of data remain: \""
585 . pretty_str($$ref_pack)
586 . "\"");
587 }
588  
589 0 return $ref_hash;
590 }
591  
592 2 1;
593 __END__
↑ Summary MaTirelire/AccountsV2.pm »