blib/lib/GPS/Magellan/File.pm

filter: Statementstmt 71.0% 54 / 76 Branchbran 33.3% 6 / 18 Conditioncond 28.5% 2 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 65.2% 15 / 23 Podpod 12.5% 1 / 8 totaltotal 57.3% 78 / 136 CC 14 SCAR 13.4
CC
14
Cov
61%
read
12.0
_set
12.0
AUTOLOAD
4.4
CRAP 3.8
« blib/lib/GPS/Magellan.pm ↑ Summary blib/lib/GPS/Magellan/Message.pm »
1  
2 package GPS::Magellan::File;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.6
Pod documented
10 1 my $proto = shift;
11 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
12  
13 1 my %args = @_;
14  
15
16 my $self = bless {
17 1 ▶ coords => $args{coords} || [],
Condition50%1/2
$args{'coords'} || []
l!l
10
MC/DC0%0/1
$args{'coords'} || []
$args{'coords'}
Truth table50%1/2
A
A= $args{'coords'}
Aresult
11
00
18 }, $class;
19  
20 1 $self->_init();
21  
22 1 return $self;
23 }
24  
25 1 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
26 1 my $self = shift;
27  
28 }
29  
30 0 ▶sub read {
Subroutine read: not called CC=3 SCAR=24.8
Pod undocumented
31 0 my $self = shift;
32 0 my $file = shift;
33  
34 0 my @raw = ();
35  
36 0 ▶ if($file){
Branch: 1 branch
BranchTrueFalseTotal
if ($file) { } 0 0 0
37 0 ▶ open(INPUT, $file) or die sprintf("%s::read(): cannot open %s\n", ref($self), $file);
Branch: 1 branch
BranchTrueFalseTotal
open INPUT, $file or die sprintf("%s::read(): cannot open %s\n", ref $self, $file) 0 0 0
38 0 @raw = <INPUT>;
39 0 close(INPUT);
40 } else {
41 0 @raw = <STDIN>;
42 }
43  
44 0 $self->decode(\@raw);
45 }
46  
47 1 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
48 1 shift->encode();
49 }
50  
51  
52 1 ▶sub write {
Subroutine write: called CC=3 SCAR=11.4
Pod undocumented
53 1 my $self = shift;
54 1 my $file = shift;
55  
56 1 ▶ if($file){
Branch: 1 branch
BranchTrueFalseTotal
if ($file) { } 1 0 1
57 1 ▶ open(OUTPUT, ">$file") or die sprintf("%s::write(): cannot open %s\n", ref($self), $file);
Branch: 1 branch
BranchTrueFalseTotal
open OUTPUT, ">$file" or die sprintf("%s::write(): cannot open %s\n", ref $self, $file) 1 0 1
58 1 print OUTPUT $self->encode();
59 1 close(OUTPUT);
60 } else {
61 0 print $self->encode();
62 }
63 1 return;
64 }
65  
66  
67 # Interface to be implemented by subclasses representing various file formats
68  
69 0 ▶sub name { 'PLACEHOLDER' }
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
70  
71 0 ▶sub encode { '' }
Subroutine encode: not called CC=1 SCAR=6.9
Pod undocumented
72  
73 0 ▶sub decode { [] }
Subroutine decode: not called CC=1 SCAR=6.9
Pod undocumented
74  
75 0 ▶sub can_read { 0 }
Subroutine can_read: not called CC=1 SCAR=6.9
Pod undocumented
76  
77  
78 # Accessors
79 4 ▶sub _get {
Subroutine _get: called CC=1 SCAR=0.0
80 4 my $self = shift;
81 4 my $attr = shift;
82 4 return $self->{$attr};
83 }
84  
85 0 ▶sub _set {
Subroutine _set: not called CC=3 SCAR=24.8
86 0 my $self = shift;
87 0 my $attr = shift;
88 0 ▶ my $value = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
89  
90 0 ▶ return unless $attr;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr 0 0 0
91  
92 0 $self->{$attr} = $value;
93 0 return $self->_get($attr);
94 }
95  
96 2 ▶sub _debug_autoload {
Subroutine _debug_autoload: called CC=2 SCAR=7.1
97 2 my $self = shift;
98 2 ▶ $self->_set('_debug_autoload', shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
99 2 $self->_get('_debug_autoload');
100 }
101  
102
103 2 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=14.8
104 2 my $self = shift;
105 2 my $attr = $AUTOLOAD;
106  
107 2 $attr =~ s/.*:://;
108  
109 2 ▶ return if $attr =~ /^_/;
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^_/ 0 2 2
110  
111 2 ▶ warn "AUTOLOAD: $attr\n" if $self->_debug_autoload;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_debug_autoload 0 2 2
112  
113 2 ▶ if(@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
114 0 $self->_set($attr, shift);
115 }
116 2 return $self->_get($attr);
117 }
118  
119 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
120  
121 }
122  
123 package GPS::Magellan::File::Way_Txt;
124  
125 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
126  
127 1 ▶use base qw/GPS::Magellan::File/;
Subroutine BEGIN: called CC=1 SCAR=0.0
128  
129 1 ▶sub name { 'GpsDrive way.txt' }
Subroutine name: called CC=1 SCAR=0.0
130  
131 # FILE FORMAT:
132 # EEMSSTRA 5220.484000 454.569000 0000016M
133 # WPT002 5220.879000 454.287000 0000000M
134  
135 2 ▶sub encode {
Subroutine encode: called CC=2 SCAR=6.9
136 2 my $self = shift;
137  
138 2 my @output = ();
139  
140 2 foreach my $c (@{$self->coords}){
141 20 push @output, sprintf("%-22s %04.6f %04.6f %07d%s\n", $c->name, $c->longitude, $c->latitude, $c->altitude, $c->unknown);
142 }
143 2 @output;
144 }
145  
146 0 ▶sub decode {
Subroutine decode: not called CC=1 SCAR=6.9
147 0 my $self = shift;
148 }
149  
150  
151 1 1;
152  
153 __END__
« blib/lib/GPS/Magellan.pm ↑ Summary blib/lib/GPS/Magellan/Message.pm »