Skip to content

Commit

Permalink
Merge 1e714ed into 916b0e3
Browse files Browse the repository at this point in the history
  • Loading branch information
andreeap committed Feb 25, 2015
2 parents 916b0e3 + 1e714ed commit a16d84a
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ requires 'JSON', '2.90';
requires 'LWP::Protocol::https';
requires 'LWP::UserAgent';
requires 'LWP::UserAgent::Paranoid';
requires 'List::AllUtils';
requires 'List::MoreUtils';
requires 'List::Util';
requires 'Log::Contextual';
Expand Down
22 changes: 22 additions & 0 deletions cpanfile.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4020,6 +4020,18 @@ DISTRIBUTIONS
requirements:
Test::More 0
version 0
List-AllUtils-0.09
pathname: D/DR/DROLSKY/List-AllUtils-0.09.tar.gz
provides:
List::AllUtils 0.09
requirements:
Exporter 0
ExtUtils::MakeMaker 0
List::MoreUtils 0.28
List::Util 1.31
base 0
strict 0
warnings 0
List-MoreUtils-0.33
pathname: A/AD/ADAMK/List-MoreUtils-0.33.tar.gz
provides:
Expand Down Expand Up @@ -6802,6 +6814,16 @@ DISTRIBUTIONS
Exporter 5.57
ExtUtils::MakeMaker 0
Scalar::Util 0
Scalar-List-Utils-1.41
pathname: P/PE/PEVANS/Scalar-List-Utils-1.41.tar.gz
provides:
List::Util 1.41
List::Util::XS 1.41
Scalar::Util 1.41
Sub::Util 1.41
requirements:
ExtUtils::MakeMaker 0
Test::More 0
Scope-Guard-0.20
pathname: C/CH/CHOCOLATE/Scope-Guard-0.20.tar.gz
provides:
Expand Down
56 changes: 56 additions & 0 deletions lib/MetaCPAN/Document/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use Moose;
use ElasticSearchX::Model::Document;

use Encode;
use List::AllUtils qw( any );
use List::MoreUtils qw(any uniq);
use MetaCPAN::Document::Module;
use MetaCPAN::Pod::XHTML;
Expand Down Expand Up @@ -681,6 +682,52 @@ sub add_module {
$self->module( [ @{ $self->module }, @modules ] );
}

=head2 is_in_other_files
Returns true if the file is one from the list below.
=cut

sub is_in_other_files {
my $self = shift;
my @other = qw(
AUTHORS
Build.PL
Changelog
ChangeLog
CHANGELOG
Changes
CHANGES
CONTRIBUTING
CONTRIBUTING.md
CONTRIBUTING.pod
Copying
COPYRIGHT
cpanfile
CREDITS
dist.ini
FAQ
INSTALL
INSTALL.md
INSTALL.pod
LICENSE
Makefile.PL
MANIFEST
META.json
META.yml
NEWS
README
README.md
README.pod
THANKS
Todo
ToDo
TODO
);

return any { $self->name eq $_ } @other;
}

=head2 set_indexed
Expects a C<$meta> parameter which is an instance of L<CPAN::Meta>.
Expand Down Expand Up @@ -708,6 +755,15 @@ does not include any modules, the L</indexed> property is true.
sub set_indexed {
my ( $self, $meta ) = @_;

#files listed under 'other files' are not shown in a search
if ( $self->is_in_other_files() ) {
foreach my $mod ( @{ $self->module } ) {
$mod->indexed(0);
}
$self->indexed(0);
return;
}

foreach my $mod ( @{ $self->module } ) {
if ( $mod->name !~ /^[A-Za-z]/ ) {
$mod->indexed(0);
Expand Down
19 changes: 19 additions & 0 deletions t/document/file.t
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,25 @@ subtest 'Packages starting with underscore are not indexed' => sub {
is( $file->module->[0]->indexed, 0, 'Package is not indexed' );
};

subtest 'files listed under other files' => sub {
my $content = <<'END';
=head1 NAME
Makefile.PL - configure Makefile
=head1 DESCRIPTION
just a makefile description
END
my $file = new_file_doc(
name => 'Makefile.PL',
content_cb => sub { \$content }
);

is( $file->indexed, 0, 'File listed under other files is not indexed' );
};

subtest 'pod name/package mismatch' => sub {
my $content = <<'END';
package
Expand Down

0 comments on commit a16d84a

Please sign in to comment.