package Dist::Zilla::Plugin::AbstractFromPOD;

use 5.008;
use version; our $VERSION = qv( sprintf '0.3.%d', q$Rev: 1 $ =~ /\d+/gmx );

use Moose;
use English                 qw( -no_match_vars );
use File::Spec::Functions   qw( catfile );

with 'Dist::Zilla::Role::BeforeBuild';

sub before_build {
   my $self  = shift;
   my $name  = $self->zilla->name;
   my $class = $name; $class =~ s{ [\-] }{::}gmx;
   my $file  = $self->zilla->_main_module_override
            || catfile( 'lib', split m{ [\-] }mx, "${name}.pm" );

                     $file or die 'No main module specified';
                  -f $file or die "Path ${file} does not exist or not a file";
   open my $fh, '<', $file or die "File ${file} cannot open: ${OS_ERROR}";

   my $content    = do { local $RS; <$fh> }; $fh->close;
   my ($abstract) = $content
      =~ m{ =head1 \s+ Name \s* [\n] \s* $class \s* [\-] \s* ([^\n]+) }imsx;

   $abstract or die "File ${file} contains no abstract";
   $self->zilla->abstract( $abstract );


no Moose;




=encoding utf8

=begin html

<a href=""><img src="" alt="CPAN Badge"></a>
<a href=""><img src="" alt="Kwalitee Badge"></a>

=end html

=head1 Name

Dist::Zilla::Plugin::AbstractFromPOD - Case insensitive head1 POD matching for the Name attribute

=head1 Synopsis

   # In dist.ini

=head1 Version

This documents version v0.3.$Rev: 1 $ of L<Dist::Zilla::Plugin::AbstractFromPOD>

=head1 Description

Case insensitive head1 POD matching for the Name attribute

L<Dist::Zilla> should do this by default but unfortunately it's pattern
matching is case sensitive so this instead

=head1 Configuration and Environment

Defines no attributes

=head1 Subroutines/Methods

=head2 before_build

Read the main module and extract the abstract (case insensitive matching on
the head1 Name POD directive)

=head1 Diagnostics


=head1 Dependencies

=over 3

=item L<Dist::Zilla::Role::BeforeBuild>


=head1 Incompatibilities

There are no known incompatibilities in this module

=head1 Bugs and Limitations

There are no known bugs in this module. Please report problems to
Patches are welcome

=head1 Acknowledgements

Larry Wall - For the Perl programming language

=head1 Author

Peter Flanigan, C<< <> >>

=head1 License and Copyright

Copyright (c) 2015 Peter Flanigan. All rights reserved

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself. See L<perlartistic>

This program is distributed in the hope that it will be useful,
but WITHOUT WARRANTY; without even the implied warranty of


# Local Variables:
# mode: perl
# tab-width: 3
# End: