Subject: | problem with RequireExplicitInclusion and "use base" and "use parent" |
Hi,
please consider the two Perl packages below. The rule RequireExplicitInclusion will report a
violation. But bar does use foo it only doesn't say so directly.
I did look into it. Please see my solution at the end of the mail.
Kind regards from Stockholm
Ulrich
Example modules (of course to be saved in two files):
package foo;
use base 'Exporter';
our @EXPORT = qw(test_method);
sub test_method {
print "TEST TEST TEST\n";
return;
}
1;
__END__
package bar;
use strict;
use warnings;
use utf8;
use base 'foo';
sub another_method {
my $self = shift;
print "ANOTHER ";
foo::test_method();
return;
}
1;
__END__
In Perl/Critic/StricterSubs/Utils.pm replace the following subroutine
sub get_package_names_from_include_statements {
my $doc = shift;
my $statements = $doc->find( \&_wanted_include_statement );
return () if not $statements;
my @modules = ();
foreach (@{$statements}) {
my $module = $_->module();
if ($module =~ m/^(base|parent)$/) {
my @schildren = $_->schildren();
$module = substr($schildren[2], 1, -1);
}
print STDERR "Module: $module\n";
push @modules, $module;
}
return @modules;
}
--
Help building the worlds most comprehensive list of judo dojos.
Put your dojo on the list at http://JudoWorldMap.com