blib/lib/GPS/Magellan/Message.pm

filter: Statementstmt 65.5% 40 / 61 Branchbran 50.0% 7 / 14 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 60.0% 9 / 15 Podpod 33.3% 1 / 3 totaltotal 60.4% 61 / 101 CC 13 SCAR 13.4
CC
13
Cov
62%
_parse_message
12.0
_checksum
6.0
AUTOLOAD
4.0
CRAP 3.8
« blib/lib/GPS/Magellan/File.pm ↑ Summary blib/lib/GPS/Magellan/Coord.pm »
1  
2 package GPS::Magellan::Message;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 ▶sub new {
Subroutine new: called CC=3 SCAR=13.1
Pod documented
9 10 my $proto = shift;
10 10 my $raw_msg = shift;
11  
12 10 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0100
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
13  
14 10 my $self = bless {
15 fields => [ qw/RAW COMMAND DATA CHECKSUM/ ],
16 }, $class;
17
18 10 $self->_init();
19  
20 10 ▶ return $self unless $raw_msg;
Branch: 1 branch
BranchTrueFalseTotal
unless $raw_msg 10 0 10
21  
22 0 $self->RAW($raw_msg);
23 0 $self->_parse_message($raw_msg);
24 0 $self;
25 }
26  
27  
28 10 ▶sub _init {
Subroutine _init: called CC=2 SCAR=6.9
29 10 my $self = shift;
30  
31 10 foreach my $field (@{$self->fields}){
32 40 $self->_set($field, "");
33 }
34 }
35  
36 0 ▶sub verify_checksum {
Subroutine verify_checksum: not called CC=1 SCAR=6.9
Pod undocumented
37 0 my $self = shift;
38 0 $self->CHECKSUM eq $self->_checksum($self->RAW);
39 }
40  
41 0 ▶sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod undocumented
42 0 my $self = shift;
43 0 $self->RAW(sprintf('PMGN%s,%s', $self->COMMAND, $self->DATA));
44 0 sprintf('$%s*%s', $self->RAW, $self->_checksum($self->RAW));
45 }
46  
47  
48 0 ▶sub _checksum {
Subroutine _checksum: not called CC=2 SCAR=17.9
49 0 my $self = shift;
50 0 my $msg = shift;
51
52 0 my $chksum = 0;
53 0 for (split //, $msg){
54 0 $chksum ^= ord($_);
55 }
56 0 sprintf('%02X', $chksum);
57 }
58  
59  
60 0 ▶sub _parse_message {
Subroutine _parse_message: not called CC=3 SCAR=24.8
61 0 my $self = shift;
62  
63 0 ▶ my @msg = $self->RAW =~ /
Branch: 1 branch
BranchTrueFalseTotal
my(@msg) = $self->RAW =~ / ^\$( PMGN ([A-Z]{3}), (.*) ) \* ([A-Z0-9]{2}) $ /x or die sprintf("Cannot parse message: %s\n", $self->RAW) 0 0 0
64 ^\$(
65 PMGN
66 ([A-Z]{3}),
67 (.*)
68 )
69 \*
70 ([A-Z0-9]{2})
71 $
72 /x or die sprintf("Cannot parse message: %s\n", $self->RAW);
73  
74 0 foreach my $field (@{$self->fields}){
75 0 $self->_set($field, shift @msg);
76 }
77 }
78  
79 0 ▶sub _dump {
Subroutine _dump: not called CC=1 SCAR=6.9
80 0 my $self = shift;
81 0 Dumper($self);
82 }
83  
84 # Accessors
85 110 ▶sub _get {
Subroutine _get: called CC=1 SCAR=0.0
86 110 my $self = shift;
87 110 my $attr = shift;
88 110 return $self->{$attr};
89 }
90  
91 50 ▶sub _set {
Subroutine _set: called CC=3 SCAR=11.0
92 50 my $self = shift;
93 50 my $attr = shift;
94 50 ▶ my $value = shift || '';
Condition100%2/2
shift() || ''
l!l
1040
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
95  
96 50 ▶ return unless $attr;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr 0 50 50
97  
98 50 $self->{$attr} = $value;
99 50 return $self->_get($attr);
100 }
101  
102 30 ▶sub _debug_autoload {
Subroutine _debug_autoload: called CC=2 SCAR=7.1
103 30 my $self = shift;
104 30 ▶ $self->_set('_debug_autoload', shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 30 30
105 30 $self->_get('_debug_autoload');
106 }
107  
108
109 30 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=14.0
110 30 my $self = shift;
111 30 my $attr = $AUTOLOAD;
112  
113 30 $attr =~ s/.*:://;
114  
115 30 ▶ return if $attr =~ /^_/;
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^_/ 0 30 30
116  
117 30 ▶ warn "AUTOLOAD: $attr\n" if $self->_debug_autoload;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_debug_autoload 0 30 30
118  
119 30 ▶ if(@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 10 20 30
120 10 $self->_set($attr, shift);
121 }
122 30 return $self->_get($attr);
123 }
124  
125 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
126  
127 }
128  
129 1 1;
130  
131 __END__
« blib/lib/GPS/Magellan/File.pm ↑ Summary blib/lib/GPS/Magellan/Coord.pm »