Dist-Zilla-Plugin-Acme-CPANLists
view release on metacpan or search on metacpan
lib/Dist/Zilla/Plugin/Acme/CPANLists.pm view on Meta::CPAN
unless (defined $filecontent) {
$filecontent = do {
open my($fh), "<", $filename or die "Can't open $filename: $!";
local $/;
~~<$fh>;
};
}
unless ($filecontent =~ m{^#[ \t]*ABSTRACT:[ \t]*([^\n]*)[ \t]*$}m) {
$self->log_debug(["Skipping %s: no # ABSTRACT", $filename]);
return undef;
}
my $abstract = $1;
if ($abstract =~ /\S/) {
$self->log_debug(["Skipping %s: Abstract already filled (%s)", $filename, $abstract]);
return $abstract;
}
my $pkg;
if (!defined($filecontent)) {
(my $mod_p = $filename) =~ s!^lib/!!;
require $mod_p;
# find out the package of the file
($pkg = $mod_p) =~ s/\.pm\z//; $pkg =~ s!/!::!g;
} else {
eval $filecontent;
die if $@;
if ($filecontent =~ /\bpackage\s+(\w+(?:::\w+)*)/s) {
$pkg = $1;
} else {
die "Can't extract package name from file content";
}
}
no strict 'refs';
my $author_lists = \@{"$pkg\::Author_Lists"};
my $module_lists = \@{"$pkg\::Module_Lists"};
# find the first module or author list
my $abstract_from_list;
{
for (@$module_lists, @$author_lists) {
if ($_->{summary}) {
return $_->{summary};
last;
}
}
}
undef;
}
# dzil also wants to get abstract for main module to put in dist's
# META.{yml,json}
sub before_build {
my $self = shift;
my $name = $self->zilla->name;
my $class = $name; $class =~ s{ [\-] }{::}gmx;
my $filename = $self->zilla->_main_module_override ||
catfile( 'lib', split m{ [\-] }mx, "${name}.pm" );
$filename or die 'No main module specified';
-f $filename or die "Path ${filename} does not exist or not a file";
open my $fh, '<', $filename or die "File ${filename} cannot open: $!";
my $abstract = $self->_get_abstract_from_author_or_module_list($filename);
return unless $abstract;
$self->zilla->abstract($abstract);
return;
}
sub munge_files {
my $self = shift;
$self->munge_file($_) for @{ $self->found_files };
}
sub munge_file {
my ($self, $file) = @_;
my $content = $file->content;
unless ($file->isa("Dist::Zilla::File::OnDisk")) {
$self->log_debug(["skipping %s: not an ondisk file, currently generated file is assumed to be OK", $file->name]);
return;
}
my $abstract = $self->_get_abstract_from_author_or_module_list($file->name, $file->content);
ADD_X_MENTIONS_PREREQS:
{
my $pkg = do {
my $pkg = $file->name;
$pkg =~ s!^lib/!!;
$pkg =~ s!\.pm$!!;
$pkg =~ s!/!::!g;
$pkg;
};
no strict 'refs';
#my $author_lists = \@{"$pkg\::Author_Lists"};
my $module_lists = \@{"$pkg\::Module_Lists"};
my @mods;
for my $module_list (@$module_lists) {
for my $entry (@{ $module_list->{entries} }) {
push @mods, $entry->{module};
for (@{ $entry->{alternate_modules} || [] }) {
push @mods, $_;
}
}
}
for my $mod (@mods) {
$self->zilla->register_prereqs(
{phase=>'x_mentions', type=>'x_mentions'}, $mod, 0);
}
}
SET_ABSTRACT:
{
last unless $abstract;
$content =~ s{^#\s*ABSTRACT:.*}{# ABSTRACT: $abstract}m
or die "Can't insert abstract for " . $file->name;
( run in 0.582 second using v1.01-cache-2.11-cpan-71847e10f99 )