File Coverage

blib/lib/Protocol/DBus/Signature.pm
Criterion Covered Total %
statement 29 29 100.0
branch 11 12 91.6
condition 3 3 100.0
subroutine 4 4 100.0
pod 0 2 0.0
total 47 50 94.0


line stmt bran cond sub pod time code
1             package Protocol::DBus::Signature;
2              
3 7     7   705 use strict;
  7         14  
  7         212  
4 7     7   32 use warnings;
  7         10  
  7         1689  
5              
6             # Returns a list of single complete types (SCTs).
7              
8             sub split {
9 164     164 0 235 my ($sig) = @_;
10              
11 164         205 my @scts;
12              
13 164         260 while (length($sig)) {
14 211         299 my $next_sct_len = Protocol::DBus::Signature::get_sct_length($sig, 0);
15 211         526 push @scts, substr( $sig, 0, $next_sct_len, q<> );
16             }
17              
18 164         394 return @scts;
19             }
20              
21             # Returns the length of the single complete type at $sct_offset.
22              
23             sub get_sct_length {
24 740     740 0 3705 my ($sig, $sct_offset) = @_;
25              
26 740         911 my $start = $sct_offset;
27              
28 740         1085 my $next = substr($sig, $sct_offset, 1);
29              
30 740 100       1267 if ($next eq 'a') {
31              
32             # “{ }” only happens after “a”
33 114         194 my $next_2nd = substr($sig, 1 + $sct_offset, 1);
34 114 100       234 if ($next_2nd eq '{') {
35              
36             # 4 for the “a”, “{”, key type, and “}”.
37             # We assume that the signature is well-formed.
38 36         103 return 4 + get_sct_length($sig, 3 + $sct_offset);
39             }
40              
41 78         152 return 1 + get_sct_length($sig, 1 + $sct_offset);
42             }
43              
44 626 100       990 if ($next eq '(') {
45 52         71 while (1) {
46 160         224 $sct_offset++;
47              
48 160 50       253 last if $sct_offset >= length($sig);
49              
50 160         221 my $next_in_struct = substr($sig, $sct_offset, 1);
51              
52 160 100 100     471 if ($next_in_struct eq '(' || $next_in_struct eq 'a') {
    100          
53 18         48 $sct_offset += get_sct_length($sig, $sct_offset) - 1;
54             }
55             elsif ($next_in_struct eq ')') {
56 52         83 last;
57             }
58             }
59             }
60              
61 626         1253 return 1 + ($sct_offset - $start);
62             }
63              
64             1;