File Coverage

blib/lib/GPS/Base.pm
Criterion Covered Total %
statement 19 22 86.3
branch 4 8 50.0
condition 8 12 66.6
subroutine 4 4 100.0
pod 0 2 0.0
total 35 48 72.9


line stmt bran cond sub pod time code
1             # -*- perl -*-
2              
3             #
4             # $Id: Base.pm,v 1.4 2006/09/09 16:57:15 eserte Exp $
5             # Author: Slaven Rezic
6             #
7             # Copyright (C) 2003 Slaven Rezic. All rights reserved.
8             # This package is free software; you can redistribute it and/or
9             # modify it under the same terms as Perl itself.
10             #
11             # Mail: slaven@rezic.de
12             # WWW: http://www.rezic.de/eserte/
13             #
14              
15             package GPS::Base;
16              
17 3     3   12 use strict;
  3         4  
  3         87  
18 3     3   9 use vars qw($VERSION);
  3         4  
  3         1100  
19             $VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
20              
21             # Factory
22             sub new {
23 1     1 0 50 my($class, %param) = @_;
24 1 50       4 if ($param{Protocol} eq 'GRMN') {
    0          
25 1         49 require GPS::Garmin;
26 1         8 GPS::Garmin->new(%param);
27             } elsif ($param{Protocol} eq 'NMEA') {
28 0         0 require GPS::NMEA;
29 0         0 GPS::NMEA->new(%param);
30             } else {
31 0         0 die "Unknown or unspecified Protocol: $param{Protocol}";
32             }
33             }
34              
35             sub common_new {
36 6     6 0 10 my $type = shift;
37 6         13 my %param = @_;
38 6   66     50 my $port = $param{'Port'} ||
39             ($^O eq 'MSWin32'
40             ? 'COM1'
41             : ($^O =~ /^(?:(?:free|net|open)bsd|bsd(?:os|i))$/
42             ? (-e '/dev/cuad0'
43             ? '/dev/cuad0' # FreeBSD 6.x and later
44             : '/dev/cuaa0'
45             )
46             : '/dev/ttyS1'
47             )
48             );
49 6   100     26 my $baud = $param{'Baud'} || 9600;
50 6   50     14 my $protocol = $param{'Protocol'} || 'GRMN';
51 6   100     19 my $timeout = $param{'timeout'} || 10;
52              
53             my $self = bless
54             { 'port' => $port,
55             'baud' => $baud,
56             'protocol' => $protocol,
57             'timeout' => $timeout,
58             'verbose' => $param{verbose},
59 6 50 33     45 (exists $param{'Return'} && $param{'Return'} eq 'hash'
60             ? (return_as_hash => 1)
61             : ()
62             ),
63             }, $type;
64              
65 6 100       29 $self->connect unless $param{do_not_init};
66              
67 5         45 $self;
68             }
69              
70             1;
71              
72             __END__