| 1 | package WebService::OpenSky::Response; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | # ABSTRACT: A class representing a response from the OpenSky Network API | ||||||||||||||
| 4 | |||||||||||||||
| 5 | 8 | ▶ | use WebService::OpenSky::Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 8 | ▶ | use WebService::OpenSky::Utils::Iterator; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 8 | ▶ | use WebService::OpenSky::Types qw( | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | ArrayRef | ||||||||||||||
| 9 | Bool | ||||||||||||||
| 10 | HashRef | ||||||||||||||
| 11 | InstanceOf | ||||||||||||||
| 12 | Route | ||||||||||||||
| 13 | 8 | ); | |||||||||||||
| 14 | |||||||||||||||
| 15 | 8 | our $VERSION = '0.5'; | |||||||||||||
| 16 | |||||||||||||||
| 17 | 6 | ▶ | param raw_response => ( | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 18 | isa => ArrayRef | HashRef, | ||||||||||||||
| 19 | 6 | ▶ | default => method() { $self->_empty_response }, | ||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
| |||||||||||||||
| 20 | ); | ||||||||||||||
| 21 | |||||||||||||||
| 22 | 8 | param route => ( | |||||||||||||
| 23 | isa => Route, | ||||||||||||||
| 24 | ); | ||||||||||||||
| 25 | |||||||||||||||
| 26 | 8 | param query => ( | |||||||||||||
| 27 | isa => HashRef, | ||||||||||||||
| 28 | ); | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 8 | field _iterator => ( | |||||||||||||
| 31 | is => 'rw', | ||||||||||||||
| 32 | isa => InstanceOf ['WebService::OpenSky::Utils::Iterator'], | ||||||||||||||
| 33 | writer => '_set_iterator', | ||||||||||||||
| 34 | init_arg => undef, | ||||||||||||||
| 35 | ); | ||||||||||||||
| 36 | |||||||||||||||
| 37 | 8 | field _inflated => ( | |||||||||||||
| 38 | is => 'rw', | ||||||||||||||
| 39 | isa => Bool, | ||||||||||||||
| 40 | default => 0, | ||||||||||||||
| 41 | init_arg => undef, | ||||||||||||||
| 42 | ); | ||||||||||||||
| 43 | |||||||||||||||
| 44 | 13 | ▶ | method BUILD(@args) { | ||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.8
Pod
undocumented
Branch: 1 branch
| |||||||||||||||
| 45 | 13 | ▶ | if ( !$self->raw_response ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | 0 | $self->raw_response( $self->_empty_response ); | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | 8 | } | |||||||||||||
| 49 | |||||||||||||||
| 50 | 98 | ▶ | method _inflate() { | ||||||||||||
|
Subroutine
_inflate: called CC=4 SCAR=14.0
Branch: 2 branches
| |||||||||||||||
| 51 | 98 | ▶ | return if $self->_inflated; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | 12 | my $iterator = WebService::OpenSky::Utils::Iterator->new( rows => $self->_create_response_objects ); | |||||||||||||
| 53 | 12 | $self->_set_iterator($iterator); | |||||||||||||
| 54 | 12 | $self->_inflated(1); | |||||||||||||
| 55 | 8 | } | |||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | ▶ | method _create_response_iterator() { | ||||||||||||
|
Subroutine
_create_response_iterator: not called CC=3 SCAR=24.8
Branch: 2 branches
| |||||||||||||||
| 58 | 0 | croak 'This method must be implemented by a subclass'; | |||||||||||||
| 59 | 8 | } | |||||||||||||
| 60 | |||||||||||||||
| 61 | 0 | ▶ | method _empty_response() { | ||||||||||||
|
Subroutine
_empty_response: not called CC=3 SCAR=24.8
Branch: 2 branches
| |||||||||||||||
| 62 | 0 | croak 'This method must be implemented by a subclass'; | |||||||||||||
| 63 | 8 | } | |||||||||||||
| 64 | |||||||||||||||
| 65 | 50 | ▶ | method iterator() { | ||||||||||||
|
Subroutine
iterator: called CC=3 SCAR=11.2
Pod
documented
Branch: 2 branches
| |||||||||||||||
| 66 | 50 | $self->_inflate; | |||||||||||||
| 67 | 50 | return $self->_iterator; | |||||||||||||
| 68 | 8 | } | |||||||||||||
| 69 | |||||||||||||||
| 70 | 36 | ▶ | method next() { ## no critic (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||||
|
Subroutine
next: called CC=3 SCAR=11.2
Pod
documented
Branch: 2 branches
| |||||||||||||||
| 71 | 36 | $self->_inflate; | |||||||||||||
| 72 | 36 | return $self->iterator->next; | |||||||||||||
| 73 | 8 | } | |||||||||||||
| 74 | |||||||||||||||
| 75 | 0 | ▶ | method first() { | ||||||||||||
|
Subroutine
first: not called CC=3 SCAR=24.8
Pod
documented
Branch: 2 branches
| |||||||||||||||
| 76 | 0 | $self->_inflate; | |||||||||||||
| 77 | 0 | return $self->iterator->first; | |||||||||||||
| 78 | 8 | } | |||||||||||||
| 79 | |||||||||||||||
| 80 | 0 | ▶ | method reset() { ## no critic (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||||
|
Subroutine
reset: not called CC=3 SCAR=24.8
Pod
documented
Branch: 2 branches
| |||||||||||||||
| 81 | 0 | $self->_inflate; | |||||||||||||
| 82 | 0 | return $self->iterator->reset; | |||||||||||||
| 83 | 8 | } | |||||||||||||
| 84 | |||||||||||||||
| 85 | 0 | ▶ | method all() { | ||||||||||||
|
Subroutine
all: not called CC=3 SCAR=24.8
Pod
documented
Branch: 2 branches
| |||||||||||||||
| 86 | 0 | $self->_inflate; | |||||||||||||
| 87 | 0 | return $self->iterator->all; | |||||||||||||
| 88 | 8 | } | |||||||||||||
| 89 | |||||||||||||||
| 90 | 12 | ▶ | method count() { | ||||||||||||
|
Subroutine
count: called CC=3 SCAR=11.2
Pod
documented
Branch: 2 branches
| |||||||||||||||
| 91 | 12 | $self->_inflate; | |||||||||||||
| 92 | 12 | return $self->iterator->count; | |||||||||||||
| 93 | } | ||||||||||||||
| 94 | |||||||||||||||
| 95 | __END__ | ||||||||||||||