Skip to content

Commit

Permalink
Ensure we can index local::lib
Browse files Browse the repository at this point in the history
closes #380.
  • Loading branch information
rwstauner committed Jan 17, 2015
1 parent 6cecb7c commit 3e017fb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 55 deletions.
25 changes: 0 additions & 25 deletions lib/MetaCPAN/Document/File.pm
Expand Up @@ -667,23 +667,6 @@ sub is_pod_file {
shift->name =~ /\.pod$/i;
}

=head2 is_in_excluded_directory
Returns true if the file is below an excluded directory.
=cut

sub is_in_excluded_directory {
my $self = shift;
my @excluded = qw[t inc local];
my @parts = split m{/}, $self->path;
return any {
my $part = $_;
any { $_ eq $part } @excluded;
}
@parts;
}

=head2 add_module
Requires at least one parameter which can be either a HashRef or
Expand Down Expand Up @@ -721,14 +704,6 @@ does not include any modules, the L</indexed> property is true.
sub set_indexed {
my ( $self, $meta ) = @_;

if ( $self->is_in_excluded_directory() ) {
foreach my $mod ( @{ $self->module } ) {
$mod->indexed(0);
}
$self->indexed(0);
return;
}

foreach my $mod ( @{ $self->module } ) {
$mod->indexed(
$meta->should_index_package( $mod->name )
Expand Down
30 changes: 0 additions & 30 deletions t/document/file.t
Expand Up @@ -12,36 +12,6 @@ my %stub = (
name => 'module.pm',
);

{
my @excluded_paths = qw(
t/whomp
foo/t/bar
cuppa/t
conv/inc/ing
buy/local/beer
);

my @non_excluded_paths = qw(
foo/bart/shorts
tit/mouse
say/wat
wince/inducing/module
not/locally/made
);

foreach my $path (@excluded_paths) {
my $file = MetaCPAN::Document::File->new( %stub, path => $path );
my $msg = "$path is in an excluded directory";
ok( $file->is_in_excluded_directory(), $msg );
}

foreach my $path (@non_excluded_paths) {
my $file = MetaCPAN::Document::File->new( %stub, path => $path );
my $msg = "$path is not in an excluded directory";
ok( !$file->is_in_excluded_directory(), $msg );
}
}

sub test_attributes {
my ( $obj, $att ) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
Expand Down
49 changes: 49 additions & 0 deletions t/release/local-lib.t
@@ -0,0 +1,49 @@
use Test::More;
use strict;
use warnings;

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

test_release(
{
name => 'local-lib-0.01',
author => 'BORISNAT',
abstract => 'Legitimate module',
authorized => \1,
first => \1,
provides => ['local::lib'],
modules => {
'lib/local/lib.pm' => [
{
name => 'local::lib',
indexed => \1,
authorized => \1,
version => '0.01',
version_numified => 0.01,
associated_pod =>
'BORISNAT/local-lib-0.01/lib/local/lib.pm',
},
],
},
extra_tests => sub {
my ($self) = @_;

{
my $file = $self->file_by_path('lib/local/lib.pm');

ok $file->indexed, 'local::lib should be indexed';
ok $file->authorized, 'local::lib should be authorized';
is $file->sloc, 3, 'sloc';
is $file->slop, 2, 'slop';

is_deeply $file->{pod_lines}, [ [ 4, 3 ] ], 'pod_lines';

is $file->abstract, q[Legitimate module], 'abstract';
}

},
}
);

done_testing;
13 changes: 13 additions & 0 deletions t/var/fakecpan/configs/local-lib.json
@@ -0,0 +1,13 @@
{
"name": "local-lib",
"version": "0.01",
"abstract": "undef (no meta files)",
"X_Module_Faker": {
"cpan_author": "BORISNAT",
"omitted_files": ["META.json", "META.yml"],
"append": [ {
"file": "lib/local/lib.pm",
"content": "# Module::Faker\n=head1 NAME\n\nlocal::lib - Legitimate module\n"
} ]
}
}

0 comments on commit 3e017fb

Please sign in to comment.