TeamCity/Iterator.pm

filter: Statementstmt 100% 45 / 45 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 100% 61 / 61 CC 5 SCAR 6.9
CC
5
Cov
100%
next
3.0
_fetch_more
3.0
BEGIN
1.0
CRAP 2.0
« TeamCity/Inflator.pm ↑ Summary TeamCity.pm »
1 package WebService::TeamCity::Iterator;
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 Types::Standard qw( ArrayRef HashRef InstanceOf Int Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 has client => (
15 is => 'ro',
16 isa => InstanceOf ['WebService::TeamCity'],
17 required => 1,
18 );
19  
20 4 has class => (
21 is => 'ro',
22 isa => Str,
23 required => 1,
24 );
25  
26 4 has items_key => (
27 is => 'ro',
28 isa => Str,
29 required => 1,
30 );
31  
32 4 has _next_href => (
33 is => 'rw',
34 isa => Str,
35 init_arg => 'next_href',
36 predicate => '_has_next_href',
37 clearer => '_clear_next_href',
38 );
39  
40 4 has _items => (
41 is => 'ro',
42 isa => ArrayRef [HashRef],
43 init_arg => 'items',
44 required => 1,
45 );
46  
47 4 has _i => (
48 is => 'rw',
49 isa => Int,
50 default => 0,
51 );
52  
53 ## no critic (Subroutines::ProhibitBuiltinHomonyms)
54 453 ▶sub next {
Subroutine next: called CC=3 SCAR=11.0
55 453 my $self = shift;
56  
57 453 my $items = $self->_items;
58 453 my $i = $self->_i;
59  
60 453 ▶ if ( $i >= @{$items} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= @{$items;}) 7 446 453
61 7 ▶ $self->_fetch_more
Branch: 1 branch
BranchTrueFalseTotal
$self->_fetch_more or return undef 3 4 7
62 or return undef;
63 }
64 my $obj = $self->class->new(
65 client => $self->client,
66 449 %{ $items->[$i] },
67 );
68 449 $self->_i( $i + 1 );
69  
70 449 return $obj;
71 }
72 ## use critic
73  
74 7 ▶sub _fetch_more {
Subroutine _fetch_more: called CC=3 SCAR=11.0
75 7 my $self = shift;
76  
77 7 ▶ return 0 unless $self->_has_next_href;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_next_href 4 3 7
78  
79 3 my $raw = $self->client->decoded_json_for(
80 uri => $self->client->base_uri . $self->_next_href );
81  
82 3 push @{ $self->_items }, @{ $raw->{ $self->items_key } };
83  
84 3 ▶ if ( $raw->{next_href} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw->{'next_href'}) { } 1 2 3
85 1 $self->_next_href( $raw->{next_href} );
86 }
87 else {
88 2 $self->_clear_next_href;
89 }
90  
91 3 return 1;
92 }
93  
94 4 1;
95  
96 # ABSTRACT: Generic object iterator for paged results from the TeamCity REST API
97  
98 __END__
« TeamCity/Inflator.pm ↑ Summary TeamCity.pm »