Skip to content

Commit 9b3ad40

Browse files
committed
use real booleans when interacting with Elasticsearch
Fixes #1273
1 parent 8bbdd3e commit 9b3ad40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+248
-199
lines changed

lib/MetaCPAN/Document/Author.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use MetaCPAN::Types::TypeTiny qw(
1313
ArrayRef
1414
ArrayRefPromote
1515
Blog
16-
Bool
16+
ESBool
1717
Dict
1818
HashRef
1919
NonEmptySimpleStr
@@ -105,9 +105,9 @@ has updated => (
105105

106106
has is_pause_custodial_account => (
107107
is => 'ro',
108-
isa => Bool,
108+
isa => ESBool,
109109
coerce => 1,
110-
default => 0,
110+
default => sub {false},
111111
);
112112

113113
sub _build_gravatar_url {

lib/MetaCPAN/Document/Distribution.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use Moose;
88
use ElasticSearchX::Model::Document;
99

1010
use MetaCPAN::Types::TypeTiny qw( BugSummary RiverSummary );
11+
use MetaCPAN::Util qw(true false);
1112

1213
has name => (
1314
is => 'ro',
@@ -49,11 +50,11 @@ sub set_first_release {
4950
my @releases = $self->releases->sort( ["date"] )->all;
5051

5152
my $first = shift @releases;
52-
$first->_set_first(1);
53+
$first->_set_first(true);
5354
$first->put;
5455

5556
for my $rel (@releases) {
56-
$rel->_set_first(0);
57+
$rel->_set_first(false);
5758
$rel->put;
5859
}
5960

lib/MetaCPAN/Document/File.pm

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ use MetaCPAN::Document::Module ();
1212
use MetaCPAN::Types qw( Module );
1313
use MetaCPAN::Types::TypeTiny qw(
1414
ArrayRef
15-
Bool
15+
ESBool
1616
Int
1717
Maybe
1818
Num
1919
ScalarRef
2020
Stat
2121
Str
2222
);
23-
use MetaCPAN::Util qw(numify_version);
23+
use MetaCPAN::Util qw(numify_version true false);
2424
use Plack::MIME ();
2525
use Pod::Text ();
2626
use Try::Tiny qw( catch try );
@@ -50,8 +50,8 @@ it is also set if the entire release is marked deprecated (see L<MetaCPAN::Docum
5050

5151
has deprecated => (
5252
is => 'ro',
53-
isa => Bool,
54-
default => 0,
53+
isa => ESBool,
54+
default => sub {false},
5555
writer => '_set_deprecated',
5656
);
5757

@@ -260,9 +260,9 @@ File is binary or not.
260260

261261
has binary => (
262262
is => 'ro',
263-
isa => Bool,
263+
isa => ESBool,
264264
required => 1,
265-
default => 0,
265+
default => sub {false},
266266
);
267267

268268
=head2 authorized
@@ -274,8 +274,8 @@ See L</set_authorized>.
274274
has authorized => (
275275
required => 1,
276276
is => 'ro',
277-
isa => Bool,
278-
default => 1,
277+
isa => ESBool,
278+
default => sub {true},
279279
writer => '_set_authorized',
280280
);
281281

@@ -301,8 +301,8 @@ Return true if this object represents a directory.
301301
has directory => (
302302
is => 'ro',
303303
required => 1,
304-
isa => Bool,
305-
default => 0,
304+
isa => ESBool,
305+
default => sub {false},
306306
);
307307

308308
=head2 documentation
@@ -433,13 +433,13 @@ not. See L</set_indexed> for a more verbose explanation.
433433
has indexed => (
434434
required => 1,
435435
is => 'ro',
436-
isa => Bool,
436+
isa => ESBool,
437437
lazy => 1,
438438
default => sub {
439439
my ($self) = @_;
440-
return 0 if $self->is_in_other_files;
441-
return 0 if !$self->metadata->should_index_file( $self->path );
442-
return 1;
440+
return false if $self->is_in_other_files;
441+
return false if !$self->metadata->should_index_file( $self->path );
442+
return true;
443443
},
444444
writer => '_set_indexed',
445445
);
@@ -897,24 +897,24 @@ sub set_indexed {
897897
if ( exists $meta->provides->{ $mod->name }
898898
and $self->path eq $meta->provides->{ $mod->name }{file} )
899899
{
900-
$mod->_set_indexed(1);
900+
$mod->_set_indexed(true);
901901
return;
902902
}
903903
}
904904

905905
# files listed under 'other files' are not shown in a search
906906
if ( $self->is_in_other_files() ) {
907907
foreach my $mod ( @{ $self->module } ) {
908-
$mod->_set_indexed(0);
908+
$mod->_set_indexed(false);
909909
}
910-
$self->_set_indexed(0);
910+
$self->_set_indexed(false);
911911
return;
912912
}
913913

914914
# files under no_index directories should not be indexed
915915
foreach my $dir ( @{ $meta->no_index->{directory} } ) {
916916
if ( $self->path eq $dir or $self->path =~ /^$dir\// ) {
917-
$self->_set_indexed(0);
917+
$self->_set_indexed(false);
918918
return;
919919
}
920920
}
@@ -923,24 +923,26 @@ sub set_indexed {
923923
if ( $mod->name !~ /^[A-Za-z]/
924924
or !$meta->should_index_package( $mod->name ) )
925925
{
926-
$mod->_set_indexed(0);
926+
$mod->_set_indexed(false);
927927
next;
928928
}
929929

930930
$mod->_set_indexed(
931931
$mod->hide_from_pause( ${ $self->content }, $self->name )
932-
? 0
933-
: 1
932+
? false
933+
: true
934934
);
935935
}
936936

937937
$self->_set_indexed(
938+
(
938939

939-
# .pm file with no package declaration but pod should be indexed
940-
!@{ $self->module } ||
940+
# .pm file with no package declaration but pod should be indexed
941+
!@{ $self->module } ||
941942

942943
# don't index if the documentation doesn't match any of its modules
943-
!!grep { $self->documentation eq $_->name } @{ $self->module }
944+
!!grep { $self->documentation eq $_->name } @{ $self->module }
945+
) ? true : false
944946
) if ( $self->documentation );
945947
}
946948

@@ -974,18 +976,18 @@ sub set_authorized {
974976
if ( $self->distribution eq 'perl' ) {
975977
my $allowed = grep $_ eq $self->author, @{ $perms->{perl} };
976978
foreach my $module ( @{ $self->module } ) {
977-
$module->_set_authorized($allowed);
979+
$module->_set_authorized( $allowed ? true : false );
978980
}
979-
$self->_set_authorized($allowed);
981+
$self->_set_authorized( $allowed ? true : false );
980982
}
981983
else {
982984
foreach my $module ( @{ $self->module } ) {
983-
$module->_set_authorized(0)
985+
$module->_set_authorized(false)
984986
if ( $perms->{ $module->name }
985987
&& !grep { $_ eq $self->author }
986988
@{ $perms->{ $module->name } } );
987989
}
988-
$self->_set_authorized(0)
990+
$self->_set_authorized(false)
989991
if ( $self->authorized
990992
&& $self->documentation
991993
&& $perms->{ $self->documentation }

lib/MetaCPAN/Document/File/Set.pm

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use List::Util qw( max );
66
use MetaCPAN::Query::Favorite ();
77
use MetaCPAN::Query::File ();
88
use MetaCPAN::Query::Release ();
9-
use MetaCPAN::Util qw( single_valued_arrayref_to_scalar );
9+
use MetaCPAN::Util qw( single_valued_arrayref_to_scalar true false );
1010

1111
extends 'ElasticSearchX::Model::Document::Set';
1212

@@ -78,8 +78,8 @@ sub find {
7878
my @candidates = $self->index->type('file')->query( {
7979
bool => {
8080
must => [
81-
{ term => { indexed => 1 } },
82-
{ term => { authorized => 1 } },
81+
{ term => { indexed => true } },
82+
{ term => { authorized => true } },
8383
{ term => { status => 'latest' } },
8484
{
8585
bool => {
@@ -100,8 +100,8 @@ sub find {
100100
[
101101
{ term =>
102102
{ "module.authorized"
103-
=> 1 }
104-
},
103+
=> true
104+
} },
105105
{ exists =>
106106
{ field =>
107107
'module.associated_pod'
@@ -175,7 +175,10 @@ sub documented_modules {
175175
exists =>
176176
{ field => 'module.name' }
177177
},
178-
{ term => { 'module.indexed' => 1 } },
178+
{
179+
term =>
180+
{ 'module.indexed' => true }
181+
},
179182
],
180183
}
181184
},
@@ -186,7 +189,7 @@ sub documented_modules {
186189
exists =>
187190
{ field => 'pod.analyzed' }
188191
},
189-
{ term => { indexed => 1 } },
192+
{ term => { indexed => true } },
190193
],
191194
}
192195
},
@@ -217,8 +220,8 @@ sub history {
217220
filter => {
218221
bool => {
219222
must => [
220-
{ term => { "module.authorized" => 1 } },
221-
{ term => { "module.indexed" => 1 } },
223+
{ term => { "module.authorized" => true } },
224+
{ term => { "module.indexed" => true } },
222225
{ term => { "module.name" => $module } },
223226
]
224227
}
@@ -242,8 +245,8 @@ sub history {
242245
bool => {
243246
must => [
244247
{ match_phrase => { documentation => $module } },
245-
{ term => { indexed => 1 } },
246-
{ term => { authorized => 1 } },
248+
{ term => { indexed => true } },
249+
{ term => { authorized => true } },
247250
]
248251
}
249252
} )
@@ -252,8 +255,8 @@ sub history {
252255
: $self->query(
253256
bool => {
254257
must => [
255-
{ term => { indexed => 1 } },
256-
{ term => { authorized => 1 } },
258+
{ term => { indexed => true } },
259+
{ term => { authorized => true } },
257260
]
258261
}
259262
);
@@ -279,8 +282,8 @@ sub autocomplete {
279282
},
280283
{ exists => { field => 'documentation' } },
281284
{ term => { status => 'latest' } },
282-
{ term => { indexed => 1 } },
283-
{ term => { authorized => 1 } }
285+
{ term => { indexed => true } },
286+
{ term => { authorized => true } }
284287
],
285288
must_not =>
286289
[ { terms => { distribution => \@ROGUE_DISTRIBUTIONS } }, ],
@@ -340,8 +343,8 @@ sub autocomplete_suggester {
340343
query => {
341344
bool => {
342345
must => [
343-
{ term => { indexed => 1 } },
344-
{ term => { authorized => 1 } },
346+
{ term => { indexed => true } },
347+
{ term => { authorized => true } },
345348
{ term => { status => 'latest' } },
346349
{ terms => { documentation => [ keys %docs ] } },
347350
],
@@ -390,7 +393,7 @@ sub autocomplete_suggester {
390393
sub find_changes_files {
391394
my ( $self, $author, $release ) = @_;
392395
my $result = $self->files_by_category( $author, $release, ['changelog'],
393-
{ fields => \1 } );
396+
{ fields => true } );
394397
my ($file) = @{ $result->{categories}{changelog} || [] };
395398
return $file;
396399
}

lib/MetaCPAN/Document/Module.pm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use ElasticSearchX::Model::Document;
88

99
with 'ElasticSearchX::Model::Document::EmbeddedRole';
1010

11-
use MetaCPAN::Types::TypeTiny qw( Bool Maybe Num Str );
12-
use MetaCPAN::Util;
11+
use MetaCPAN::Types::TypeTiny qw( ESBool Maybe Num Str );
12+
use MetaCPAN::Util qw(true false);
1313

1414
=head1 SYNOPSIS
1515
@@ -73,16 +73,16 @@ has version => ( is => 'ro' );
7373
has indexed => (
7474
is => 'ro',
7575
required => 1,
76-
isa => Bool,
77-
default => 1,
76+
isa => ESBool,
77+
default => sub {true},
7878
writer => '_set_indexed',
7979
);
8080

8181
has authorized => (
8282
is => 'ro',
8383
required => 1,
84-
isa => Bool,
85-
default => 1,
84+
isa => ESBool,
85+
default => sub {true},
8686
writer => '_set_authorized',
8787
);
8888

0 commit comments

Comments
 (0)