File Coverage

blib/lib/CBOR/Free/AddOne.pm
Criterion Covered Total %
statement 17 17 100.0
branch 4 4 100.0
condition 1 3 33.3
subroutine 3 3 100.0
pod 0 1 0.0
total 25 28 89.2


line stmt bran cond sub pod time code
1             package CBOR::Free::AddOne;
2              
3 2     2   423200 use strict;
  2         4  
  2         97  
4 2     2   12 use warnings;
  2         3  
  2         467  
5              
6             # Hard to believe there’s not some simple module out there
7             # that already does this.
8              
9             sub to_nonnegative_integer {
10 103     103 0 93795 my @digits = unpack '(a)*', shift();
11              
12 103         214 my $done;
13              
14 103         172 my $carry = 1;
15              
16 103         321 for my $d ( reverse( 0 .. $#digits ) ) {
17 114         283 $digits[$d] += $carry;
18 114         215 $carry = 0;
19              
20 114 100       330 if ($digits[$d] > 9) {
21 11         19 $carry = $digits[$d] - 9;
22 11         23 $digits[$d] = 0;
23             }
24              
25 114 100       303 last if !$carry;
26             }
27              
28 103   33     1013 return join( q<>, $carry || (), @digits );
29             }
30              
31             1;