Skip to content

Commit

Permalink
improved documentation fetching logic + fixed test
Browse files Browse the repository at this point in the history
also, updated file docuemntation builder with comments to clarify
the decision making.
  • Loading branch information
mickeyn committed Apr 25, 2016
1 parent 9643c87 commit 52d4df2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
21 changes: 16 additions & 5 deletions lib/MetaCPAN/Document/File.pm
Expand Up @@ -317,19 +317,30 @@ sub _build_documentation {

return undef unless length $documentation;

# Modules to be indexed
my @indexed = grep { $_->indexed } @{ $self->module || [] };

# This is a Pod file, return its name
if ( $documentation && $self->is_pod_file ) {
return $documentation;
}
elsif ( $documentation && grep { $_->name eq $documentation } @indexed ) {

# OR: found an indexed module with the same name
if ( $documentation && grep { $_->name eq $documentation } @indexed ) {
return $documentation;
}
elsif (@indexed) {
return $indexed[0]->name;

# OR: found an indexed module with a name
if ( my ($mod) = grep { defined $_->name } @indexed ) {
return $mod->name;
}
elsif ( !@{ $self->module || [] } ) {
return $documentation;

# OR: we have a parsed documentation
return $documentation if defined $documentation;

# OR: found ANY module with a name (better than nothing)
if ( my ($mod) = grep { defined $_->name } @{ $self->module || [] } ) {
return $mod->name;
}

return undef;
Expand Down
14 changes: 12 additions & 2 deletions t/document/file.t
Expand Up @@ -271,8 +271,18 @@ END
is( $file->sloc, 8, '8 lines of code' );
is( $file->slop, 4, '4 lines of pod' );
is( $file->module->[0]->hide_from_pause($content), 1, 'not indexed' );
is( $file->abstract, 'AS-specific methods for Number::Phone' );
is( $file->documentation, 'Number::Phone::NANP::ASS' );
is(
$file->abstract,
'AS-specific methods for Number::Phone',
'abstract text'
);

# changed because the extracted document from content takes
# precedence over a non-indexed module.
# test may need an update if we want to see the name
# from the module. -- Mickey
is( $file->documentation, 'Number::Phone::NANP::AS', 'document text' );

is_deeply( $file->pod_lines, [ [ 18, 7 ] ], 'correct pod_lines' );
is( $file->module->[0]->version_numified,
1.1, 'numified version has been calculated' );
Expand Down

0 comments on commit 52d4df2

Please sign in to comment.