Skip to content

Commit 94673ac

Browse files
committed
handle_error : take exit_code + tidy
1 parent 7910662 commit 94673ac

File tree

5 files changed

+40
-33
lines changed

5 files changed

+40
-33
lines changed

bin/mirrors.pl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
# setup
2121
my $cpan = cpan_dir();
22-
my $es = MetaCPAN::ES->new( type => "mirror" );
23-
22+
my $es = MetaCPAN::ES->new( type => "mirror" );
2423

2524
index_mirrors();
2625

@@ -50,14 +49,13 @@ ()
5049
};
5150

5251
#Dlog_trace {"Indexing $_"} $mirror;
53-
log_debug {sprintf("Indexing %s", $mirror->{name})};
52+
log_debug { sprintf( "Indexing %s", $mirror->{name} ) };
5453

55-
my @doc =
56-
map { $_ => $mirror->{$_} }
54+
my @doc = map { $_ => $mirror->{$_} }
5755
grep { defined $mirror->{$_} }
5856
keys %$mirror;
5957

60-
$es->index( body => { @doc } );
58+
$es->index( body => {@doc} );
6159
}
6260
}
6361

bin/purge.pl

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,58 +21,67 @@
2121

2222
# setup
2323
my $type2index = {
24-
release => 'cpan',
25-
file => 'cpan',
26-
author => 'cpan',
27-
favorite => 'cpan',
28-
permission => 'cpan',
29-
contributor => 'contributor',
24+
release => 'cpan',
25+
file => 'cpan',
26+
author => 'cpan',
27+
favorite => 'cpan',
28+
permission => 'cpan',
29+
contributor => 'contributor',
3030
};
3131

32-
3332
purge_author() if $author;
3433

3534
log_info {'Done'};
3635

3736
sub purge_author () {
37+
3838
# confirm
3939
$release
40-
? are_you_sure( sprintf("%s's %s release is about to be purged!", $author, $release), $force )
41-
: are_you_sure( sprintf("All of %s's releases are about to be purged!", $author), $force );
40+
? are_you_sure(
41+
sprintf(
42+
"%s's %s release is about to be purged!", $author, $release
43+
),
44+
$force
45+
)
46+
: are_you_sure(
47+
sprintf( "All of %s's releases are about to be purged!", $author ),
48+
$force );
4249

4350
my $query = {
4451
bool => {
4552
must => [
4653
{ term => { author => $author } },
47-
( $release
48-
? { term => { release => $release } }
49-
: ()
54+
(
55+
$release
56+
? { term => { release => $release } }
57+
: ()
5058
)
5159
]
5260
}
5361
};
5462

55-
purge_ids( type => 'favorite', query => $query);
56-
purge_ids( type => 'file', query => $query);
57-
purge_ids( type => 'release', query => $query);
63+
purge_ids( type => 'favorite', query => $query );
64+
purge_ids( type => 'file', query => $query );
65+
purge_ids( type => 'release', query => $query );
5866
if ( !$release ) {
59-
purge_ids( type => 'author', id => $author );
67+
purge_ids( type => 'author', id => $author );
6068
purge_ids( type => 'contributor', id => $author );
6169
}
6270
}
6371

64-
sub purge_ids ( %args ) {
72+
sub purge_ids (%args) {
6573
my $type = $args{type};
66-
my $es = MetaCPAN::ES->new(
74+
my $es = MetaCPAN::ES->new(
6775
index => $type2index->{$type},
68-
type => $type
76+
type => $type
6977
);
7078

7179
my $bulk = $es->bulk;
7280

7381
my $id = $args{id};
74-
my $ids = $id
75-
? [ $id ]
82+
my $ids
83+
= $id
84+
? [$id]
7685
: $es->get_ids( query => $args{query} );
7786

7887
$bulk->delete_ids(@$ids);

bin/release.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
else {
217217
try { _import_archive( $file, $dist ) }
218218
catch {
219-
handle_error( "$file $_[0]", 1 );
219+
handle_error( 1, "$file $_[0]" );
220220
};
221221
}
222222
}

lib/MetaCPAN/ES.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ sub get_ids ( $self, %args ) {
129129
sub delete_ids ( $self, $ids ) {
130130
my $bulk = $self->bulk;
131131

132-
while ( my @batch = splice(@$ids, 0, 500) ) {
132+
while ( my @batch = splice( @$ids, 0, 500 ) ) {
133133
$bulk->delete_ids(@batch);
134134
}
135135

136136
$bulk->flush;
137137
}
138138

139-
sub clear_type ( $self ) {
139+
sub clear_type ($self) {
140140
my $ids = $self->get_ids();
141141

142142
$self->delete_ids(@$ids);

lib/MetaCPAN/Ingest.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ sub fix_version ($version) {
163163
return ( ( $v ? 'v' : '' ) . $version );
164164
}
165165

166-
sub handle_error ( $error, $die_always ) {
166+
sub handle_error ( $exit_code, $error, $die_always ) {
167167

168168
# Always log.
169169
log_fatal {$error};
170170

171-
$! = 1; ### $self->exit_code if ( $self->exit_code != 0 );
171+
$! = $exit_code;
172172

173173
Carp::croak $error if $die_always;
174174
}
@@ -224,7 +224,7 @@ sub read_url ( $url ) {
224224
my $ua = ua();
225225
my $resp = $ua->get($url);
226226

227-
handle_error( $resp->status_line, 1 ) unless $resp->is_success;
227+
handle_error(1, $resp->status_line, 1 ) unless $resp->is_success;
228228

229229
# clean up headers if .json.gz is served as gzip type
230230
# rather than json encoded with gzip

0 commit comments

Comments
 (0)