line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::BitbucketServer::Response; |
2
|
|
|
|
|
|
|
# ABSTRACT: A response object for Bitbucket Server REST APIs |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
109
|
|
6
|
4
|
|
|
4
|
|
15
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
116
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.605'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
1097
|
use Clone qw(clone); |
|
4
|
|
|
|
|
7114
|
|
|
4
|
|
|
|
|
179
|
|
11
|
4
|
|
|
4
|
|
25
|
use Types::Standard qw(HashRef Object); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
19
|
|
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
3332
|
use Moo; |
|
4
|
|
|
|
|
32396
|
|
|
4
|
|
|
|
|
15
|
|
14
|
4
|
|
|
4
|
|
5462
|
use namespace::clean; |
|
4
|
|
|
|
|
27116
|
|
|
4
|
|
|
|
|
18
|
|
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
0
|
|
0
|
sub _croak { require Carp; Carp::croak(@_) } |
|
0
|
|
|
|
|
0
|
|
17
|
0
|
|
|
0
|
|
0
|
sub _usage { _croak("Usage: @_\n") } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has context => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
isa => Object, |
23
|
|
|
|
|
|
|
required => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has request_args => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
isa => HashRef, |
30
|
|
|
|
|
|
|
required => 1, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has raw => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
isa => HashRef, |
37
|
|
|
|
|
|
|
required => 1, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has decoded_content => ( |
42
|
|
|
|
|
|
|
is => 'lazy', |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _build_decoded_content { |
46
|
2
|
|
|
2
|
|
17
|
my $self = shift; |
47
|
2
|
|
|
|
|
8
|
my $body = $self->raw->{content}; |
48
|
|
|
|
|
|
|
|
49
|
2
|
50
|
50
|
|
|
16
|
if (($self->raw->{headers}{'content-type'} || '') =~ /json/) { |
50
|
2
|
|
|
|
|
29
|
$body = $self->json->decode($body); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
64
|
return $body; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has json => ( |
58
|
|
|
|
|
|
|
is => 'lazy', |
59
|
|
|
|
|
|
|
isa => Object, |
60
|
|
|
|
|
|
|
default => sub { |
61
|
|
|
|
|
|
|
shift->context->json || do { |
62
|
|
|
|
|
|
|
require JSON::MaybeXS; |
63
|
|
|
|
|
|
|
JSON::MaybeXS->new(utf8 => 1); |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
}, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
4
|
|
|
4
|
1
|
6400
|
sub is_success { shift->raw->{success} } |
70
|
2
|
|
|
2
|
1
|
281
|
sub status { shift->raw->{status} } |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub error { |
74
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
2
|
50
|
|
|
|
6
|
return if $self->is_success; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
0
|
return $self->decoded_content; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub data { |
83
|
2
|
|
|
2
|
1
|
2121
|
my $self = shift; |
84
|
|
|
|
|
|
|
|
85
|
2
|
100
|
|
|
|
7
|
return $self->decoded_content->{values} if $self->is_paged; |
86
|
1
|
|
|
|
|
32
|
return $self->decoded_content; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
0
|
0
|
sub info { shift->data(@_) } |
90
|
0
|
|
|
0
|
0
|
0
|
sub value { shift->data(@_) } |
91
|
0
|
|
|
0
|
0
|
0
|
sub values { shift->data(@_) } |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
4
|
|
|
4
|
1
|
79
|
sub is_paged { !!shift->page_info } |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
has page_info => ( |
98
|
|
|
|
|
|
|
is => 'lazy', |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _build_page_info { |
102
|
2
|
|
|
2
|
|
19
|
my $self = shift; |
103
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
40
|
my $content = $self->decoded_content; |
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
9
|
my @envelope_keys = qw(isLastPage limit size start values); |
107
|
|
|
|
|
|
|
return if $self->request_args->{method} ne 'GET' || |
108
|
2
|
100
|
33
|
|
|
21
|
ref($content) ne 'HASH' || @envelope_keys != grep { exists $content->{$_} } @envelope_keys; |
|
10
|
|
66
|
|
|
23
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
return { |
111
|
|
|
|
|
|
|
filter => $content->{filter}, |
112
|
|
|
|
|
|
|
is_last_page => $content->{isLastPage}, |
113
|
|
|
|
|
|
|
limit => $content->{limit}, |
114
|
|
|
|
|
|
|
next_page_start => $content->{nextPageStart}, |
115
|
|
|
|
|
|
|
size => $content->{size}, |
116
|
|
|
|
|
|
|
start => $content->{start}, |
117
|
1
|
|
|
|
|
18
|
}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub next { |
122
|
2
|
|
|
2
|
1
|
8708
|
my $self = shift; |
123
|
|
|
|
|
|
|
|
124
|
2
|
100
|
|
|
|
38
|
return if not my $page_info = $self->page_info; |
125
|
|
|
|
|
|
|
|
126
|
1
|
50
|
33
|
|
|
10
|
return if $page_info->{is_last_page} || !$page_info->{next_page_start}; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $args = clone($self->request_args); |
129
|
0
|
|
|
|
|
|
$args->{data}{start} = $page_info->{next_page_start}; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
return $self->context->call($args); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub wrap { |
136
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
137
|
0
|
0
|
|
|
|
|
my $field = shift or _usage(qw{$response->wrap($field)}); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
return __PACKAGE__->new( |
140
|
|
|
|
|
|
|
context => $self->context, |
141
|
|
|
|
|
|
|
request_args => $self->request_args, |
142
|
|
|
|
|
|
|
raw => $self->raw, |
143
|
0
|
|
|
|
|
|
decoded_content => $self->data->{$field}, |
144
|
|
|
|
|
|
|
json => $self->json, |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
__END__ |