| 1 | package WebService::TeamCity::Inflator; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | our $VERSION = '0.04'; | |||||||||
| 9 | |||||||||||
| 10 | 4 | ▶ | use WebService::TeamCity::Iterator; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 4 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 4 | requires 'client'; | |||||||||
| 15 | |||||||||||
| 16 | ## no critic (ProhibitUnusedPrivateSubroutines) | ||||||||||
| 17 | 7 | ▶ | sub _inflate_array { | ||||||||
|
Subroutine
_inflate_array: called CC=2 SCAR=6.9
| |||||||||||
| 18 | 7 | my $self = shift; | |||||||||
| 19 | 7 | my $raw = shift; | |||||||||
| 20 | |||||||||||
| 21 | 7 | ▶ | return [] unless $raw; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 6 | return [ map { $self->_inflate_one( $_, @_ ) } @{$raw} ]; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 912 | ▶ | sub _inflate_one { | ||||||||
|
Subroutine
_inflate_one: called CC=3 SCAR=11.0
| |||||||||||
| 26 | 912 | my $self = shift; | |||||||||
| 27 | 912 | my $raw = shift; | |||||||||
| 28 | 912 | my $class = shift; | |||||||||
| 29 | 912 | my $self_key = shift; | |||||||||
| 30 | |||||||||||
| 31 | 912 | ▶ | return unless $raw; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | return ( 'WebService::TeamCity::Entity::' . $class )->new( | ||||||||||
| 34 | 912 | ▶ | %{$raw}, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | client => $self->client, | ||||||||||
| 36 | ( $self_key ? ( $self_key => $self ) : () ), | ||||||||||
| 37 | ); | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 9 | ▶ | sub _iterator_for { | ||||||||
|
Subroutine
_iterator_for: called CC=4 SCAR=13.9
| |||||||||||
| 41 | 9 | my $self = shift; | |||||||||
| 42 | 9 | my $uri = shift; | |||||||||
| 43 | 9 | my $items_key = shift; | |||||||||
| 44 | 9 | my $class = shift; | |||||||||
| 45 | |||||||||||
| 46 | 9 | my $raw = $self->client->decoded_json_for( uri => $uri ); | |||||||||
| 47 | |||||||||||
| 48 | 9 | my %args = ( | |||||||||
| 49 | client => $self->client, | ||||||||||
| 50 | class => 'WebService::TeamCity::Entity::' . $class, | ||||||||||
| 51 | items_key => $items_key, | ||||||||||
| 52 | items => [], | ||||||||||
| 53 | ); | ||||||||||
| 54 | |||||||||||
| 55 | 9 | ▶ | if ($raw) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | $args{next_href} = $raw->{next_href} | ||||||||||
| 57 | 9 | ▶ | if $raw->{next_href}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | $args{items} = $raw->{$items_key} | ||||||||||
| 59 | 9 | ▶ | if $raw->{$items_key}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 9 | return WebService::TeamCity::Iterator->new(%args); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 4 | 1; | |||||||||
| 66 | |||||||||||
| 67 | # ABSTRACT: Role for any class that inflates REST API objects from JSON | ||||||||||
| 68 | |||||||||||
| 69 | __END__ | ||||||||||