Skip to content

Commit

Permalink
Limit indexer errors by filtering files without packages
Browse files Browse the repository at this point in the history
  • Loading branch information
rwstauner committed Mar 31, 2015
1 parent 2747794 commit 7148c27
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/MetaCPAN/Model/Release.pm
Expand Up @@ -215,7 +215,8 @@ sub _set_main_module {
my $self = shift;
my ( $mod, $release ) = @_;

my @modules = @{$mod};
# Only select modules (files) that have modules (packages).
my @modules = grep { scalar @{ $_->module } } @$mod;

return unless @modules;

Expand Down
1 change: 0 additions & 1 deletion t/release/no-modules.t
Expand Up @@ -28,4 +28,3 @@ test_release(
);

done_testing;

30 changes: 30 additions & 0 deletions t/release/no-packages.t
@@ -0,0 +1,30 @@
use Test::More;
use strict;
use warnings;

use lib 't/lib';
use MetaCPAN::TestHelpers;

# Some uploads contain no usable modules.
test_release(
{
name => 'No-Packages-1.1',
author => 'BORISNAT',
authorized => \1,
first => \1,

# Without modules it won't get marked as latest.
status => 'cpan',

provides => [

# empty
],
modules => {

# empty
},
}
);

done_testing;
5 changes: 5 additions & 0 deletions t/release/packages.t
Expand Up @@ -52,6 +52,11 @@ test_release(
is ${ $file->pod },
q[NAME Packages::BOM - package in a file with a BOM],
'pod text';

is_deeply $self->file_by_path('lib/Packages/None.pm')
->module,
[],
'pm file has no packages';
},
},
'Test Packages release and its modules',
Expand Down
17 changes: 17 additions & 0 deletions t/var/fakecpan/configs/no-packages.yml
@@ -0,0 +1,17 @@
---
name: No-Packages
version: 1.1
abstract: An archive with pm files but no parseable packages

# Empty hash so Module::Faker won't build its own.
provides: {}

X_Module_Faker:
cpan_author: BORISNAT

append:
-
file: NoPackages.pm
content: |
use Something;
# no package statements
4 changes: 4 additions & 0 deletions t/var/fakecpan/configs/packages.json
Expand Up @@ -13,6 +13,10 @@
{
"file": "lib/Packages/BOM.pm",
"content": "\ufeffpackage Packages::BOM;\nour $VERSION = 0.04;\n\n=head1 NAME\n\nPackages::BOM - package in a file with a BOM\n"
},
{
"file": "lib/Packages/None.pm",
"content": "use Packages;\n\n# a .pm file with no package statement\n"
} ]
}
}

0 comments on commit 7148c27

Please sign in to comment.