line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bintray::API::Version; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
####################### |
4
|
|
|
|
|
|
|
# LOAD CORE MODULES |
5
|
|
|
|
|
|
|
####################### |
6
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
8
|
1
|
|
|
1
|
|
3
|
use Carp qw(croak carp); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
51
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
####################### |
11
|
|
|
|
|
|
|
# VERSION |
12
|
|
|
|
|
|
|
####################### |
13
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
####################### |
16
|
|
|
|
|
|
|
# LOAD CPAN MODULES |
17
|
|
|
|
|
|
|
####################### |
18
|
1
|
|
|
1
|
|
11
|
use Params::Validate qw(validate_with :types); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
121
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
8
|
use Object::Tiny qw( |
21
|
|
|
|
|
|
|
name |
22
|
|
|
|
|
|
|
session |
23
|
|
|
|
|
|
|
package |
24
|
1
|
|
|
1
|
|
5
|
); |
|
1
|
|
|
|
|
1
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
####################### |
27
|
|
|
|
|
|
|
# LOAD DIST MODULES |
28
|
|
|
|
|
|
|
####################### |
29
|
1
|
|
|
1
|
|
143
|
use Bintray::API::Session; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
####################### |
32
|
|
|
|
|
|
|
# PUBLIC METHODS |
33
|
|
|
|
|
|
|
####################### |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
## Constructor |
36
|
|
|
|
|
|
|
sub new { |
37
|
0
|
|
|
0
|
0
|
|
my ( $class, @args ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my %opts = validate_with( |
40
|
|
|
|
|
|
|
params => [@args], |
41
|
|
|
|
|
|
|
spec => { |
42
|
|
|
|
|
|
|
session => { |
43
|
|
|
|
|
|
|
type => OBJECT, |
44
|
|
|
|
|
|
|
isa => 'Bintray::API::Session', |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
name => { |
47
|
|
|
|
|
|
|
type => SCALAR, |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
package => { |
50
|
|
|
|
|
|
|
type => OBJECT, |
51
|
|
|
|
|
|
|
isa => 'Bintray::API::Package', |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return $class->SUPER::new(%opts); |
57
|
|
|
|
|
|
|
} ## end sub new |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
####################### |
60
|
|
|
|
|
|
|
# API METHODS |
61
|
|
|
|
|
|
|
####################### |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
## Info |
64
|
|
|
|
|
|
|
sub info { |
65
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
66
|
0
|
|
|
|
|
|
return $self->session()->talk( |
67
|
|
|
|
|
|
|
path => join( '/', |
68
|
|
|
|
|
|
|
'packages', $self->package->repo->subject->name, |
69
|
|
|
|
|
|
|
$self->package->repo->name, $self->package->name, |
70
|
|
|
|
|
|
|
'versions', $self->name, |
71
|
|
|
|
|
|
|
), |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
} ## end sub info |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
## Update Version |
76
|
|
|
|
|
|
|
sub update { |
77
|
0
|
|
|
0
|
0
|
|
my ( $self, @args ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my %opts = validate_with( |
80
|
|
|
|
|
|
|
params => [@args], |
81
|
|
|
|
|
|
|
spec => { |
82
|
|
|
|
|
|
|
details => { |
83
|
|
|
|
|
|
|
type => HASHREF, |
84
|
|
|
|
|
|
|
}, |
85
|
|
|
|
|
|
|
}, |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Create JSON |
89
|
0
|
|
|
|
|
|
my $json = $self->session()->json()->encode( $opts{details} ); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# POST |
92
|
0
|
|
|
|
|
|
return $self->session()->talk( |
93
|
|
|
|
|
|
|
method => 'PATCH', |
94
|
|
|
|
|
|
|
path => join( '/', |
95
|
|
|
|
|
|
|
'packages', $self->package->repo->subject->name, |
96
|
|
|
|
|
|
|
$self->package->repo->name, $self->package->name, |
97
|
|
|
|
|
|
|
'versions', $self->name, |
98
|
|
|
|
|
|
|
), |
99
|
|
|
|
|
|
|
content => $json, |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
} ## end sub update |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
## Get Attributes |
104
|
|
|
|
|
|
|
sub get_attributes { |
105
|
0
|
|
|
0
|
0
|
|
my ( $self, @args ) = @_; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my %opts = validate_with( |
108
|
|
|
|
|
|
|
params => [@args], |
109
|
|
|
|
|
|
|
spec => { |
110
|
|
|
|
|
|
|
names => { |
111
|
|
|
|
|
|
|
type => ARRAYREF, |
112
|
|
|
|
|
|
|
default => [], |
113
|
|
|
|
|
|
|
}, |
114
|
|
|
|
|
|
|
}, |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return $self->session->talk( |
118
|
|
|
|
|
|
|
path => join( '/', |
119
|
|
|
|
|
|
|
'packages', $self->package->repo->subject->name, |
120
|
|
|
|
|
|
|
$self->package->repo->name, $self->package->name, |
121
|
|
|
|
|
|
|
'versions', $self->name, |
122
|
|
|
|
|
|
|
'attributes', ), ( |
123
|
|
|
|
|
|
|
defined $opts{names} |
124
|
|
|
|
|
|
|
? ( |
125
|
|
|
|
|
|
|
query => [ |
126
|
|
|
|
|
|
|
{ |
127
|
0
|
0
|
|
|
|
|
names => join( ',', @{ $opts{names} } ), |
128
|
|
|
|
|
|
|
}, |
129
|
|
|
|
|
|
|
], |
130
|
|
|
|
|
|
|
) |
131
|
|
|
|
|
|
|
: (), |
132
|
|
|
|
|
|
|
), |
133
|
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
} ## end sub get_attributes |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Set Attributes |
137
|
|
|
|
|
|
|
sub set_attributes { |
138
|
0
|
|
|
0
|
0
|
|
my ( $self, @args ) = @_; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
my %opts = validate_with( |
141
|
|
|
|
|
|
|
params => [@args], |
142
|
|
|
|
|
|
|
spec => { |
143
|
|
|
|
|
|
|
attributes => { |
144
|
|
|
|
|
|
|
type => ARRAYREF, |
145
|
|
|
|
|
|
|
}, |
146
|
|
|
|
|
|
|
update => { |
147
|
|
|
|
|
|
|
type => BOOLEAN, |
148
|
|
|
|
|
|
|
default => 0, |
149
|
|
|
|
|
|
|
}, |
150
|
|
|
|
|
|
|
}, |
151
|
|
|
|
|
|
|
); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# Create JSON |
154
|
0
|
|
|
|
|
|
my $json = $self->session()->json()->encode( $opts{attributes} ); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# POST |
157
|
0
|
0
|
|
|
|
|
return $self->session()->talk( |
158
|
|
|
|
|
|
|
method => $opts{update} ? 'PATCH' : 'POST', |
159
|
|
|
|
|
|
|
path => join( '/', |
160
|
|
|
|
|
|
|
'packages', $self->package->repo->subject->name, |
161
|
|
|
|
|
|
|
$self->package->repo->name, $self->package->name, |
162
|
|
|
|
|
|
|
'versions', $self->name, |
163
|
|
|
|
|
|
|
'attributes', ), |
164
|
|
|
|
|
|
|
content => $json, |
165
|
|
|
|
|
|
|
); |
166
|
|
|
|
|
|
|
} ## end sub set_attributes |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
## Update Attributes |
169
|
0
|
|
|
0
|
0
|
|
sub update_attributes { return shift->set_attributes( @_, update => 1, ); } |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
## Test WebHook |
172
|
|
|
|
|
|
|
sub test_webhook { |
173
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
174
|
0
|
|
|
|
|
|
return $self->session()->talk( |
175
|
|
|
|
|
|
|
method => 'POST', |
176
|
|
|
|
|
|
|
path => join( '/', |
177
|
|
|
|
|
|
|
'webhooks', $self->package->repo->subject->name, |
178
|
|
|
|
|
|
|
$self->package->repo->name, $self->package->name, |
179
|
|
|
|
|
|
|
'versions', $self->name, |
180
|
|
|
|
|
|
|
), |
181
|
|
|
|
|
|
|
wantheaders => 1, |
182
|
|
|
|
|
|
|
); |
183
|
|
|
|
|
|
|
} ## end sub test_webhook |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
## Upload |
186
|
|
|
|
|
|
|
sub upload { |
187
|
0
|
|
|
0
|
0
|
|
my ( $self, @args ) = @_; |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
my %opts = validate_with( |
190
|
|
|
|
|
|
|
params => [@args], |
191
|
|
|
|
|
|
|
spec => { |
192
|
|
|
|
|
|
|
file => { |
193
|
|
|
|
|
|
|
type => SCALAR, |
194
|
|
|
|
|
|
|
}, |
195
|
|
|
|
|
|
|
repo_path => { |
196
|
|
|
|
|
|
|
type => SCALAR, |
197
|
|
|
|
|
|
|
}, |
198
|
|
|
|
|
|
|
publish => { |
199
|
|
|
|
|
|
|
type => BOOLEAN, |
200
|
|
|
|
|
|
|
default => 0, |
201
|
|
|
|
|
|
|
}, |
202
|
|
|
|
|
|
|
explode => { |
203
|
|
|
|
|
|
|
type => BOOLEAN, |
204
|
|
|
|
|
|
|
default => 0, |
205
|
|
|
|
|
|
|
}, |
206
|
|
|
|
|
|
|
}, |
207
|
|
|
|
|
|
|
); |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# Read File contents |
210
|
0
|
|
|
|
|
|
my $file_contents; |
211
|
0
|
0
|
|
|
|
|
open( my $fh, '<:raw', $opts{file} ) |
212
|
|
|
|
|
|
|
or croak "ERROR: Failed to open $opts{file} to read!"; |
213
|
0
|
|
|
|
|
|
my $fs = -s $fh; |
214
|
0
|
|
|
|
|
|
read( $fh, $file_contents, $fs ); |
215
|
0
|
|
|
|
|
|
close($fh); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# Cleanup Repo Path |
218
|
0
|
|
|
|
|
|
$opts{repo_path} =~ s{^\/}{}xi; |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
# Upload |
221
|
0
|
0
|
|
|
|
|
return $self->session->talk( |
|
|
0
|
|
|
|
|
|
222
|
|
|
|
|
|
|
method => 'PUT', |
223
|
|
|
|
|
|
|
path => join( '/', |
224
|
|
|
|
|
|
|
'content', $self->package->repo->subject->name, |
225
|
|
|
|
|
|
|
$self->package->repo->name, $self->package->name, |
226
|
|
|
|
|
|
|
$self->name, $opts{repo_path}, |
227
|
|
|
|
|
|
|
), |
228
|
|
|
|
|
|
|
content => $file_contents, |
229
|
|
|
|
|
|
|
params => [ |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# Publish? |
232
|
|
|
|
|
|
|
( defined $opts{publish} ? { publish => $opts{publish} } : (), ), |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
# Explode? |
235
|
|
|
|
|
|
|
( defined $opts{explode} ? { explode => $opts{explode} } : (), ), |
236
|
|
|
|
|
|
|
], |
237
|
|
|
|
|
|
|
); |
238
|
|
|
|
|
|
|
} ## end sub upload |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
## Publish files |
241
|
|
|
|
|
|
|
sub publish { |
242
|
0
|
|
|
0
|
0
|
|
my ( $self, @args ) = @_; |
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
my %opts = validate_with( |
245
|
|
|
|
|
|
|
params => [@args], |
246
|
|
|
|
|
|
|
spec => { |
247
|
|
|
|
|
|
|
discard => { |
248
|
|
|
|
|
|
|
type => BOOLEAN, |
249
|
|
|
|
|
|
|
default => 0, |
250
|
|
|
|
|
|
|
}, |
251
|
|
|
|
|
|
|
}, |
252
|
|
|
|
|
|
|
); |
253
|
|
|
|
|
|
|
|
254
|
0
|
0
|
|
|
|
|
return $self->session->talk( |
255
|
|
|
|
|
|
|
method => 'POST', |
256
|
|
|
|
|
|
|
path => join( '/', |
257
|
|
|
|
|
|
|
'content', $self->package->repo->subject->name, |
258
|
|
|
|
|
|
|
$self->package->repo->name, $self->package->name, |
259
|
|
|
|
|
|
|
$self->name, 'publish', |
260
|
|
|
|
|
|
|
), ( |
261
|
|
|
|
|
|
|
# Check for discard |
262
|
|
|
|
|
|
|
$opts{discard} |
263
|
|
|
|
|
|
|
? ( content => |
264
|
|
|
|
|
|
|
$self->session->json->encode( { discard => 'true' } ) ) |
265
|
|
|
|
|
|
|
: (), |
266
|
|
|
|
|
|
|
), |
267
|
|
|
|
|
|
|
); |
268
|
|
|
|
|
|
|
} ## end sub publish |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
## Discard files |
271
|
0
|
|
|
0
|
0
|
|
sub discard { return shift->publish( @_, discard => 1, ); } |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
## Sign a Version |
274
|
|
|
|
|
|
|
sub sign { |
275
|
0
|
|
|
0
|
0
|
|
my ( $self, @args ) = @_; |
276
|
0
|
|
|
|
|
|
my %opts = validate_with( |
277
|
|
|
|
|
|
|
params => [@_], |
278
|
|
|
|
|
|
|
spec => { |
279
|
|
|
|
|
|
|
passphrase => { |
280
|
|
|
|
|
|
|
type => SCALAR, |
281
|
|
|
|
|
|
|
default => '', |
282
|
|
|
|
|
|
|
}, |
283
|
|
|
|
|
|
|
}, |
284
|
|
|
|
|
|
|
); |
285
|
|
|
|
|
|
|
|
286
|
0
|
0
|
|
|
|
|
return $self->session()->talk( |
287
|
|
|
|
|
|
|
method => 'POST', |
288
|
|
|
|
|
|
|
path => join( '/', |
289
|
|
|
|
|
|
|
'gpg', $self->package->repo->subject->name, |
290
|
|
|
|
|
|
|
$self->package->repo->name, $self->package->name, |
291
|
|
|
|
|
|
|
'versions', $self->name, |
292
|
|
|
|
|
|
|
), ( |
293
|
|
|
|
|
|
|
$opts{passphrase} |
294
|
|
|
|
|
|
|
? ( |
295
|
|
|
|
|
|
|
query => [ |
296
|
|
|
|
|
|
|
{ |
297
|
|
|
|
|
|
|
passphrase => $opts{passphrase}, |
298
|
|
|
|
|
|
|
}, |
299
|
|
|
|
|
|
|
], |
300
|
|
|
|
|
|
|
) |
301
|
|
|
|
|
|
|
: (), |
302
|
|
|
|
|
|
|
), |
303
|
|
|
|
|
|
|
); |
304
|
|
|
|
|
|
|
} ## end sub sign |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
####################### |
307
|
|
|
|
|
|
|
1; |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
__END__ |