File Coverage

blib/lib/Geo/Constants.pm
Criterion Covered Total %
statement 21 21 100.0
branch 1 2 50.0
condition n/a
subroutine 9 9 100.0
pod 6 6 100.0
total 37 38 97.3


line stmt bran cond sub pod time code
1             package Geo::Constants;
2 1     1   145627 use strict;
  1         2  
  1         47  
3 1     1   13 use warnings;
  1         2  
  1         68  
4 1     1   9 use base qw{Exporter};
  1         2  
  1         633  
5              
6             our $VERSION = '0.07';
7             our @EXPORT_OK = qw{PI DEG RAD KNOTS};
8              
9             =head1 NAME
10              
11             Geo::Constants - Package for standard Geo:: constants.
12              
13             =head1 SYNOPSIS
14              
15             use Geo::Constants qw{PI DEG RAD}; #import into namespace
16             print "PI: ", PI(), "\n";
17             print "d/r: ", DEG(), "\n";
18             print "r/d: ", RAD(), "\n";
19              
20             use Geo::Constants; #Perl OO
21             my $obj = Geo::Constants->new();
22             print "PI: ", $obj->PI, "\n";
23             print "d/r: ", $obj->DEG, "\n";
24             print "r/d: ", $obj->RAD, "\n";
25              
26             =head1 DESCRIPTION
27              
28             =head1 CONSTRUCTOR
29              
30             =head2 new
31              
32             The new() constructor
33              
34             my $obj = Geo::Constants->new();
35              
36             =cut
37              
38             sub new {
39 1     1 1 232339 my $this = shift;
40 1 50       6 my $class = ref($this) ? ref($this) : $this;
41 1         4 my $self = {};
42 1         2 bless $self, $class;
43 1         6 $self->initialize(@_);
44 1         4 return $self;
45             }
46              
47             =head2 initialize
48              
49             =cut
50              
51             sub initialize {
52 1     1 1 2 my $self=shift;
53 1         7 %$self=@_;
54             }
55              
56             =head1 FUNCTIONS
57              
58             =head2 PI
59              
60             my $pi = $obj->PI;
61              
62             use Geo::Constants qw{PI};
63             my $pi = PI();
64              
65             =cut
66              
67             sub PI {
68 6     6 1 3354 return 4 * atan2(1,1); #Perl should complile this as a constant
69             }
70              
71             =head2 DEG
72              
73             my $degrees_per_radian = $obj->DEG;
74              
75             use Geo::Constants qw{DEG};
76             my $degrees_per_radian = DEG();
77              
78             UOM: degrees/radian
79              
80             =cut
81              
82             sub DEG {
83 2     2 1 9 return 180 / PI(); #Degrees per radian
84             }
85              
86             =head2 RAD
87              
88             my $radians_per_degree = $obj->RAD;
89              
90             use Geo::Constants qw{DEG};
91             my $radians_per_degree = RAD();
92              
93             UOM: radians/degree
94              
95             =cut
96              
97             sub RAD {
98 2     2 1 7 return PI() / 180; #Radians per degree
99             }
100              
101             =head2 KNOTS
102              
103             1 nautical mile per hour = (1852/3600) m/s - United States Department of Commerce, National Institute of Standards and Technology, NIST Special Publication 330, 2001 Edition
104              
105             Returns 1852/3600 m/s/knot
106              
107             UOM: meters/second per knot
108              
109             =cut
110              
111             sub KNOTS {
112 2     2 1 10 return 1852/3600; #1 nautical mile per hour = (1852/3600) m/s
113             }
114              
115             =head1 AUTHOR
116              
117             Michael R. Davis
118              
119             =head1 LICENSE
120              
121             Copyright (c) 2006-2025 Michael R. Davis
122              
123             This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
124              
125             =head1 SEE ALSO
126              
127             L, L, L
128              
129             =cut
130              
131             1;