Skip to content

Commit e6e9fa2

Browse files
committed
use real booleans when interacting with Elasticsearch
Fixes #1273
1 parent 6679936 commit e6e9fa2

Some content is hidden

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

43 files changed

+269
-217
lines changed

lib/MetaCPAN/Document/Author.pm

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

99
# load order not important
1010
use Gravatar::URL ();
11-
use MetaCPAN::Types qw( Profile );
11+
use MetaCPAN::Types qw( ESBool Profile );
1212
use MetaCPAN::Types::TypeTiny qw(
1313
ArrayRef
1414
ArrayRefPromote
1515
Blog
16-
Bool
1716
Dict
1817
HashRef
1918
NonEmptySimpleStr
2019
PerlMongers
2120
Str
2221
);
23-
use MetaCPAN::Util;
22+
use MetaCPAN::Util qw(true false);
2423

2524
has name => (
2625
is => 'ro',
@@ -105,9 +104,9 @@ has updated => (
105104

106105
has is_pause_custodial_account => (
107106
is => 'ro',
108-
isa => Bool,
107+
isa => ESBool,
109108
coerce => 1,
110-
default => 0,
109+
default => sub {false},
111110
);
112111

113112
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 & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ use ElasticSearchX::Model::Document;
99

1010
use List::Util qw( any );
1111
use MetaCPAN::Document::Module ();
12-
use MetaCPAN::Types qw( Module );
12+
use MetaCPAN::Types qw( ESBool Module );
1313
use MetaCPAN::Types::TypeTiny qw(
1414
ArrayRef
15-
Bool
1615
Int
1716
Maybe
1817
Num
1918
ScalarRef
2019
Stat
2120
Str
2221
);
23-
use MetaCPAN::Util qw(numify_version);
22+
use MetaCPAN::Util qw(numify_version true false);
2423
use Plack::MIME ();
2524
use Pod::Text ();
2625
use Try::Tiny qw( catch try );
@@ -50,8 +49,8 @@ it is also set if the entire release is marked deprecated (see L<MetaCPAN::Docum
5049

5150
has deprecated => (
5251
is => 'ro',
53-
isa => Bool,
54-
default => 0,
52+
isa => ESBool,
53+
default => sub {false},
5554
writer => '_set_deprecated',
5655
);
5756

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

261260
has binary => (
262261
is => 'ro',
263-
isa => Bool,
262+
isa => ESBool,
264263
required => 1,
265-
default => 0,
264+
default => sub {false},
266265
);
267266

268267
=head2 authorized
@@ -274,8 +273,8 @@ See L</set_authorized>.
274273
has authorized => (
275274
required => 1,
276275
is => 'ro',
277-
isa => Bool,
278-
default => 1,
276+
isa => ESBool,
277+
default => sub {true},
279278
writer => '_set_authorized',
280279
);
281280

@@ -301,8 +300,8 @@ Return true if this object represents a directory.
301300
has directory => (
302301
is => 'ro',
303302
required => 1,
304-
isa => Bool,
305-
default => 0,
303+
isa => ESBool,
304+
default => sub {false},
306305
);
307306

308307
=head2 documentation
@@ -433,13 +432,13 @@ not. See L</set_indexed> for a more verbose explanation.
433432
has indexed => (
434433
required => 1,
435434
is => 'ro',
436-
isa => Bool,
435+
isa => ESBool,
437436
lazy => 1,
438437
default => sub {
439438
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;
439+
return false if $self->is_in_other_files;
440+
return false if !$self->metadata->should_index_file( $self->path );
441+
return true;
443442
},
444443
writer => '_set_indexed',
445444
);
@@ -897,24 +896,24 @@ sub set_indexed {
897896
if ( exists $meta->provides->{ $mod->name }
898897
and $self->path eq $meta->provides->{ $mod->name }{file} )
899898
{
900-
$mod->_set_indexed(1);
899+
$mod->_set_indexed(true);
901900
return;
902901
}
903902
}
904903

905904
# files listed under 'other files' are not shown in a search
906905
if ( $self->is_in_other_files() ) {
907906
foreach my $mod ( @{ $self->module } ) {
908-
$mod->_set_indexed(0);
907+
$mod->_set_indexed(false);
909908
}
910-
$self->_set_indexed(0);
909+
$self->_set_indexed(false);
911910
return;
912911
}
913912

914913
# files under no_index directories should not be indexed
915914
foreach my $dir ( @{ $meta->no_index->{directory} } ) {
916915
if ( $self->path eq $dir or $self->path =~ /^$dir\// ) {
917-
$self->_set_indexed(0);
916+
$self->_set_indexed(false);
918917
return;
919918
}
920919
}
@@ -923,24 +922,26 @@ sub set_indexed {
923922
if ( $mod->name !~ /^[A-Za-z]/
924923
or !$meta->should_index_package( $mod->name ) )
925924
{
926-
$mod->_set_indexed(0);
925+
$mod->_set_indexed(false);
927926
next;
928927
}
929928

930929
$mod->_set_indexed(
931930
$mod->hide_from_pause( ${ $self->content }, $self->name )
932-
? 0
933-
: 1
931+
? false
932+
: true
934933
);
935934
}
936935

937936
$self->_set_indexed(
937+
(
938938

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

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

@@ -974,18 +975,18 @@ sub set_authorized {
974975
if ( $self->distribution eq 'perl' ) {
975976
my $allowed = grep $_ eq $self->author, @{ $perms->{perl} };
976977
foreach my $module ( @{ $self->module } ) {
977-
$module->_set_authorized($allowed);
978+
$module->_set_authorized( $allowed ? true : false );
978979
}
979-
$self->_set_authorized($allowed);
980+
$self->_set_authorized( $allowed ? true : false );
980981
}
981982
else {
982983
foreach my $module ( @{ $self->module } ) {
983-
$module->_set_authorized(0)
984+
$module->_set_authorized(false)
984985
if ( $perms->{ $module->name }
985986
&& !grep { $_ eq $self->author }
986987
@{ $perms->{ $module->name } } );
987988
}
988-
$self->_set_authorized(0)
989+
$self->_set_authorized(false)
989990
if ( $self->authorized
990991
&& $self->documentation
991992
&& $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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ 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 qw( ESBool );
12+
use MetaCPAN::Types::TypeTiny qw( Maybe Num Str );
13+
use MetaCPAN::Util qw(true false);
1314

1415
=head1 SYNOPSIS
1516
@@ -73,16 +74,16 @@ has version => ( is => 'ro' );
7374
has indexed => (
7475
is => 'ro',
7576
required => 1,
76-
isa => Bool,
77-
default => 1,
77+
isa => ESBool,
78+
default => sub {true},
7879
writer => '_set_indexed',
7980
);
8081

8182
has authorized => (
8283
is => 'ro',
8384
required => 1,
84-
isa => Bool,
85-
default => 1,
85+
isa => ESBool,
86+
default => sub {true},
8687
writer => '_set_authorized',
8788
);
8889

0 commit comments

Comments
 (0)