Skip to content

Commit

Permalink
automatically use .pod placed next to main_module
Browse files Browse the repository at this point in the history
  • Loading branch information
ap authored and kentfredric committed Jan 9, 2016
1 parent b33895e commit 450b483
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Release history for Dist-Zilla-Plugin-Readme-Brief

[Features]
- Can now specify `source_file` which forces the name of a file to use instead of `main_module` ( aristotle++ #5 )
- Can now automatically use the `.pod` file alternative for your `main_module` if you ship one. ( aristotle++ #5 )

0.002005 2015-03-04T15:21:15Z 03b80f3
[Dependencies::Stats]
Expand Down
3 changes: 2 additions & 1 deletion README.mkdn
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ However, bugs are highly likely to be encountered, especially as there are no te

Determines the file that will be parsed for POD to populate the README from.

By default, it uses your `main_module`.
By default, it uses your `main_module`, except if you have a `.pod` file with
the same basename and path as your `main_module`, in which case it uses that.

## installer

Expand Down
11 changes: 9 additions & 2 deletions lib/Dist/Zilla/Plugin/Readme/Brief.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ my %installers = (
Determines the file that will be parsed for POD to populate the README from.
By default, it uses your C<main_module>.
By default, it uses your C<main_module>, except if you have a C<.pod> file with
the same basename and path as your C<main_module>, in which case it uses that.
=cut

Expand All @@ -50,8 +51,14 @@ has source_file => (
my $file =
$self->_has_source_file_override
? first { $_->name eq $self->_source_file_override } @{ $self->zilla->files }
: $self->zilla->main_module;
: do {
my $main_module = $self->zilla->main_module;
my $alt = $main_module->name;
my $pod = ( $alt =~ s/\.pm\z/.pod/ ) && first { $_->name eq $alt } @{ $self->zilla->files };
$pod or $main_module;
};
$self->log_fatal('Unable to find source_file in the distribution') if not $file;
$self->log_debug( 'Using POD from ' . $file->name ) unless $self->_has_source_file_override;
return $file;
},
);
Expand Down
2 changes: 1 addition & 1 deletion maint/perlcritic.rc.gen.pl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
my $bundle = create_bundle('Example::Author::KENTNL');
$bundle->configure;

my @stopwords = (qw( README CPAN ));
my @stopwords = (qw( README CPAN basename ));
for my $wordlist (@stopwords) {
$bundle->add_or_append_policy_field( 'Documentation::PodSpelling' => ( 'stop_words' => $wordlist ) );
}
Expand Down
2 changes: 1 addition & 1 deletion perlcritic.rc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ allow_includes = 1

[Documentation::PodSpelling]
spell_command = aspell list --lang en_US
stop_words = README CPAN
stop_words = README CPAN basename

[Documentation::ProhibitAdjacentLinks]

Expand Down
41 changes: 41 additions & 0 deletions t/pod_file.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use strict;
use warnings;

use Test::More;

# ABSTRACT: Basic Test for documentation in .pod

use Dist::Zilla::Util::Test::KENTNL 1.004 qw( dztest );
use Test::DZil qw( simple_ini );

my $test = dztest();
$test->add_file( 'lib/Example.pm' => 1 );
$test->add_file( 'lib/Example.pod' => <<'EOF' );
# PODNAME: Foo
=head1 DESCRIPTION
This is a description
=cut
1;
EOF

$test->add_file( 'dist.ini' => simple_ini( [ 'GatherDir' => {} ], [ 'Readme::Brief' => {} ], ) );
$test->build_ok;

my $src_file = $test->test_has_built_file('README');
my @lines = $src_file->lines_utf8( { chomp => 1 } );

use List::Util qw( first );

ok( ( first { $_ eq 'Foo' } @lines ), 'Document name found and injected' );
ok( ( first { $_ eq 'This is a description' } @lines ), 'Description injected' );
ok( ( first { $_ eq 'INSTALLATION' } @lines ), 'Installation section injected' );
ok( ( first { $_ eq 'COPYRIGHT AND LICENSE' } @lines ), 'Copyright section injected' );

done_testing;

0 comments on commit 450b483

Please sign in to comment.