#!./perl
#
# test method calls and autoloading.
#
BEGIN {
chdir 't' if -d 't';
}
print "1..78\n";
@A::ISA = 'B';
@B::ISA = 'C';
sub C::d {"C::d"}
sub D::d {"D::d"}
# First, some basic checks of method-calling syntax:
*B::d = \&D::d; # Import now.
{
$#A::ISA = -1;
}
{
local *B::d;
eval 'sub B::d {"B::d1"}'; # Import now.
undef &B::d;
}
eval 'sub B::d {"B::d2"}'; # Import now.
# What follows is hardly guarantied to work, since the names in scripts
# are already linked to "pruned" globs. Say, `undef &B::d' if it were
# after `delete $B::{d}; sub B::d {}' would reach an old subroutine.
undef &B::d;
delete $B::{d};
eval 'sub B::d {"B::d3"}'; # Import now.
delete $B::{d};
eval 'sub B::d {"B::d4"}'; # Import now.
delete $B::{d}; # Should work without any help too
{
local *C::d;
}
*A::x = *A::d; # See if cache incorrectly follows synonyms
A->d;
eval <<'EOF';
sub C::e;
sub Y::f;
$counter = 0;
sub B::AUTOLOAD {
my $c = ++$counter;
goto &$method;
}
sub C::AUTOLOAD {
my $c = ++$counter;
goto &$method;
}
# This test is not intended to be reasonable. It is here just to let you
# know that you broke some old construction. Feel free to rewrite the test
# if your patch breaks it.
*B::AUTOLOAD = sub {
my $c = ++$counter;
goto &$AUTOLOAD;
};
# this test added due to bug discovery
# test that failed subroutine calls don't affect method calls
{
}
## This test was totally misguided. It passed before only because the
## code to determine if a package was loaded used to look for the hash
## %Foo::Bar instead of the package Foo::Bar:: -- and Config.pm just
## happens to export %Config.
# {
# is(do { use Config; eval 'Config->foo()';
# $@ =~ /^\QCan't locate object method "foo" via package "Config" at/ ? 1 : $@}, 1);
# is(do { use Config; eval '$d = bless {}, "Config"; $d->foo()';
# $@ =~ /^\QCan't locate object method "foo" via package "Config" at/ ? 1 : $@}, 1);
# }
# test error messages if method loading fails
$@ =~ /^\QCan't locate object method "foo" via package "E::A" at/ ? 1 : $@}, 1);
$@ =~ /^\QCan't locate object method "foo" via package "E::C" (perhaps / ? 1 : $@}, 1);
$@ =~ /^\QCan't locate object method "foo" via package "E::E" (perhaps / ? 1 : $@}, 1);
$e = bless {}, "E::F"; # force package to exist
$@ =~ /^\QCan't locate object method "foo" via package "E::F" at/ ? 1 : $@}, 1);
# TODO: we need some tests for the SUPER:: pseudoclass
# failed method call or UNIVERSAL::can() should not autovivify packages
is( $::{"Foo::"} || "none", "none"); # sanity check 1
is( $::{"Foo::"} || "none", "none"); # sanity check 2
is( UNIVERSAL::can("Foo", "boogie") ? "yes":"no", "no" );
is( $::{"Foo::"} || "none", "none"); # still missing?
is( Foo->UNIVERSAL::can("boogie") ? "yes":"no", "no" );
is( $::{"Foo::"} || "none", "none"); # still missing?
is( Foo->can("boogie") ? "yes":"no", "no" );
is( $::{"Foo::"} || "none", "none"); # still missing?
is( $::{"Foo::"} || "none", "none"); # still missing?
eval 'sub Foo::boogie { "yes, sir!" }';
# TODO: universal.t should test NoSuchPackage->isa()/can()
# This is actually testing parsing of indirect objects and undefined subs
# print foo("bar") where foo does not exist is not an indirect object.
# print foo "bar" where foo does not exist is an indirect object.
eval 'sub AUTOLOAD { "ok ", shift, "\n"; }';
# Bug ID 20010902.002
is(
eval q[
$x = 'x';
] || $@, 'ok'
);
# An autoloaded, inherited DESTROY may be invoked differently than normal
# methods, and has been known to give rise to spurious warnings
# eg <200203121600.QAA11064@gizmo.fdgroup.co.uk>
{
use warnings;
my $w = '';
$w =~ s/\n//g;
}
# [ID 20020305.025] PACKAGE::SUPER doesn't work anymore
our @X;
sub test {
}
sub Bminor::test {
}
['SUPER::Bar', 'main::SUPER::Bar'],
['Xyz::SUPER::Bar', 'Xyz::SUPER::Bar'])
{
package UNIVERSAL; sub AUTOLOAD { my \$c = shift; print "\$c \$AUTOLOAD\\n" }
sub DESTROY {} # IO object destructor called in MacOS, because of Mac::err
package Xyz;
package main; Foo->$meth->[0]();
EOT
"check if UNIVERSAL::AUTOLOAD works",
);
}