Skip to content

Commit

Permalink
Merge pull request #303 from CPAN-API/oalders/mpeters/476
Browse files Browse the repository at this point in the history
oalders/mpeters/476
  • Loading branch information
rwstauner committed Mar 21, 2014
2 parents 397bf17 + ff0074f commit 2aba91d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/MetaCPAN/Document/File.pm
Expand Up @@ -46,6 +46,16 @@ sub _build_abstract {
my $text = ${ $self->content };
my ( $documentation, $abstract );
my $section = MetaCPAN::Util::extract_section( $text, 'NAME' );

# if it's a POD file without a name section, let's try to generate
# an abstract and name based on filename
if( !$section && $self->path =~ /\.pod$/ ) {
$section = $self->path;
$section =~ s{^(lib|pod|docs)/}{};
$section =~ s{\.pod$}{};
$section =~ s{/}{::}g;
}

return undef unless ($section);
$section =~ s/^=\w+.*$//mg;
$section =~ s/X<.*?>//mg;
Expand Down
42 changes: 41 additions & 1 deletion t/document/file.t
Expand Up @@ -115,7 +115,8 @@ END
is( $file->abstract,
'An object containing information about how to get access to teh Moby databases, resources, etc. from the mobycentral.config file'
);
is( $file->module->[0]
is(
$file->module->[0]
->hide_from_pause( ${ $file->content }, $file->name ),
0, 'indexed'
);
Expand Down Expand Up @@ -225,4 +226,43 @@ END
is( $file->description, 'hot stuff * Foo * Bar' );
}

{
my $content = <<'END';
package Foo::Bar::Baz;
=head1 DESCRIPTION
hot stuff
=over
=item *
Foo
=item *
Bar
=back
END

foreach my $folder ( 'pod', 'lib', 'docs' ) {
my $file = MetaCPAN::Document::File->new(
author => 'Foo',
content_cb => sub { \$content },
distribution => 'Foo',
name => 'Baz.pod',
path => $folder . '/Foo/Bar/Baz.pod',
release => 'release',
);
is( $file->documentation, 'Foo::Bar::Baz',
'Fakes a name when no name section exists in '
. $folder
. ' folder' );
is( $file->abstract, undef, 'abstract undef when NAME is missing' );
}
}

done_testing;

0 comments on commit 2aba91d

Please sign in to comment.