Skip to content

Commit

Permalink
tighten up the regex that extracts local packages in AutoPrereqs
Browse files Browse the repository at this point in the history
Skip all comments, words with sigils.
  • Loading branch information
karenetheridge committed May 16, 2015
1 parent ce783fe commit 66e7b42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions corpus/dist/AutoPrereqs/lib/DZPA/Main.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ use parent qw{ DZPA::Base::parent2 DZPA::Base::parent3 };
# DZPA::Skip should be trimmed
use DZPA::Skip::Blah;

# and this comment should not cause a package to be trimmed:
# package foobar DZPA::Role

# require in a module
require DZPA::ModRequire;

Expand Down Expand Up @@ -54,3 +57,6 @@ this pod should not be taken in to account, with:
use fake;
require blah;
with 'fubar';
nor should this statement here, but that is still a TODO!
pack age strict; XXX remove this space
5 changes: 4 additions & 1 deletion lib/Dist/Zilla/Plugin/AutoPrereqs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ sub register_prereqs {
s{\.pm$}{} for @this_thing;
s{/}{::}g for @this_thing;

push @this_thing, $file->content =~ /package\s+([^\s;]+)/g;
# this is a bunk heuristic and can still capture strings from pod - the
# proper thing to do is grab all packages from Module::Metadata
push @this_thing, $file->content =~ /^[^#]*?(?:^|\s)package\s+([^\s;#]+)/mg;
push @modules, List::MoreUtils::uniq @this_thing;

# parse a file, and merge with existing prereqs
Expand All @@ -183,6 +185,7 @@ sub register_prereqs {
}

# remove prereqs shipped with current dist
$self->log_debug([ 'excluding local packages: %s', sub { join(', ', List::MoreUtils::uniq @modules) } ]);
$req->clear_requirement($_) for @modules;

$req->clear_requirement($_) for qw(Config Errno); # never indexed
Expand Down

0 comments on commit 66e7b42

Please sign in to comment.