[win32] document CORE::GLOBAL:: and global overriding, fix up
[p5sagit/p5-mst-13.2.git] / t / lib / autoloader.t
CommitLineData
a30dce55 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 $dir = "auto-$$";
6 @INC = ("./$dir", "../lib");
7}
8
9print "1..9\n";
10
11# First we must set up some autoloader files
12mkdir $dir, 0755 or die "Can't mkdir $dir: $!";
13mkdir "$dir/auto", 0755 or die "Can't mkdir: $!";
14mkdir "$dir/auto/Foo", 0755 or die "Can't mkdir: $!";
15
16open(FOO, ">$dir/auto/Foo/foo.al") or die;
17print FOO <<'EOT';
18package Foo;
19sub foo { shift; shift || "foo" }
201;
21EOT
22close(FOO);
23
24open(BAR, ">$dir/auto/Foo/bar.al") or die;
25print BAR <<'EOT';
26package Foo;
27sub bar { shift; shift || "bar" }
281;
29EOT
30close(BAR);
31
32open(BAZ, ">$dir/auto/Foo/bazmarkhian.al") or die;
33print BAZ <<'EOT';
34package Foo;
35sub bazmarkhianish { shift; shift || "baz" }
361;
37EOT
38close(BAZ);
39
40# Let's define the package
41package Foo;
42require AutoLoader;
43@ISA=qw(AutoLoader);
44
45sub new { bless {}, shift };
46
47package main;
48
49$foo = new Foo;
50
51print "not " unless $foo->foo eq 'foo'; # autoloaded first time
52print "ok 1\n";
53
54print "not " unless $foo->foo eq 'foo'; # regular call
55print "ok 2\n";
56
57# Try an undefined method
58eval {
59 $foo->will_fail;
60};
61print "not " unless $@ =~ /^Can't locate/;
62print "ok 3\n";
63
64# Used to be trouble with this
65eval {
66 my $foo = new Foo;
67 die "oops";
68};
69print "not " unless $@ =~ /oops/;
70print "ok 4\n";
71
72# Pass regular expression variable to autoloaded function. This used
73# to go wrong because AutoLoader used regular expressions to generate
74# autoloaded filename.
75"foo" =~ /(\w+)/;
76print "not " unless $1 eq 'foo';
77print "ok 5\n";
78
79print "not " unless $foo->bar($1) eq 'foo';
80print "ok 6\n";
81
82print "not " unless $foo->bar($1) eq 'foo';
83print "ok 7\n";
84
85print "not " unless $foo->bazmarkhianish($1) eq 'foo';
86print "ok 8\n";
87
88print "not " unless $foo->bazmarkhianish($1) eq 'foo';
89print "ok 9\n";
90
91# cleanup
92END {
93return unless $dir && -d $dir;
94unlink "$dir/auto/Foo/foo.al";
95unlink "$dir/auto/Foo/bar.al";
96unlink "$dir/auto/Foo/bazmarkhian.al";
97rmdir "$dir/auto/Foo";
98rmdir "$dir/auto";
99rmdir "$dir";
100}