Net/OBEX/Packet/Headers.pm

filter: Statementstmt 96.9% 63 / 65 Branchbran 66.6% 16 / 24 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 5 / 5 totaltotal 91.0% 102 / 112 CC 14 SCAR 11.7
CC
14
Cov
89%
_make_header_value
5.1
make
5.1
parse
4.0
CRAP 3.2
« Net/OBEX/Packet/Request/SetPath.pm ↑ Summary Net/OBEX/Packet/Headers/Byte4.pm »
1 package Net::OBEX::Packet::Headers;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 our $VERSION = '1.001002'; # VERSION
7  
8 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Net::OBEX::Packet::Headers::Unicode;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Net::OBEX::Packet::Headers::ByteSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Net::OBEX::Packet::Headers::Byte4;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 my %Header_Meaning_Of = _make_header_meanings();
14 my %Header_Type_Of = (
15 32 ( map { $_ => 'byte4' } qw( count length timeb connection_id ) ),
16  
17 88 ( map { $_ => 'byteseq' } qw(
18 type time target http
19 who app_params auth_challenge auth_response
20 body end_of_body object_class
21 )
22 ),
23  
24 8 ( map { $_ => 'unicode' } qw( name description ) ),
25 );
26  
27 6 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
28 6 my ( $class, $headers_raw ) = @_;
29  
30 6 return bless { HEADERS_RAW => $headers_raw }, $class;
31 }
32  
33 17 ▶sub make {
Subroutine make: called CC=5 SCAR=16.3
Pod documented
34 17 my $self = shift;
35 17 my ( $name, $value ) = @_;
36 17 $name = lc $name;
37 croak "Invalid header name specified to make()"
38 17 ▶ unless exists $Header_Type_Of{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Header_Type_Of{$name} 0 17 17
39  
40 17 my $type = $Header_Type_Of{ $name };
41 17 ▶ if ( $type eq 'byteseq' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'byteseq') { } 11 6 17
elsif ($type eq 'byte4') { } 4 2 6
elsif ($type eq 'unicode') { } 2 0 2
42 11 return Net::OBEX::Packet::Headers::ByteSeq->new(
43 $name => $value,
44 )->make;
45 }
46 elsif ( $type eq 'byte4' ) {
47 4 return Net::OBEX::Packet::Headers::Byte4->new(
48 $name => $value,
49 )->make;
50 }
51 elsif ( $type eq 'unicode' ) {
52 2 return Net::OBEX::Packet::Headers::Unicode->new(
53 $name => $value,
54 )->make;
55 }
56 else {
57 0 die 'I should never got to here. Please email '
58 . 'to zoffix@cpan.org';
59 }
60 }
61  
62 2 ▶sub parse {
Subroutine parse: called CC=4 SCAR=13.9
Pod documented
63 2 my $self = shift;
64  
65 2 my $headers_raw = shift;
66 2 ▶ $headers_raw = $self->headers_raw
Branch: 1 branch
BranchTrueFalseTotal
unless defined $headers_raw 0 2 2
67 unless defined $headers_raw;
68  
69 2 $self->headers_raw( $headers_raw );
70  
71 2 my %headers;
72 2 ▶ while (length $headers_raw) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $headers_raw) 19 2 21
73 19 (my $HI_raw, $headers_raw ) = unpack 'a a*', $headers_raw;
74  
75 19 my $HI = $Header_Meaning_Of{ $HI_raw };
76 last
77 19 ▶ unless defined $HI;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $HI 0 19 19
78  
79 19 ( $headers{ $HI }, $headers_raw)
80 = $self->_make_header_value( $HI_raw, $headers_raw );
81 }
82  
83 2 return $self->headers_parsed( \%headers );
84 }
85  
86 19 ▶sub _make_header_value {
Subroutine _make_header_value: called CC=5 SCAR=16.4
87 19 my ( $self, $HI_raw, $headers_raw ) = @_;
88  
89 # Bits 8 and 7 of HI - Interpretation
90 # 00 - null terminated Unicode text,
91 # length prefixed with 2 byte unsigned integer
92 # 01 - byte sequence, length prefixed with 2 byte unsigned integer
93 # 10 - 1 byte quantity
94 # 11 - 4 byte quantity - transmitted in network byte order
95  
96 19 my $type = unpack 'B2', $HI_raw;
97 19 ▶ if ( $type eq '00' or $type eq '01' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq '00' or $type eq '01') { } 14 5 19
elsif ($type eq '10') { } 0 5 5
elsif ($type eq '11') { } 5 0 5
Condition100%3/3
$type eq "00" or $type eq "01"
l!l&&r!l&&!r
2125
MC/DC100%2/2
$type eq "00" or $type eq "01"
$type eq "00" $type eq "01"
Truth table100%3/3
A or B
A= $type eq "00"B= $type eq "01"
ABresult
1X1
011
000
98 14 my ( $header_length, $headers_raw ) = unpack 'n a*', $headers_raw;
99 14 $header_length -= 3; # first three bytes of length are
100 # the HI and it's length bytes
101 14 return unpack "a$header_length a*", $headers_raw;
102 }
103 elsif ( $type eq '10' ) {
104 0 return unpack 'aa*', $headers_raw;
105 }
106 elsif ( $type eq '11' ) {
107 5 return unpack 'a4a*', $headers_raw;
108 }
109 }
110  
111 2 ▶sub headers_raw {
Subroutine headers_raw: called CC=2 SCAR=7.0
Pod documented
112 2 my $self = shift;
113 2 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 0 2
114 2 $self->{ HEADERS_RAW } = shift;
115 }
116 2 return $self->{ HEADERS_RAW };
117 }
118  
119 2 ▶sub headers_parsed {
Subroutine headers_parsed: called CC=2 SCAR=7.0
Pod documented
120 2 my $self = shift;
121 2 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 0 2
122 2 $self->{ HEADERS_PARSED } = shift;
123 }
124 2 return $self->{ HEADERS_PARSED };
125 }
126  
127 8 ▶sub _make_header_meanings {
Subroutine _make_header_meanings: called CC=1 SCAR=0.0
128 return (
129 8 "\xC0" => 'count',
130 "\x01" => 'name',
131 "\x42" => 'type',
132 "\xC3" => 'length',
133 "\x44" => 'time',
134 "\xC4" => 'timeb',
135 "\x05" => 'description',
136 "\x46" => 'target',
137 "\x47" => 'http',
138 "\x48" => 'body',
139 "\x49" => 'end_of_body',
140 "\x4A" => 'who',
141 "\xCB" => 'connection_id',
142 "\x4C" => 'app_params',
143 "\x4D" => 'auth_challenge',
144 "\x4E" => 'auth_response',
145 "\x4F" => 'object_class',
146 );
147  
148 }
149  
150 8 1;
151  
152 __END__
« Net/OBEX/Packet/Request/SetPath.pm ↑ Summary Net/OBEX/Packet/Headers/Byte4.pm »