| 1 | # ,A class representing a states response from the OpenSky Network API | ||
| 2 | |||
| 3 | package OpenSky::API::States; | ||
| 4 | |||
| 5 | our $VERSION = '0.002'; | ||
| 6 | use Moose; | ||
| 7 | use OpenSky::API::Types qw( | ||
| 8 | InstanceOf | ||
| 9 | PositiveOrZeroInt | ||
| 10 | ); | ||
| 11 | use OpenSky::API::Core::StateVector; | ||
| 12 | use OpenSky::API::Utils::Iterator; | ||
| 13 | use experimental qw(signatures); | ||
| 14 | |||
| 15 | has time => ( is => 'ro', isa => PositiveOrZeroInt ); | ||
| 16 | has vectors => ( | ||
| 17 | is => 'ro', | ||
| 18 | isa => InstanceOf ['OpenSky::API::Utils::Iterator'], | ||
| 19 | handles => [qw(first next reset all count)], | ||
| 20 | ); | ||
| 21 | |||
| 22 | around 'BUILDARGS' => sub ( $orig, $class, $response ) { | ||
| 23 | my $states = $response->{states}; | ||
| 24 | my $time = $response->{time}; | ||
| 25 | |||
| 26 | my @state_vectors = map { OpenSky::API::Core::StateVector->new($_) } @$states; | ||
| 27 | my $iterator = OpenSky::API::Utils::Iterator->new( rows => \@state_vectors ); | ||
| 28 | |||
| 29 | return $class->$orig( vectors => $iterator, time => $time ); | ||
| 30 | }; | ||
| 31 | |||
| 32 | __PACKAGE__->meta->make_immutable; | ||
| 33 | |||
| 34 | __END__ | ||
| 35 | |||
| 36 | =pod | ||
| 37 | |||
| 38 | =encoding UTF-8 | ||
| 39 | |||
| 40 | =head1 NAME | ||
| 41 | |||
| 42 | OpenSky::API::States | ||
| 43 | |||
| 44 | =head1 VERSION | ||
| 45 | |||
| 46 | version 0.002 | ||
| 47 | |||
| 48 | =head1 METHODS | ||
| 49 | |||
| 50 | =head2 time | ||
| 51 | |||
| 52 | The time which the state vectors in this response are associated with. All | ||
| 53 | vectors represent the state of a vehicle with the interval C<[time=1, time]>. | ||
| 54 | |||
| 55 | =head2 vectors | ||
| 56 | |||
| 57 | Returns an iterator of L<OpenSky::API::Core::StateVector> objects. | ||
| 58 | |||
| 59 | As a convenience, the following methods are delegated to the iterator: | ||
| 60 | |||
| 61 | =over 4 | ||
| 62 | |||
| 63 | =item * first | ||
| 64 | |||
| 65 | =item * next | ||
| 66 | |||
| 67 | =item * reset | ||
| 68 | |||
| 69 | =item * all | ||
| 70 | |||
| 71 | =item * count | ||
| 72 | |||
| 73 | =back | ||
| 74 | |||
| 75 | =head1 AUTHOR | ||
| 76 | |||
| 77 | Curtis "Ovid" Poe <curtis.poe@gmail.com> | ||
| 78 | |||
| 79 | =head1 COPYRIGHT AND LICENSE | ||
| 80 | |||
| 81 | This software is Copyright (c) 2023 by Curtis "Ovid" Poe. | ||
| 82 | |||
| 83 | This is free software, licensed under: | ||
| 84 | |||
| 85 | The Artistic License 2.0 (GPL Compatible) | ||
| 86 | |||
| 87 | =cut |