6 unshift @INC, ("./$dir", "../lib");
10 # First we must set up some selfloader files
11 mkdir $dir, 0755 or die "Can't mkdir $dir: $!";
13 open(FOO, ">$dir/Foo.pm") or die;
18 sub new { bless {}, shift }
23 sub never; # declared but definition should never be read
27 sub foo { shift; shift || "foo" };
29 sub bar { shift; shift || "bar" }
31 sub bazmarkhianish { shift; shift || "baz" }
34 sub bleat { shift; shift || "baa" }
37 sub never { die "D'oh" }
42 open(BAR, ">$dir/Bar.pm") or die;
49 sub new { bless {}, shift }
59 sub never { die "D'oh" }
79 print "not " unless $foo->foo eq 'foo'; # selfloaded first time
82 print "not " unless $foo->foo eq 'foo'; # regular call
85 # Try an undefined method
89 if ($@ =~ /^Undefined subroutine/) {
92 print "not ok 3 $@\n";
95 # Used to be trouble with this
103 print "not ok 4 $@\n";
106 # Pass regular expression variable to autoloaded function. This used
107 # to go wrong in AutoLoader because it used regular expressions to generate
108 # autoloaded filename.
110 print "not " unless $1 eq 'foo';
113 print "not " unless $foo->bar($1) eq 'foo';
116 print "not " unless $foo->bar($1) eq 'foo';
119 print "not " unless $foo->bazmarkhianish($1) eq 'foo';
122 print "not " unless $foo->bazmarkhianish($1) eq 'foo';
125 # Check nested packages inside __DATA__
126 print "not " unless sheep::bleat() eq 'baa';
129 # Now check inheritance:
133 # Before anything is SelfLoaded there is no declaration of Foo::b so we should
135 print "not " unless $bar->b() eq 'b Baz';
138 # There is no Bar::c so we should get Baz::c
139 print "not " unless $bar->c() eq 'c Baz';
142 # This selfloads Bar::a because it is stubbed. It also stubs Bar::b as a side
144 print "not " unless $bar->a() eq 'a Bar';
147 print "not " unless $bar->b() eq 'b Bar';
150 print "not " unless $bar->c() eq 'c Baz';
155 # Check that __END__ is honoured
156 # Try an subroutine that should never be noticed by selfloader
160 if ($@ =~ /^Undefined subroutine/) {
163 print "not ok 16 $@\n";
166 # Try to read from the data file handle
167 my $foodata = <Foo::DATA>;
169 if (defined $foodata) {
170 print "not ok 17 # $foodata\n";
175 # Check that __END__ DATA is honoured
176 # Try an subroutine that should never be noticed by selfloader
180 if ($@ =~ /^Undefined subroutine/) {
183 print "not ok 18 $@\n";
186 # Try to read from the data file handle
187 my $bardata = <Bar::DATA>;
189 if ($bardata ne "sub never { die \"D'oh\" }\n") {
190 print "not ok 19 # $bardata\n";
197 return unless $dir && -d $dir;
198 unlink "$dir/Foo.pm", "$dir/Bar.pm";