Subject: | Accidental use of indirect object syntax |
Class::Autouse chokes on Apache::TestConfig inside Class::Autouse::can().
my $cfg = Apache::TestConfig->new
( top_dir => $apache_root,
t_dir => $apache_root,
apxs => $apxs,
)->httpd_config;
t/50dav....Can't locate object method "_namespace_occupied" via
package "Apache::TestConfig" at
/usr/local/lib/perl5/site_perl/5.8.5/mach/Apache/TestConfigParse.pm
line 355
_namespace_occupied() is a Class::Autouse function. There is code like this in CA: "_namespace_occupied $class". Since _namespace_occupied() is defined after its used that gets evaluated as an indirect object call: $class->_namespace_occupied.
This patch fixes _namespace_occupied() and a few other potential trouble spots. A full sweep is recommended.
--- lib/Class/Autouse.pm 2005/02/08 22:23:23 1.1
+++ lib/Class/Autouse.pm 2005/02/08 22:25:35
@@ -23,7 +23,7 @@
use vars qw{$HOOKS %chased %loaded %special %bad}; # Working data
use vars qw{*_UNIVERSAL_can}; # Subroutine storage
BEGIN {
- $VERSION = '1.14';
+ $VERSION = '1.14_01';
$DEBUG = 0;
# We play with UNIVERSAL::can at times, so save a backup copy
@@ -137,7 +137,7 @@
}
# Does the file for the class exist?
- my $file = _class_file $class;
+ my $file = _class_file($class);
next if exists $INC{$file};
unless ( _file_exists($file) ) {
my $inc = join ', ', @INC;
@@ -211,7 +211,7 @@
# Returns 1 if the class can be used.
sub can_call_methods {
_debug(\@_, 1) if $DEBUG;
- _namespace_occupied $_[1] or exists $INC{_class_file $_[1]};
+ _namespace_occupied($_[1]) or exists $INC{_class_file($_[1])};
}
# Recursive methods currently only work withing the scope of the single @INC
@@ -300,14 +300,14 @@
# Do we try to load the class
my $load = 0;
- my $file = _class_file $class;
+ my $file = _class_file($class);
if ( defined $INC{$file} and $INC{$file} eq 'Class::Autouse' ) {
# It's an autoused class
$load = 1;
} elsif ( ! $SUPERLOAD ) {
# Superloader isn't on, don't load
$load = 0;
- } elsif ( _namespace_occupied $class ) {
+ } elsif ( _namespace_occupied($class) ) {
# Superloader is on, but there is something already in the class
# This can't be the autouse loader, because we would have caught
# that case already
@@ -344,7 +344,7 @@
return 1 if $special{$class};
# Run some checks
- my $file = _class_file $class;
+ my $file = _class_file($class);
if ( defined $INC{$file} ) {
# If the %INC lock is set to any other value, the file is
# already loaded. We do not need to do anything.
@@ -380,7 +380,7 @@
_debug(\@_) if $DEBUG;
# Find where it is in @INC
- my $base_file = _class_file shift;
+ my $base_file = _class_file(shift);
my $inc_path = List::Util::first {
-f File::Spec->catfile($_, $base_file)
} @INC or return;
@@ -445,7 +445,7 @@
return undef if $file =~ m/(?:\012|\015)/o;
# If provided a class name, convert it
- $file = _class_file $file if $file =~ /::/o;
+ $file = _class_file($file) if $file =~ /::/o;
# Scan @INC for the file
foreach ( @INC ) {