Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions t/02_list.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ my @expectedrequires = (
"$perl_ns(base)\n",
"$perl_ns(parent)\n",
"$perl_ns(Theta)\n",
"$perl_ns(Omicron)\n",
"$perl_ns(Xi)\n",
"$perl_ns(WithTrailingComma)\n",
"$perl_ns(Kappa::Lambda)\n",
"$perl_ns(Mu::Nu)\n",
"$perl_ns(Try)\n",
Expand All @@ -38,6 +41,9 @@ my @expectedrequires = (
"$perl_ns(TARGET_CLASS)\n",
"$perl_ns(XML::XQL::Element)\n",
"$perl_ns(Class::Accessor::Fast)\n",
"$perl_ns(AfterTab)\n",
"$perl_ns(AfterSpace)\n",
"$perl_ns(AfterNLAndTab)\n",
);

is_deeply([ sort @requires ], [ sort @expectedrequires ], "Only expected requires were found.");
8 changes: 8 additions & 0 deletions t/data/list
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use base qw<Delta>;
use parent 'Epsilon';
use parent qw{Theta};

use base ("Xi", "Omicron");
use base ("WithTrailingComma",);

# 'Zeta', 'Iota', 'Not::Require*' should not be found
use parent -norequire, qw(Zeta Iota);
use parent -norequire, 'Not::Require1', 'Not::Require2';
Expand Down Expand Up @@ -40,3 +43,8 @@ use base TARGET_CLASS;

# Do not ignore line which contains '->' in a coment
use base 'XML::XQL::Element'; # L -> L

use base qw {
AfterTab AfterSpace
AfterNLAndTab
};
44 changes: 29 additions & 15 deletions template/bin/perl.req
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ sub process_file {
$_ = <FILE>;
}

my $quoted_list = q/\s*(?:['"][^"'\$]*["']\s*,\s*)*\s*['"][^"'\$]*["']\s*,?\s*/;

if (

# ouch could be in a eval, perhaps we do not want these since we catch
Expand All @@ -244,38 +246,50 @@ sub process_file {
(?:$begin_re\s*
([^)\/"'\$!|}]*?)
\s*$end_re|
\s*(\($quoted_list\))|
(?:qw<|qq?<)([^>]*?)>|([\w\:]+)|)\s*(.*)
/x)
) {
my ($whitespace, $statement, $module, $version, $params, $list, $rest) = ($1, $2, $3, $5, $6, $7 || $8 || $9, $10);
my ($whitespace, $statement, $module, $version, $params, $list, $rest) = ($1, $2, $3, $5, $6, $7 || $8 || $9 || $10, $11);
$version = undef if ($version eq '');

# Ignore line which contains direct method calls
# use base __PACKAGE__->subroutine(...);
$list = "" if ($list =~ /^[^;#]*?->/ || $rest =~ /^[^;#]*?->/);

my @list = split ' ', $list;

#
# Executed in case that multiline q{} quoted sections is used for
# list of modules
if (defined($list) && $list =~ /^q[qxwr]?$/) {
$list = "";
if ($rest =~ m/^\s*([{([#|!\/])\s*([^})\]#|!\/]*)$/) {
@list = ();
$tag = $1;
$list = $2;
chomp($list);
$tag =~ tr/{\(\[\#|!\//})]#|!\//;
$tag = quotemeta($tag);
while (<FILE>) {
my $line = $_;
chomp($line);
if ($line =~ m/^\s*(.*?)$tag/) {
$list .= ' ' . $1 if ($1 ne '');
last;
} else { $list .= ' ' . $line; }
chomp(my $line = $_);
# If line contains tag, remove it and finish iteration.
my $last = $line =~ s/$tag.*$//;
push(@list, split(' ', $line));
last if $last;
}
$list = "";
}
}

# Executed in the case of a standard quoted array in the list of modules.
# use base ("Package1", "Package2");
if (defined($list) && $list =~ /^\(($quoted_list)\)$/) {
$list = "";
@list = grep { /\S/ } (split /,/, $1);
# Remove ignored spaces and quotes.
s/^\s*['"]|['"]\s*$//g for @list;
}

# we only consider require statements that are flushed against
# the left edge. any other require statements give too many
# false positives, as they are usually inside of an if statement
Expand Down Expand Up @@ -362,17 +376,17 @@ sub process_file {
# use aliased qw(Foo::Bar) dependencies
if ($statement eq "use" && ($module eq "base" || $module eq "aliased")) {
add_require($module, $version);
if (defined($list) && $list ne "") {
add_require($_, undef) for split(' ', $list);
if (@list) {
add_require($_, undef) for @list;
}
next;
}
# use parent -norequire, 'No::Version'; # $params == "-norequire,"
# use parent qw/-norequire XML::XPath::Node/; # $list == "-norequire XML::XPath::Node"
# use parent qw/-norequire XML::XPath::Node/; # @list == qw(-norequire XML::XPath::Node}
if ($statement eq "use" && $module eq "parent") {
add_require($module, $version);
if (defined($list) && $list ne "" && $list !~ /-norequire/ && $params !~ /-norequire/) {
add_require($_, undef) for split(' ', $list);
if (@list && !grep(/-norequire/, @list) && $params !~ /-norequire/) {
add_require($_, undef) for @list;
}
next;
}
Expand All @@ -381,8 +395,8 @@ sub process_file {
# Mouse or Mouse::Role will be added
if ($statement eq "use" && $module eq "Any::Moose") {
add_require($module, $version);
if (defined($list) && $list ne "") {
if (grep { !/^Role$/ } split(' ', $list)) {
if (@list) {
if (grep { !/^Role$/ } @list) {
add_require('Mouse::Role', undef);
} else {
add_require('Mouse', undef);
Expand Down