File Coverage

lib/WebService/OpenSky/Core/StateVector.pm
Criterion Covered Total %
statement 7 23 30.4
branch 0 12 0.0
condition 0 4 0.0
subroutine 2 4 50.0
pod 2 2 100.0
total 11 45 24.4


line stmt bran cond sub pod time code
1             package WebService::OpenSky::Core::StateVector;
2              
3             # ABSTRACT: A class representing a state from the OpenSky Network API
4              
5 8     8   64 use WebService::OpenSky::Moose;
  8         19  
  8         63  
6             our $VERSION = '0.4';
7              
8             my @PARAMS = qw(
9             icao24
10             callsign
11             origin_country
12             time_position
13             last_contact
14             longitude
15             latitude
16             baro_altitude
17             on_ground
18             velocity
19             true_track
20             vertical_rate
21             sensors
22             geo_altitude
23             squawk
24             spi
25             position_source
26             category
27             );
28              
29             param [@PARAMS];
30              
31             around 'BUILDARGS' => sub ( $orig, $class, $state ) {
32             my %value_for;
33             @value_for{@PARAMS} = @$state;
34             return $class->$orig(%value_for);
35             };
36              
37 1     1   8 sub _get_params ($class) {@PARAMS}
  1         3  
  1         1  
  1         6  
38              
39 0 0   0 1   method category_name() {
  0 0          
  0            
  0            
40 0   0       my $category = $self->category // 0;
41 0 0         $category = 0 if $category > 20;
42 0 0         return '' unless $category;
43 0           my @names = (
44             'No information at all',
45             'No ADS-B Emitter Category Information',
46             'Light (< 15500 lbs)',
47             'Small (15500 to 75000 lbs)',
48             'Large (75000 to 300000 lbs)',
49             'High Vortex Large (aircraft such as B-757)',
50             'Heavy (> 300000 lbs)',
51             'High Performance (> 5g acceleration and 400 kts)',
52             'Rotorcraft',
53             'Glider / sailplane',
54             'Lighter-than-air',
55             'Parachutist / Skydiver',
56             'Ultralight / hang-glider / paraglider',
57             'Reserved',
58             'Unmanned Aerial Vehicle',
59             'Space / Trans-atmospheric vehicle',
60             'Surface Vehicle – Emergency Vehicle',
61             'Surface Vehicle – Service Vehicle',
62             'Point Obstacle (includes tethered balloons)',
63             'Cluster Obstacle',
64             'Line Obstacle',
65             );
66 0           return $names[$category];
67             }
68              
69 0 0   0 1   method position_source_name() {
  0 0          
  0            
  0            
70 0   0       my $source = $self->position_source // return 'Uknown';
71 0           my @sources = (
72             'ADS-B',
73             'ASTERIX',
74             'MLAT',
75             'FLARM',
76             );
77 0           return $sources[$source];
78             }
79              
80             __END__
81              
82             =pod
83              
84             =encoding UTF-8
85              
86             =head1 NAME
87              
88             WebService::OpenSky::Core::StateVector - A class representing a state from the OpenSky Network API
89              
90             =head1 VERSION
91              
92             version 0.4
93              
94             =head1 SYNOPSIS
95              
96             use WebService::OpenSky;
97             my $opensky = WebService::OpenSky->new;
98             my $states = $opensky->get_states;
99             while ( my $vector = $states->next ) {
100             say $vector->callsign;
101             say $vector->latitude;
102             say $vector->longitude;
103             }
104              
105             =head1 DESCRIPTION
106              
107             This class is not to be instantiated directly. It is a read-only class representing an
108             L<OpenSky state vector|https://openskynetwork.github.io/opensky-api/index.html#state-vectors>.
109              
110             All attributes are read-only.
111              
112             =head2 C<icao24>
113              
114             Unique ICAO 24-bit address of the transponder in hex string representation.
115              
116             =head2 C<callsign>
117              
118             Callsign of the vehicle (8 chars). Can be null if no callsign has been received.
119              
120             =head2 C<origin_country>
121              
122             Country name inferred from the ICAO 24-bit address.
123              
124             =head2 C<time_position>
125              
126             Unix timestamp (seconds) for the last position update. Can be null if no position report was received by OpenSky within the past 15s.
127              
128             =head2 C<last_contact>
129              
130             Unix timestamp (seconds) for the last update in general. This field is updated for any new, valid message received from the transponder.
131              
132             =head2 C<longitude>
133              
134             WGS-84 longitude in decimal degrees. Can be null.
135              
136             =head2 C<latitude>
137              
138             WGS-84 latitude in decimal degrees. Can be null.
139              
140             =head2 C<baro_altitude>
141              
142             Barometric altitude in meters. Can be null.
143              
144             =head2 C<on_ground>
145              
146             Boolean value which indicates if the position was retrieved from a surface position report.
147              
148             =head2 C<velocity>
149              
150             Velocity over ground in m/s. Can be null.
151              
152             =head2 C<true_track>
153              
154             True track in decimal degrees clockwise from north (north=0°). Can be null.
155              
156             =head2 C<vertical_rate>
157              
158             Vertical rate in m/s. A positive value indicates that the airplane is climbing, a negative value indicates that it descends. Can be null.
159              
160             =head2 C<sensors>
161              
162             IDs of the receivers which contributed to this state vector. Is null if no filtering for sensor was used in the request.
163              
164             =head2 C<geo_altitude>
165              
166             Geometric altitude in meters. Can be null.
167              
168             =head2 C<squawk>
169              
170             The transponder code aka Squawk. Can be null.
171              
172             =head2 C<spi>
173              
174             Whether flight status indicates special purpose indicator.
175              
176             =head2 C<position_source_name>
177              
178             Returns the name of the position source. Can be an empty string.
179              
180             =head2 C<position_source>
181              
182             Integer. Origin of this state’s position:
183              
184             0 = ADS-B
185             1 = ASTERIX
186             2 = MLAT
187             3 = FLARM
188              
189             =head2 C<category_name>
190              
191             Returns the name of the aircraft category. Can be an empty string.
192              
193             If C<< $opensky->get_states >> is called without C<extended> set to true, this
194             method will always return an empty string.
195              
196             =head2 C<category>
197              
198             Integer. Aircraft category. Can be null.
199              
200             0 = No information at all
201             1 = No ADS-B Emitter Category Information
202             2 = Light (< 15500 lbs)
203             3 = Small (15500 to 75000 lbs)
204             4 = Large (75000 to 300000 lbs)
205             5 = High Vortex Large (aircraft such as B-757)
206             6 = Heavy (> 300000 lbs)
207             7 = High Performance (> 5g acceleration and 400 kts)
208             8 = Rotorcraft
209             9 = Glider / sailplane
210             10 = Lighter-than-air
211             11 = Parachutist / Skydiver
212             12 = Ultralight / hang-glider / paraglider
213             13 = Reserved
214             14 = Unmanned Aerial Vehicle
215             15 = Space / Trans-atmospheric vehicle
216             16 = Surface Vehicle – Emergency Vehicle
217             17 = Surface Vehicle – Service Vehicle
218             18 = Point Obstacle (includes tethered balloons)
219             19 = Cluster Obstacle
220             20 = Line Obstacle
221              
222             =head1 AUTHOR
223              
224             Curtis "Ovid" Poe <curtis.poe@gmail.com>
225              
226             =head1 COPYRIGHT AND LICENSE
227              
228             This software is Copyright (c) 2023 by Curtis "Ovid" Poe.
229              
230             This is free software, licensed under:
231              
232             The Artistic License 2.0 (GPL Compatible)
233              
234             =cut